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.
- Section 1: Environment Setup
- Section 2: Running Examples
- Section 3: Creating a Project
- Section 4: Using Components
- Section 5: Debugging
- Section 6: FreeRTOS
- Section 7: Peripherals
- Section 8: Wi-Fi Programming
- Section 9: BLE Programming
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
For the ESP32-S3-Touch-LCD-1.85B development board, ESP-IDF V5.5.3 or above is required.
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.
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
-
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).

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).

Please wait for both files to finish downloading.
-
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.

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.

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

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

Install Visual Studio Code and the ESP-IDF Extension
-
Download and install Visual Studio Code.
-
During installation, it is recommended to check Add "Open with Code" action to Windows Explorer file context menu to facilitate opening project folders quickly.
-
In VS Code, click the Extensions icon
in the Activity Bar on the side (or use the shortcut Ctrl + Shift + X) to open the Extensions view.
-
Enter ESP-IDF in the search box, locate the ESP-IDF extension, and click Install.

-
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.
| Example | Basic Description |
|---|---|
| 01_comprehensive_example | Comprehensive example program driving LCD, audio, and onboard sensors |
| 02_lvgl_demo | Display LVGL demo |
| 03_mp3_player | Scan the TF card and play MP3 |
| 04_esp_wakeword_det | Use the esp-sr component to implement voice wake‑up and command word recognition |
| 05_esp-brookesia | Display an LVGL APP‑style UI using the brookesia component |
| 06_qmi8658_test | Test the gyroscope |
| 07_pcf85063_test | Test the RTC real‑time clock |
| 08_bq27220_test | Test the onboard battery monitoring IC |
01_comprehensive_example
Example Description
- This is a comprehensive example program demonstrating LCD touch screen driving, LVGL initialization, audio driving, and various onboard peripherals.
Hardware Connection
- Insert a 3.7V Li‑ion battery or connect the development board to a computer.
A TF card is required (create a
musicfolder in the root directory to store MP3 files).
Code Analysis
-
Initialize the screen, touch, backlight, LVGL, and TF card:
lv_display_t *disp = bsp_display_start();lv_indev_t *tp = bsp_display_get_input_dev();bsp_display_backlight_on();bsp_sdcard_mount(); -
Initialize the audio player, onboard sensors, and wake‑word detection task:
Audio_Play_Init();msg_driver_init();wake_word_drv_init(); -
Scan for MP3 files in the
musicfolder:esp_err_t err = get_file_list_by_ext("/sdcard/music",".mp3",&mp3_files);if (err == ESP_OK) {for (int i = 0; i < mp3_files.count; i++) {printf("MP3[%d]: %s\n", i, mp3_files.list[i]);}} -
Create the UI:
bsp_display_lock(-1);main_screen = lv_obj_create(NULL);lv_obj_t * tv = lv_tileview_create(main_screen);lv_obj_t * tile1 = lv_tileview_add_tile(tv, 0, 0, LV_DIR_RIGHT);msg_ui_screen_init(main_screen,tile1);lv_obj_t * tile2 = lv_tileview_add_tile(tv, 1, 0, LV_DIR_LEFT | LV_DIR_RIGHT);init_music_ui_screen(tile2,&mp3_files);lv_obj_t * tile3 = lv_tileview_add_tile(tv, 2, 0, LV_DIR_LEFT);eaf_ui_screen_init(tile3);lv_screen_load(main_screen);bsp_display_unlock(); -
Test voice wake‑up and command word instructions::
// Wake wordHi,ESP// CommandsTurn on the backlightTurn off the backlightBacklight is brightestBacklight is darkest
Operation Result
- Three screens are displayed using LVGL's tileview; swipe left/right to switch.
![]() | ![]() |
|---|
![]() | ![]() |
|---|
![]() | ![]() |
|---|
02_lvgl_demo
Example Description
- This example shows the official LVGL example.
Hardware Connection
- Connect the development board to the computer.
Code Analysis
-
Load the LVGL demo:
bsp_display_lock(-1);lv_demo_widgets();bsp_display_unlock();
Operation Result

