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.
- 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
The V1 examples require ESP-IDF V5.1.4 or later. Note: When using ESP-IDF V5.2.0 or later, 10_FactoryProgram may fail to scan for nearby Wi-Fi networks. To test this feature, please compile with an earlier version, or directly flash the BIN firmware provided in the V1 resource package.
The 09_LVGL_V9_Test in the V2 repository is configured for ESP-IDF V5.5.2, with its dependency lock file pinned to V5.5.4. When working with V2 examples, please prioritize using ESP-IDF V5.5.x.
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
Some pin definitions differ between V1 and V2, so the ESP-IDF example programs are not interchangeable. Please confirm the actual hardware version of your board first, and then download the corresponding version from Related Resources.
The ESP-IDF example programs are located in:
- V1:
ESP-IDF - V2:
02_Example/ESP-IDF
The following example descriptions are based on the V1 package. The directory names and implementations of V2 examples may differ; please refer to the programs in the V2 repository.

| Example | Basic Description | Dependency Library |
|---|---|---|
| 01_ADC_Test | Read the current system voltage value | - |
| 02_I2C_PCF85063 | Print real-time time from the RTC chip | - |
| 03_I2C_QMI8658 | Print the raw data from the IMU | - |
| 04_SD_Card | Load and display TF card information | - |
| 05_WIFI_STA | Set to STA mode, connect to Wi-Fi and obtain IP address | - |
| 06_WIFI_AP | Set to AP mode to obtain the IP address of the access device | - |
| 07_EX_GPIO | Use extended I/O and internal I/O | - |
| 08_Li_ION_Test | Enable lithium battery | - |
| 09_LVGL_Test | LVGL example | LVGL |
| 10_FactoryProgram | Comprehensive project | LVGL |
01_ADC_Test
This example converts the analog voltage connected through GPIO to digital values via ADC, then calculates the actual system voltage and prints it to the terminal.

| ADC_CHAN | GPIO_PIN |
|---|---|
| ADC2_CHANNEL_6 | GPIO17 |
Code Walkthrough
adc_bsp_init(void): Initializes ADC2, which includes creating an ADC oneshot unit and configuring ADC2 channel 6.adc_get_value(float *value, int *data): Reads the value from ADC2 channel 6 and calculates the corresponding voltage based on the reference voltage and resolution. If the read fails, it stores a value of 0.adc_example(void* parameter): After initializing ADC2, this function creates an ADC task that reads the ADC value and calculates the system voltage every 1 second.
Expected Behavior: Once the program is flashed, open the Serial Monitor to view the printed ADC values and voltages. The ADC sample value is approximately 1628, and the BAT voltage is about 4.2 V.
02_I2C_PCF85063
This example uses the I2C protocol to initialize the PCF85063 chip, set the time, periodically read the time, and print it to the terminal.
| RTC | GPIO_PIN |
|---|---|
| RTC_SDA | GPIO47 |
| RTC_SCL | GPIO48 |
| RTC_INT | EXIO4 |
Code Walkthrough
void PCF85063_example(void* parameter): Creates an RTC task to implement RTC functionality. It reads the clock from the RTC chip every 10 seconds and outputs it to the terminal.
Expected Behavior: Once the firmware is flashed, open the Serial Monitor to view the printed RTC time. The data is output every 10 seconds.
03_I2C_QMI8658
This example uses the I2C protocol to initialize the QMI8658 chip, then reads the corresponding attitude data and prints it to the terminal every 1 second.
| IMU | GPIO_PIN |
|---|---|
| IMU_SDA | GPIO47 |
| IMU_SCL | GPIO48 |
| IMU_INT1 | EXIO4 |
| IMU_INT2 | EXIO3 |
Code Walkthrough
qmi8658c_example(void* parameter): Initializes the QMI8658 device. In an infinite loop, it reads and prints the accelerometer, gyroscope, and temperature data every 1 second.
Expected Behavior: Open the Serial Monitor to view the raw data from the IMU (Euler angles need to be converted manually). The data is output every 1 second.
04_SD_Card
This example uses a macro definition to select either SPI or SDMMC to drive the TF card. Once the TF card is successfully mounted, its information is printed to the terminal.

