Skip to main content

ESP-IDF

This chapter contains the following sections. Please read as needed:

ESP-IDF Getting Started

New to ESP32 ESP-IDF development and looking to get started quickly? We have prepared a general Getting Started Tutorial for you.

Please Note: This tutorial uses the ESP32-S3-Zero as a teaching example, and all hardware code is based on its pinout. Before you start, it is recommended that you check the pinout of your development board to ensure the pin configuration is correct.

Setting Up the Development Environment

info

For the ESP32-S3-Touch-LCD-1.47 development board, ESP-IDF V5.5.0 or above is required.

note

The following guide uses Windows as an example, demonstrating development using VS Code + the ESP-IDF extension. macOS and Linux users should refer to the official documentation.

Version Selection

The screenshots in this section use ESP-IDF V5.5.2 as an example. When installing, please select the ESP-IDF version that matches your board's example.

Install the ESP-IDF Development Environment

  1. Download the installation manager from the ESP-IDF Installation Manager page. This is Espressif's latest cross-platform installer. The following steps demonstrate how to use its offline installation feature.

    Click the Offline Installer tab on the page, then select Windows as the operating system and the ESP-IDF version you need (the version shown in the screenshot is for reference only — choose the version that fits your actual needs).

    Download EIM and offline package

    After confirming your selection, click the download button. The browser will automatically download two files: the ESP-IDF Offline Package (.zst) and the ESP-IDF Installer (.exe).

    Download EIM and offline package 2

    Please wait for both files to finish downloading.

  2. Once the download is complete, double-click to run the ESP-IDF Installer (eim-gui-windows-x64.exe).

    The installer will automatically detect if the offline package exists in the same directory. Click Install from archive.

    Auto-detect offline package

    Next, select the installation path. We recommend using the default path. If you need to customize it, ensure the path does not contain Chinese characters or spaces. Click Start installation to proceed.

    Select installation path
  3. When you see the following screen, the ESP-IDF installation is successful.

    Installation successful
  4. We recommend installing the drivers as well. Click Finish installation, then select Install driver.

    Install drivers via ESP-IDF Installation Manager

Install Visual Studio Code and the ESP-IDF Extension

  1. Download and install Visual Studio Code.

  2. During installation, it is recommended to check Add "Open with Code" action to Windows Explorer file context menu to facilitate opening project folders quickly.

  3. In VS Code, click the Extensions icon Extensions Icon in the Activity Bar on the side (or use the shortcut Ctrl + Shift + X) to open the Extensions view.

  4. Enter ESP-IDF in the search box, locate the ESP-IDF extension, and click Install.

    Search and install ESP-IDF extension in VS Code

  5. For ESP-IDF extension versions ≥ 2.0, the extension will automatically detect and recognize the ESP-IDF environment installed in the previous steps, requiring no manual configuration.

Example

The ESP-IDF examples are located in the ESP-IDF directory of the example package.

ExampleBasic Program DescriptionDependency Library
01_factoryComprehensive test program-
02_sd_card_testTest TF card read/write-
03_lvgl_exampleLVGL example program-
04_lvgl_imageDisplay images using LVGLSensorLib
05_lvgl_sd_imageDisplay images from TF card using LVGL-

01_factory

Example Description

  • This example tests the functions of the onboard modules of the ESP32-S3-Touch-LCD-1.47. The screen will display information about each module, and the user can swipe left or right on the touchscreen to switch pages.

Hardware Connection

  • Connect the board to the computer.
  • Insert the TF card into the card slot.

Code Analysis

  • Peripheral initialization

    i2c_bus_handle = bsp_i2c_init();
    bsp_battery_init();
    bsp_wifi_init("WSTEST", "waveshare0755");
    bsp_display_init(&io_handle, &panel_handle, EXAMPLE_LCD_H_RES * EXAMPLE_LCD_DRAW_BUFF_HEIGHT);
    bsp_touch_init(&touch_handle, i2c_bus_handle, EXAMPLE_LCD_H_RES, EXAMPLE_LCD_V_RES, EXAMPLE_DISPLAY_ROTATION);
    bsp_sdcard_init();
    ESP_ERROR_CHECK(app_lvgl_init());
    lv_fs_fatfs_init();

    bsp_display_brightness_init();
    bsp_display_set_brightness(100);
  • LVGL graphics library configuration

    if (lvgl_port_lock(0))
    {
    lvgl_ui_init();
    lvgl_port_unlock();
    }

