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.

ESP-IDF Examples

The ESP-IDF example programs are located in the examples/ESP-IDF directory of the example package. Each example is an independent project and targets the esp32 chip.

Preparation Before Use

  1. Install and initialize ESP-IDF with ESP32 support. ESP-IDF 6.0.2 is recommended.
  2. Open any example directory in a terminal where ESP-IDF has been initialized.
  3. Connect the board to your computer via USB, and identify its serial port name (e.g., COM5 under Windows).

Navigate to the corresponding example directory and run:

idf.py set-target esp32
idf.py build
idf.py -p COM5 flash monitor

Replace COM5 with the actual serial port name. To exit the serial monitor, press Ctrl-]. On the first build, the component manager will automatically download the dependencies declared by the project, so a network connection is required.

Example

01_HelloWorld

This example prints Hello world!, chip features, Flash size, and minimum free heap size to the serial port; then it outputs a restart countdown every second and reboots automatically when the countdown ends. It can be used to verify that the ESP-IDF environment, flashing path, and serial monitor are working properly.

ESP32-DEV-KIT-XX-IDF-TestDemo

02_RGB

This example drives the onboard addressable RGB LED. The current sdkconfig selects the RMT driver, the data pin is GPIO27, and the blinking period is 1000 ms. The RGB value when the LED is on is (16, 16, 16).

ESP32-DEV-KIT-XX-IDF-TestDemo

03_UART

This example uses UART1 for asynchronous transmission and reception, with the chip's internal software loopback enabled, so no external jumper is required. A transmit task sends the string Hello world every 2 seconds. A receive task reads the loopback data and outputs it to the serial monitor in both text and hexadecimal formats.

The current communication parameters are 115200 bps, 8 data bits, no parity, 1 stop bit, and no hardware flow control.

04_WIFI

This example connects to Wi-Fi, then sends an HTTP request to the OpenWeather API to obtain real-time weather data for Beijing and outputs the server response to the serial port. After one request completes, it waits for 30 minutes before sending the next request.

Before flashing, run idf.py menuconfig and enter the Wi-Fi SSID and password in Example Connection Configuration. When connecting to a 2.4 GHz network, make sure the router has the corresponding band enabled.

Note: The weather API URL, location, and access key are fixed in main/main.c and use plain HTTP. Before using this in a product or on a public network, you should replace these with your own key and use HTTPS, certificate validation, and secure key management.

ESP32-DEV-KIT-XX-IDF-TestDemo

05_Bluetooth

This example starts a BLE GATT Server with the advertisement name ESP_GATTS_DEMO, waiting for a phone or other BLE GATT Client to connect. The service contains two 16‑bit UUIDs:

Service UUIDCharacteristic UUIDFeatures
0x00FF0xFF01Read, Write, Notify, Indicate
0x00EE0xEE01Read, Write, Notify

Use a phone BLE debugging tool to scan and connect to ESP_GATTS_DEMO, then read or write data.

Common Issues

  • Cannot flash or find serial port: Check the USB cable, the serial port number in Device Manager, and whether the board has entered download mode.
  • Wrong build target: In the example root directory, re-run idf.py fullclean and idf.py set-target esp32, then build again.
  • Component download fails: Check the network connection and ESP-IDF Component Manager configuration, then retry.
  • UART receives no data: This example uses internal software loopback and does not require external wiring. Verify that the 03_UART example is flashed and check the serial log for UART initialization errors.
  • Wi-Fi cannot connect: Verify the SSID, password, and availability of the 2.4 GHz network; the serial log will provide the reason for connection failure.