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 Development Environment

info

For the ESP32-S3-ePaper-Driver-Board development board, ESP-IDF version 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.

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 choose your desired version from the filter bar.

    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.

Demo

The ESP-IDF demos are located in the ESP-IDF directory of the demo package.

DemoBasic Description
01_ADC_TestGet the lithium battery voltage value
02_Mic_testPlay microphone recording through the speaker
03_MusicMount TF card and read/play music files from it
04_E-Paper_Examplee‑Paper example program
05_SD_TestRead TF card and display images
06_xiaozhi-esp32Xiaozhi AI application

01_ADC_Test

Demo Description

  • The analog voltage connected through the GPIO is converted to digital by the ADC, and then the actual lithium battery voltage is calculated and printed to the terminal.

Hardware Connection

  • Connect the board to the computer using a USB cable

Code Analysis

  • adc_bsp_init(void): Initializes ADC1, including creating an ADC one-shot trigger unit and configuring Channel 7 of ADC1.
  • adc_get_value(float *value,int *data): Reads the value from Channel 7 of ADC1, calculates the corresponding voltage based on the reference voltage and resolution, and stores it at the location pointed to by the passed pointer. Stores 0 if the read fails.
  • adc_example(void* parameter): After initializing ADC1, creates an ADC task. This task reads the ADC value every second and calculates the system voltage from the raw ADC reading.

Operation Result

  • After the program is compiled and downloaded, you can view the printed ADC values and voltage output by opening the Serial Monitor, as shown in the following image:

02_Mic_test

Demo Description

  • Demonstrates how to get data from the microphone and then play it through the speaker

Hardware Connection

  • Connect the development board to the computer

Code Analysis

  • i2c_master_Init();: Initializes the I2C bus.
  • user_ui_init();: Initializes the global UI.
  • user_button_init();: Initializes the audio interface.

Operation Result

  • The screen shows nothing.

  • Long press the BOOT button to enter recording mode. Speak into the MIC, and it will automatically stop after 3 seconds.

  • Click the BOOT button to play the recorded sound. (If no recording exists, the played sound will be very harsh.)

  • Serial port prints:

03_Music

Demo Description

  • Mounts a TF card and reads/plays audio files from it.

Hardware Connection

  • Connect the development board to the computer
  • Connect a speaker to the SPK interface.

Code Analysis

  • _sdcard_init();: Initializes the TF card and reads the audio files from it.
  • i2c_master_init();: Initializes the I2C bus, providing a communication link for configuration command transmission to the ES8311 audio codec.
  • audio_player_play(audio_fp);: Starts the audio player, reads the opened MP3 file, and drives the speaker through the ES8311 for playback.

Operation Result

  • The screen shows nothing.
  • The speaker plays audio.

04_E-Paper_Example

Demo Description

  • This is a local ESP‑IDF example for the 13.3inch E6 e-Paper screen. It performs e‑Paper initialization, clears the screen, displays images, and draws basic graphics and text.

Hardware Connection

  • Connect the development board to the computer

