Skip to main content

Working with ESP-IDF

This chapter includes 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

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.

lvgl_brookesia_01

This example uses lvgl and brookesia components to build an APP-style interface that can be developed and installed independently for various applications.

ESP32-C6-Touch-LCD-1.83 ESP-IDF Example 1 Figure 1
ESP32-C6-Touch-LCD-1.83 ESP-IDF Example 1 Figure 2
ESP32-C6-Touch-LCD-1.83 ESP-IDF Example 1 Figure 3
ESP32-C6-Touch-LCD-1.83 ESP-IDF Example 1 Figure 4
ESP32-C6-Touch-LCD-1.83 ESP-IDF Example 1 Figure 5
ESP32-C6-Touch-LCD-1.83 ESP-IDF Example 1 Figure 6

i2s_es7210_rec_02

This example uses the ES7210 encoding chip for recording tests, and the audio file is stored in the root directory of the TF card.

ESP32-C6-Touch-LCD-1.83 ESP-IDF Example 2 Figure 1

Code Analysis

  • Initialize the TF card and the ES7210 chip:

    /* Init I2C bus to configure ES7210 and I2S bus to receive audio data from ES7210 */
    i2s_chan_handle_t i2s_rx_chan = es7210_i2s_init();
    /* Create ES7210 device handle and configure codec parameters */
    es7210_codec_init();
    /* Mount TF card, the recorded audio file will be saved into it */
    sdmmc_card_t *sdmmc_card = mount_sdcard();
  • Start recording:

    esp_err_t err = record_wav(i2s_rx_chan);

mp3_play_03

This example uses ES8311 to play MP3 audio from the TF card, the audio name needs to be set to 1.MP3.

ESP32-C6-Touch-LCD-1.83 ESP-IDF Example 3 Figure 1

Code Analysis

  • Initialize the TF card and the ES8311 chip, and initialize the MP3 playback library:

    sd_card_init();
    ESP_ERROR_CHECK(esp_board_init(16000, 1, 16));
    //esp_sdcard_init("/sdcard", 10);
    Audio_Play_Init();
  • Play the MP3:

    Audio_Play_Music("file://sdcard/1.mp3");

lvgl_example_04

This example ports LVGL and plays the LVGL example

ESP32-C6-Touch-LCD-1.83 ESP-IDF Example 4 Figure 1

Code Analysis

  • Initialize I2C, LCD, touch IC, and LVGL:

    i2c_master_init();

    lcd_driver_init();
    touch_driver_init();
    lvgl_driver_init();
  • Use the LVGL mutex to load the official LVGL example:

    lvgl_port_lock(0);
    lv_demo_stress();
    lvgl_port_unlock();

AXP2101_05

This example drives the AXP2101 and prints battery-related information

ESP32-C6-Touch-LCD-1.83 ESP-IDF Example 5 Figure 1

Code Analysis

  • Initialize I2C and the AXP2101:

    ESP_ERROR_CHECK(i2c_init());
    ESP_LOGI(TAG, "I2C initialized successfully");

    ESP_ERROR_CHECK(pmu_init());
  • Create a printing task:

    xTaskCreate(pmu_hander_task, "App/pwr", 4 * 1024, NULL, 10, NULL);

lvgl_image_06

This example uses lvgl to display images, and you can switch between images by swiping left and right.

ESP32-C6-Touch-LCD-1.83 ESP-IDF Example 6 Figure 1

Code Analysis

  • Use the LVGL mutex to initialize image display:

    lvgl_port_lock(0);
    image_slider_init();
    lvgl_port_unlock();