03_mp3_player
Example Description
- This example tests TF card initialization, scanning for MP3 files, and playing them.
Hardware Connection
- Connect the development board to the computer.
A TF card is required (create a
musicfolder in the root directory to store MP3 files).
Code Analysis
-
Scan for MP3 files and save the file names:
void Search_Music(void){esp_err_t err = get_file_list_by_ext("/sdcard/music",".mp3",&MP3_files);if (err == ESP_OK) {for (int i = 0; i < MP3_files.count; i++) {printf("MP3:[%d]: %s\n", i, MP3_files.list[i]);}}file_count = MP3_files.count;}
Operation Result

04_esp_wakeword_det
Example Description
- This example demonstrates offline voice wake-up and speech recognition using the ESP-SR component
Hardware Connection
- Connect the development board to the computer.
- Do not block the microphone
Code Analysis
-
Initialize the microphone and obtain a handle:
record_dev = bsp_audio_codec_microphone_init();esp_codec_dev_sample_info_t fs = {.bits_per_sample = 32,.channel = 2,.sample_rate = 16000,};esp_codec_dev_set_in_gain(record_dev, 30.0);esp_codec_dev_open(record_dev, &fs); -
Initialize the voice model:
models = esp_srmodel_init("model"); // partition label defined in partitions.csvafe_config_t *afe_config = afe_config_init(bsp_get_input_format(), models, AFE_TYPE_SR, AFE_MODE_LOW_COST);afe_handle = esp_afe_handle_from_config(afe_config);esp_afe_sr_data_t *afe_data = afe_handle->create_from_config(afe_config);afe_config_free(afe_config);xTaskCreatePinnedToCore(&detect_Task, "detect", 8 * 1024, (void*)afe_data, 5, NULL, 0);xTaskCreatePinnedToCore(&feed_Task, "feed", 8 * 1024, (void*)afe_data, 5, NULL, 1);
Operation Result

05_esp-brookesia
Example Description
- This example demonstrates a complete phone-style UI system, including components such as a status bar, navigation bar, app launcher, and gesture interaction
Hardware Connection
- Connect the development board to the computer.
Code Analysis
-
Initialize the phone UI:
ESP_LOGI(TAG, "Create phone object");systems::phone::Phone *phone = new systems::phone::Phone(disp);phone->setTouchDevice(tp);Stylesheet *stylesheet = new systems::phone::Stylesheet(STYLESHEET_360_360_DARK);ESP_UTILS_CHECK_NULL_EXIT(stylesheet, "Create stylesheet failed");ESP_UTILS_LOGI("Using stylesheet (%s)", stylesheet->core.name);ESP_UTILS_CHECK_FALSE_EXIT(phone->addStylesheet(stylesheet), "Add stylesheet failed");ESP_UTILS_CHECK_FALSE_EXIT(phone->activateStylesheet(stylesheet), "Activate stylesheet failed");delete stylesheet; -
Install the SquarelineDemo app:
auto app3 = esp_brookesia::apps::SquarelineDemo::requestInstance();ESP_UTILS_CHECK_FALSE_EXIT(phone->installApp(app3),"start Drawpanel failed");
Operation Result
![]() | ![]() |
|---|
![]() | ![]() |
|---|
06_qmi8658_test
Example Description
- This example tests the QMI8658 gyroscope driver.
Hardware Connection
- Connect the development board to the computer.
Code Analysis
-
Initialize the QMI8658 and read data in a loop:
void app_main(void){qmi8658_dev = bsp_qmi8658_drv_init();while (1){qmi8658_data_t data;bool ready;esp_err_t ret = qmi8658_is_data_ready(qmi8658_dev, &ready);if (ret == ESP_OK && ready){ret = qmi8658_read_sensor_data(qmi8658_dev, &data);if (ret == ESP_OK){ESP_LOGI("TAG", "Accel: X=%.4f m/s², Y=%.4f m/s², Z=%.4f m/s²",data.accelX, data.accelY, data.accelZ);ESP_LOGI("TAG", "Gyro: X=%.4f rad/s, Y=%.4f rad/s, Z=%.4f rad/s",data.gyroX, data.gyroY, data.gyroZ);ESP_LOGI("TAG", "Temp: %.2f °C, Timestamp: %lu",data.temperature, data.timestamp);}}vTaskDelay(pdMS_TO_TICKS(1000));}}
Operation Result
-
Open the serial monitor