Code Analysis

  • Display a predefined image:

    #if 1
    EPD_Display(Image6color);
    vTaskDelay(pdMS_TO_TICKS(3000));
    #endif
  • Draw basic shapes, Chinese/English text, numbers, and refresh the display:

    #if 1
    Paint_NewImage(Image_Mono, EPD_WIDTH, EPD_HEIGHT, 90, EPD_WHITE);
    Paint_SetScale(6);
    printf("SelectImage:Image\r\n");
    Paint_SelectImage(Image_Mono);
    Paint_Clear(EPD_WHITE);

    Paint_DrawPoint(10, 80, EPD_RED, DOT_PIXEL_1X1, DOT_STYLE_DFT);
    Paint_DrawPoint(10, 90, EPD_BLUE, DOT_PIXEL_2X2, DOT_STYLE_DFT);
    Paint_DrawPoint(10, 100, EPD_GREEN, DOT_PIXEL_3X3, DOT_STYLE_DFT);
    Paint_DrawLine(20, 70, 70, 120, EPD_YELLOW, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
    Paint_DrawLine(70, 70, 20, 120, EPD_YELLOW, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
    Paint_DrawRectangle(20, 70, 70, 120, EPD_BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
    Paint_DrawRectangle(80, 70, 130, 120, EPD_BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
    Paint_DrawCircle(45, 95, 20, EPD_BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
    Paint_DrawCircle(105, 95, 20, EPD_WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);
    Paint_DrawLine(85, 95, 125, 95, EPD_YELLOW, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
    Paint_DrawLine(105, 75, 105, 115, EPD_YELLOW, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
    Paint_DrawString_CN(10, 130, "你好 abc", &Font16_UTF8, EPD_BLACK, EPD_WHITE);
    Paint_DrawString_CN(10, 170, "微雪电子", &Font16_UTF8, EPD_WHITE, EPD_BLACK);
    Paint_DrawNum(10, 10, 123456789, &Font12, EPD_BLACK, EPD_WHITE);
    Paint_DrawNum(10, 40, 987654321, &Font12, EPD_WHITE, EPD_BLACK);
    Paint_DrawString_EN(145, 0, "Waveshare", &Font16, EPD_BLACK, EPD_WHITE);
    Paint_DrawString_EN(145, 35, "Waveshare", &Font16, EPD_GREEN, EPD_WHITE);
    Paint_DrawString_EN(145, 70, "Waveshare", &Font16, EPD_BLUE, EPD_WHITE);
    Paint_DrawString_EN(145, 105, "Waveshare", &Font16, EPD_RED, EPD_WHITE);
    Paint_DrawString_EN(145, 140, "Waveshare", &Font16, EPD_YELLOW, EPD_WHITE);

    printf("EPD_Display\r\n");
    EPD_Display(Image_Mono);
    vTaskDelay(pdMS_TO_TICKS(3000));
    #endif

Operation Result

  • The screen refreshes, clears, displays an image, and draws basic graphics and text.

05_SD_Test

Demo Description

  • This example reads BMP images from a TF card and refreshes them on the e-Paper display.

Hardware Connection

  • Connect the board to the computer using a USB cable
  • Insert the TF card module with a TF card containing a bmp folder with images in the root directory.

Code Analysis

  • _sdcard_init: TF card initialization
  • GUI_ReadBmp_RGB_6Color("/sdcard/bmp/13in3E.bmp", 0, 0);: Image decoding

Operation Result

  • Serial port prints TF card information.
  • Reads and displays images from the TF card.

06_xiaozhi-esp32

Hardware Connection

  • Connect the board to the computer using a USB cable
  • Copy all files from the TF card folder to sdcard, then insert the TF card module

Demo Description

  1. First download the Demo using your preferred method. After extracting, copy all files from the TF card directory to sdcard.
  2. The first boot will trigger a network configuration process. The voice will announce "Entering network configuration mode". At this point, use your phone to connect to Xiaozhi-xxx (where xxx is variable).
  3. After successful network configuration, go to the Xiaozhi Console and add the corresponding device.
  4. Three working modes: Basic Mode (Mode 1), Local Server Mode (Mode 2), and AI Conversation Mode (Mode 3).

Mode 1

  1. The default mode is AI Conversation Mode (Mode 3). Press and hold the BOOT button to enter mode selection (the voice will announce it). Then press the BOOT button once to select Basic Mode (Mode 1). Press and hold the BOOT button again to enter this mode.
  2. Add photos you want to display to the img directory on the TF card. Only 24‑bit BMP images with resolutions of 1600x1200 or 1200x1600 are accepted.
  3. Press the BOOT button once to display an image from the img directory.
  4. Press the BOOT button to cycle through images.

Mode 2

  1. Press and hold the BOOT button to enter mode selection; press the BOOT button twice, then press and hold the BOOT button again to enter this mode.
  2. Use your phone or computer to connect to the Wi-Fi esp_network with password 1234567890. After successful connection, go to the image selection interface as shown:
  3. On the web page, you can directly select, preview, and push images to the e‑paper display.
  4. For AP mode: first connect your phone or computer to the Wi-Fi with SSID esp_network (password: 1234567890), then visit http://192.168.4.1/index.html.
  5. For STA mode: first configure the network using Mode 3, then visit http://esp32-s3-photopainter-13_3.local/index.html.

Mode 3

  1. Press and hold the BOOT button to enter mode selection; press the BOOT button three times, then press and hold the BOOT button again to enter this mode.
  2. After initialization is complete, wake up the device with the wake word "Hello, Xiaozhi".
  3. After waking up, you can converse normally.
  4. Through conversation, you can retrieve and display the number of images in the img directory on the TF card.
  5. Regarding AI‑generated images: for example, you can say "Help me generate an image of the moon". To use this feature, you need to configure Volcanic Engine. Refer to Volcanic Engine Text‑to‑Image Configuration for details.

Volcanic Engine Text‑to‑Image Configuration

  1. Firstly, you need to obtain the access key, model name, and URL. Currently, a test model is being used, which will be discontinued later. Users need to configure their own models. The relevant code section and configuration in the config.txt file are shown below:
  2. Go to the Volcanic Engine Console
  3. Create the corresponding model. Be careful not to select the wrong model, as shown:
  4. Copy the corresponding key, model, and URL as shown:
  5. Paste the copied url, model, and key into the corresponding key‑value fields in the config.txt file located in the sdcard->img directory (see step 1, second image). New users can claim free Tokens.