| SPI/MMC | GPIO_PIN |
|---|---|
| CS | GPIO2 |
| MISO/D0 | GPIO6 |
| MOSI/CMD | GPIO5 |
| SCLK/MCLK | GPIO4 |
Code Walkthrough
- The user can select the communication protocol for the TF card. In the
sd_card_bsp.csource file, find the macroSD_Read_Mode. By default, it uses the SDMMC communication protocol, but can be changed to SDSPI.
#define SD_Read_Mode USER_SPI
Expected Behavior: Click on the Serial Monitor device to view the printed TF card information. practical_size indicates the actual capacity of the TF card.
05_WIFI_STA
This example configures the development board as a station that can connect to an available AP. Upon successful connection, it prints the obtained IP information to the terminal.

Code Modification: This project configures the chip in STA mode and connects to Wi-Fi. Before compiling and downloading the firmware, modify the Wi-Fi SSID and password in the code to match your network credentials.
Code Walkthrough
espwifi_Init(void): Initializes Wi-Fi on the ESP32. It sequentially initializes non-volatile storage, the TCP/IP stack, creates the default event loop and the default Wi-Fi station network interface, registers event handlers, sets Wi-Fi connection parameters, and starts Wi-Fi.
Expected Behavior: The chip connects to Wi-Fi in STA mode and obtains an IP address.
06_WIFI_AP
This example configures the development board as an Access Point (AP) waiting for STA connections. Upon a successful connection, the assigned IP address is printed to the terminal.
Code Walkthrough
wifi_init_softap(void): Initializes the ESP32's Wi-Fi SoftAP, including setting up the network interface, registering event handlers, configuring SoftAP parameters, and starting the SoftAP.
Expected Behavior: When the chip is in AP mode, after a phone connects to the Wi-Fi, the serial port outputs the MAC address and assigned IP address of that device.
07_EX_GPIO
This example tests the basic functionality of the extended I/O and internal GPIO.

Hardware Connection: You need to use two wires to connect EXIO5 to EXIO6, and GPIO2 to GPIO1.
| GPIOx | GPIOy |
|---|---|
| GPIO1 | GPIO2 |
| EXIO5 | EXIO6 |
Code Walkthrough
I2C_master_Init(): Initializes I2C, which is the communication protocol for the external extended I/O.esp32_gpio_init(): Initializes GPIO, setting GPIO1 and EXIO5 as outputs, and GPIO2 and EXIO6 as inputs.example_GPIO_task(): Creates a separate task to test GPIO functionality; can be modified as needed.
Expected Behavior: The serial monitor outputs GPIO test passed. to indicate success, and GPIO test failed. to indicate failure.
08_Li_ION_Test
This example controls GPIO to enable power supply from the lithium battery.
Code Walkthrough
BAT_GPIO_Init(): Uses GPIO16 to control the lithium battery power supply; initializes GPIO16.BAT_ON(): Enables the lithium battery to supply power to the system.BAT_OFF(): Disables the lithium battery power supply to the system.
Expected Behavior: After enabling the lithium battery power supply in software, connect the battery, and then the PWR button can be used to control power delivery from the lithium battery.
09_LVGL_Test
This example ports LVGL to implement some multi-functional GUI interfaces on the screen.
Rotate_90
Rotate_NONO
Code Walkthrough
lv_demo_widgets(): Verifies screen performance by running an LVGL example.
Code Modification: If you need to rotate the display 90 degrees, locate the AMOLED_Rotate macro definition in the source file where main() resides, and choose one of the two:
#define AMOLED_Rotate Rotate_90 // Landscape
#define AMOLED_Rotate Rotate_NONO // Portrait
Expected Behavior: The LVGL example consumes a significant amount of RAM and ROM; ensure the development board is configured according to the environment setup requirements. The operation result after programming is shown in the images above.
10_FactoryProgram
This example is a comprehensive project that tests onboard features.
This note applies only to V1: When compiled with ESP-IDF V5.2.0 or later, the program may fail to scan for nearby Wi-Fi networks. If you need to test this, compile with an older version, or directly flash the BIN firmware provided in the V1 package.
Expected Behavior
- Swipe left or right to switch pages. It first displays RGB colors every 1.5 seconds to check the screen for issues.
- After displaying RGB, it automatically jumps to the clock interface.
- Swipe left to see onboard hardware information.
- Swipe left again to enter the function interface.
- Tap the Wi-Fi icon to enter the Wi-Fi test interface, then tap "Scan" to search for nearby Wi-Fi networks.
- Tap the BLE icon to enter the BLE test screen, then tap "Scan" to search for nearby BLE devices.
- Swipe left again to enter the brightness adjustment interface.