07_pcf85063_test
Example Description
- This example tests the RTC real‑time clock.
Hardware Connection
- Connect the development board to the computer.
- Insert a 3.7V Li‑ion battery (without a battery, RTC data cannot be read).
Code Analysis
-
Initialize the PCF85063A and set the time:
esp_err_t ret = pcf85063a_init(&dev, bus_handle, PCF85063A_ADDRESS);if (ret != ESP_OK) {ESP_LOGE(TAG, "Failed to initialize PCF85063A (error: %d)", ret);vTaskDelete(NULL);}ESP_LOGI(TAG, "Set current time.");pcf85063a_set_time_date(&dev, Set_Time);
Operation Result
-
Open the serial monitor

08_bq27220_test
Example Description
- This example tests the battery fuel gauge chip.
Hardware Connection
- Insert a 3.7V Li‑ion battery (without a battery, battery data cannot be read).
Code Analysis
-
Initialize the BQ27220:
bq27220_handle_t bq27220_drv_init(void){i2c_bus = bsp_i2c_bus_get_handle();bq27220_config_t bq27220_cfg = {.i2c_bus = i2c_bus,.cfg = &default_config,.cedv = &default_cedv,};bq27220 = bq27220_create(&bq27220_cfg);if (!bq27220) {ESP_LOGE(TAG, "bq27220 create failed");}return bq27220;} -
Print battery‑related information:
static void test_bq27220_print_info(bq27220_handle_t bq27220Handle){battery_status_t status = {};bq27220_get_battery_status(bq27220Handle, &status);ESP_LOGI(TAG, "Battery Status1 - DSG:%d SYSDWN:%d TDA:%d BATTPRES:%d AUTH_GD:%d OCVGD:%d TCA:%d RSVD:%d",status.DSG, status.SYSDWN, status.TDA, status.BATTPRES,status.AUTH_GD, status.OCVGD, status.TCA, status.RSVD);ESP_LOGI(TAG, "Battery Status2 - CHGINH:%d FC:%d OTD:%d OTC:%d SLEEP:%d OCVFAIL:%d OCVCOMP:%d FD:%d",status.CHGINH, status.FC, status.OTD, status.OTC,status.SLEEP, status.OCVFAIL, status.OCVCOMP, status.FD);uint16_t vol = bq27220_get_voltage(bq27220Handle);int16_t current = bq27220_get_current(bq27220Handle);uint16_t rc = bq27220_get_remaining_capacity(bq27220Handle);uint16_t full_cap = bq27220_get_full_charge_capacity(bq27220Handle);uint16_t temp = bq27220_get_temperature(bq27220Handle) / 10 - 273;uint16_t cycle_cnt = bq27220_get_cycle_count(bq27220Handle);uint16_t soc = bq27220_get_state_of_charge(bq27220Handle);int16_t avg_power = bq27220_get_average_power(bq27220Handle);int16_t max_load = bq27220_get_maxload_current(bq27220Handle);uint16_t time_to_empty = bq27220_get_time_to_empty(bq27220Handle);uint16_t time_to_full = bq27220_get_time_to_full(bq27220Handle);ESP_LOGI(TAG,"Battery Info - Vol:%dmV Cur:%dmA Pwr:%dmW RC:%dmAh FCC:%dmAh ""Temp:%dC Cycle:%d SOC:%d%% MaxLoad:%dmA TTE:%dmin TTF:%dmin",vol, current, avg_power, rc, full_cap, temp,cycle_cnt, soc, max_load, time_to_empty, time_to_full);}
Operation Result
-
Open the serial monitor