Operation Result

  • After flashing the program, open the Serial Terminal. If the device successfully connects to the hotspot, the obtained IP address will be output, as shown in the figure:

2_sd_card_test

Example Description

  • This example demonstrates testing TF card read/write functionality on the ESP32-S3-Touch-LCD-1.47.

Hardware Connection

  • Connect the board to the computer.
  • Insert the TF card into the card slot (the TF card needs to be formatted as FAT32).

Code Analysis

  • TF card initialization and mounting

    sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
    #if EXAMPLE_IS_UHS1
    slot_config.flags |= SDMMC_SLOT_FLAG_UHS1;
    #endif

    // Set bus width to use:
    #ifdef CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4
    slot_config.width = 4;
    #else
    slot_config.width = 1;
    #endif

    // On chips where the GPIOs used for the TF card can be configured, set them in
    // the slot_config structure:
    #ifdef CONFIG_SOC_SDMMC_USE_GPIO_MATRIX
    slot_config.clk = CONFIG_EXAMPLE_PIN_CLK;
    slot_config.cmd = CONFIG_EXAMPLE_PIN_CMD;
    slot_config.d0 = CONFIG_EXAMPLE_PIN_D0;
    #ifdef CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4
    slot_config.d1 = CONFIG_EXAMPLE_PIN_D1;
    slot_config.d2 = CONFIG_EXAMPLE_PIN_D2;
    slot_config.d3 = CONFIG_EXAMPLE_PIN_D3;
    #endif // CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4
    #endif // CONFIG_SOC_SDMMC_USE_GPIO_MATRIX

    // Enable internal pullups on enabled pins. The internal pullups
    // are insufficient however, please make sure 10k external pullups are
    // connected on the bus. This is for debug / example purpose only.
    slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP;

    ESP_LOGI(TAG, "Mounting filesystem");
    ret = esp_vfs_fat_sdmmc_mount(mount_point, &host, &slot_config, &mount_config, &card);

Operation Result

  • After flashing the program, open the Serial Terminal. If the device successfully connects to the hotspot, the obtained IP address will be output, as shown in the figure:

03_lvgl_example

Example Description

  • This example demonstrates running the LVGL example program on the ESP32-S3-Touch-LCD-1.47.

Hardware Connection

  • Connect the board to the computer.

Code Analysis

  • TF card initialization and mounting

    // lv_demo_benchmark();
    // lv_demo_music();
    lv_demo_widgets();
    lvgl_port_unlock();

Operation Result

04_lvgl_image

Example Description

  • This example demonstrates the ESP32-S3-Touch-LCD-1.47 running LVGL to display an image.

Hardware Connection

  • Connect the board to the computer.

Preparation

  • Copy image_1.c to the main folder.
  • Add image_1.c to the CMakeLists.txt in the main folder
idf_component_register(SRCS "main.c" "image_1.c"INCLUDE_DIRS ".")

Code Analysis

  • In main.c, add the following code to declare the image.

    LV_IMG_DECLARE(image_1);
  • Specify the image to be displayed.

    lv_img_set_src(img, &image_1);

Operation Result

05_lvgl_sd_image

Example Description

  • This example demonstrates the ESP32-S3-Touch-LCD-1.47 using LVGL to display images from a TF card, supporting image formats such as jpg, bmp, png, and bin.

Hardware Connection

  • Connect the board to the computer.
  • Insert the TF card into the card slot.

Hardware Connection

  • Insert the TF card into the computer.
  • Copy the images folder of this project to the root directory of the TF card.
  • Insert the TF card into the ESP32-S3-Touch-LCD-1.47.

Operation Result