LVGL is a powerful open-source graphics library for creating graphical user interfaces on embedded devices. In this tutorial, we'll walk through setting up LVGL with the Arduino IDE and using LovyanGFX as the display driver.
LovyanGFX is a graphics library that supports a wide range of displays and microcontrollers, including the ESP32 family. By combining it with LVGL, we can quickly get a graphical interface running on supported hardware.
We'll use the M5Stack Core Basic v2.7 for this tutorial, but the same approach can be adapted to other supported boards.

1. Install the Arduino IDE#
Start by downloading and installing the Arduino IDE from the official website:
At the time of writing, the latest version was 2.3.10.
Once installed, launch the IDE and proceed with configuring support for ESP32 boards.
2. Install ESP32 Board Support#
The Arduino IDE does not include ESP32 board support by default, so we'll need to install it.
- Open the Boards Manager from the sidebar.
- Search for
esp32. - Find esp32 by Espressif Systems and click Install.

This package provides the necessary tools to compile and upload Arduino sketches to ESP32-based boards.
Depending on your operating system and the USB-to-serial chip used by your board, you may also need to install additional serial drivers.
3. Install LVGL and LovyanGFX#
Next, we'll install the libraries required for the example.
Open the Library Manager in the Arduino IDE and search for the following libraries:
- lvgl - The graphics library we'll use to create the user interface.
- LovyanGFX - The display driver library that will handle communication with the display hardware.
Install both libraries.
Using the Latest LVGL Development Version#
You can also use a custom version of LVGL instead of the one available through the Arduino Library Manager.
For example, if you want to test new features or examples that have not yet been included in an official release, you can download or clone the latest version from the LVGL GitHub repository.
A free and full-featured embedded UI library for small MCUs and 3D-capable MPUs. Use it directly in C, or go declarative with LVGL XML for AI integration, Figma import, live preview, and UI updates without reflashing.
Copy the library into your Arduino libraries directory.
For this tutorial, we're using the latest LVGL master branch. At the time of writing, LVGL v9.6.0 was the latest version available through the Arduino Library Manager, but it did not yet include the LovyanGFX examples.
4. Configure LVGL#
After installing LVGL, locate its installation directory.
On most systems, the default location is:
Documents/Arduino/libraries/lvgl/Inside this directory, you'll find a file named lv_conf_template.h.
Copy this file to the Arduino libraries directory and rename it to lv_conf.h.
Your directory structure should look like this:
- lv_conf.h
Open lv_conf.h in a text editor.
Near the beginning of the file, change #if 0 to #if 1:
#if 0
#if 1cThis enables the LVGL configuration file.
Enable LovyanGFX Support#
Since we'll be using LovyanGFX to drive the display, enable its integration in lv_conf.h:
#define LV_USE_LOVYAN_GFX 1cThis tells LVGL to use the LovyanGFX integration.
5. Open the LovyanGFX Example#
Now that the libraries are installed and configured, let's open the example project.
In the Arduino IDE, navigate to:
File > Examples > lvgl > arduino > LVGL_LovyanGFX

The example contains two files, which will appear as separate tabs in the Arduino IDE:
LVGL_LovyanGFX.ino- The main Arduino sketch that initializes LVGL and creates the example UI.my_display.hpp- The LovyanGFX display configuration, which defines how the display hardware is initialized.
Because the example uses my_display.hpp, we need to tell LVGL where to find this configuration.
Add the following to lv_conf.h:
#define LV_LGFX_USER_INCLUDE "my_display.hpp"cThis allows the LVGL integration to include our custom LovyanGFX configuration.
6. Configure the M5Stack Core Basic#
For this example, we'll use the M5Stack Core Basic v2.7, which has a 320 × 240 pixel display.
In the example sketch, configure the display resolution and rotation as follows:
#define TFT_HOR_RES 240
#define TFT_VER_RES 320
#define TFT_ROTATION LV_ROTATION_90cThese settings configure the display dimensions and apply a 90-degree rotation.
Configure LovyanGFX#
The M5Stack Core Basic is already supported by LovyanGFX, so we don't need to define its display pins or communication interface manually.
Open my_display.hpp.
You can either let LovyanGFX automatically detect the board using:
#define LGFX_AUTODETECTcppOr explicitly select the M5Stack configuration:
#define LGFX_M5STACKcppUsing the predefined board configuration makes the setup much simpler, as LovyanGFX already knows how to initialize the display hardware.
7. Compile and Upload the Example#
Connect the M5Stack Core Basic to your computer using a USB cable.
In the Arduino IDE:
- Open the board selector and search for M5Core.
- Select the appropriate board from the results.
- Select the serial port associated with your connected device.
If you see two similar serial port entries, the one with the wch prefix may correspond to the board's USB-to-serial interface. The exact port name depends on your operating system and hardware.

Once the board and port are selected, click the Verify button (checkmark icon) to compile the project.
Alternatively, click Upload, which will compile the sketch and then flash it to the connected device.
If everything is configured correctly, the project should compile and upload successfully.
8. Run the Example#
After uploading, the board should start running the LVGL example.
You should see a button labeled "Hello Arduino!" on the display.
This confirms that:
- LVGL has been initialized successfully.
- LovyanGFX is communicating with the display.
- The display resolution and rotation are configured.
- LVGL can render graphical widgets on the device.
The M5Stack Core Basic does not have a touchscreen, so the button will be visible but cannot be interacted with through touch input.

At this point, you have a working LVGL application running on Arduino using LovyanGFX!
What's Next?#
In this tutorial, we used a board that already has a predefined configuration in LovyanGFX. This allowed us to get LVGL running without manually configuring the display interface.
However, not every development board is directly supported by LovyanGFX.
In the next tutorial, we'll look at how to use LVGL with a board that doesn't have a predefined LovyanGFX configuration, but uses display and touch controllers that are already supported by the library.
We'll explore how to configure the display interface, define the required pins, and initialize the touchscreen to create a fully interactive LVGL application.
