Development docs. Unreleased and may change.Switch to Release v9.6.0

Add LVGL to an ESP32 IDF project

LVGL can be used and configured as a standard ESP-IDF component, either through the esp_lvgl_port component or on its own.

Edit on GitHub

LVGL can be used and configured as a standard ESP-IDF component.

If you are new to ESP-IDF, follow the instructions in the ESP-IDF Programming guide to install and set up ESP-IDF on your machine.

Using LVGL in Your ESP-IDF Project

The simplest way to integrate LVGL into your ESP-IDF project is via the esp_lvgl_port component. This component, used in the ready-to-use projects, provides helper functions for easy installation of LVGL and display drivers. Moreover, it can add support for touch, rotary encoders, button or USB HID inputs. It simplifies power savings, screen rotation and other platform specific nuances.

The esp_lvgl_port supports LVGL versions 8 and 9 and is compatible with ESP-IDF v4.4 and above. To add it to your project, use the following command:

sh
idf.py add-dependency "espressif/esp_lvgl_port^2.3.0"

By default, esp_lvgl_port depends on the latest stable version of LVGL, so no additional steps are needed for new projects. If a specific LVGL version is required, specify this in your project to avoid automatic updates. LVGL can also be used without esp_lvgl_port, as described below.

Obtaining LVGL

LVGL is distributed through ESP Registry, where all LVGL releases are uploaded. In case you do not want to use esp_lvgl_port, you can add LVGL component into your project with following command:

sh
idf.py add-dependency "lvgl/lvgl^9.*"

Adjust the ^9.* part to match your LVGL version requirement. More information on version specifications can be found in the IDF Component Manager documentation. During the next build, the LVGL component will be fetched from the component registry and added to the project.

Advanced usage: Use LVGL as local component

For LVGL development and testing, it may be useful to use LVGL as a local component instead of from the ESP Registry, which offers only released versions and does not allow local modifications. To do this, clone LVGL to your project with the following command:

sh
git submodule add https://github.com/lvgl/lvgl.git components/lvgl

All components from ${project_dir}/components are automatically added to the build.

Display Integration

For a successful LVGL project, you will need a display driver and optionally a touch driver. Espressif provides these drivers that are built on its esp_lcd component.

These components share a common public API, making it easy to migrate your projects across different display and touch drivers.

To add a display or touch driver to your project, use a command like:

sh
idf.py add-dependency "espressif/esp_lcd_gc9a01^2.0.0"

Configuration

To configure LVGL, launch the configuration menu with idf.py menuconfig in your project root directory. Navigate to Component config and then LVGL configuration.

The current LVGL settings can be made permanent for the project by creating a file called sdkconfig.defaults in the project root and moving the CONFIG_LV_ symbols to it.

Per-chip defaults are possible too: a defaults file whose name ends with the chip variant is applied only to that chip. For example, sdkconfig.esp32p4 applies only to an ESP32-P4 IDF project.

Starting the LVGL component

Once the IDF project and the LVGL component have been configured, the early initialization is ready to use, but the LVGL subsystem still has to be started manually by calling bsp_display_start(), or lvgl_port_init() if LVGL was configured manually, for example without the esp_bsp component.

After calling this function, LVGL will be running in the background; that is, unlike the usual approach, there is no need to periodically call lv_timer_handler, this function is called by a background task managed by the IDF.

 
void app_main(void)
{
    bsp_display_start();
    bsp_display_backlight_on();

    bsp_display_lock(0);
    lv_demo_benchmark();
    bsp_display_unlock();
}

For cases when the esp_bsp is not being used, it is possible to invoke the ESP-LVGL port directly:

 
void app_main(void)
{
    const lvgl_port_cfg_t lvgl_cfg = ESP_LVGL_PORT_INIT_CONFIG();
    esp_err_t err = lvgl_port_init(&lvgl_cfg);

    lv_demo_benchmark();
}

Building and Flashing

Building an IDF project that uses LVGL is no different from any other IDF project. On the command line, several commands can be combined into one:

sh
idf.py build flash monitor

After flashing, the monitor console is launched automatically.

Last updated on

On this page