Skip to main content

Working with ESP-IDF

This chapter includes the following two sections, please read as needed:

Setting up the Development Environment

info

For the ESP32-C6-GEEK development board, it is recommended to use ESP-IDF V5.5.0 or higher.

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.

01_SD_Card

This demo demonstrates how to use ESP32-C6-GEEK to test the read and write functions of the TF card

ESP32-C6-GEEK ESP-IDF Example 1 Figure 1

Additional Preparation

  • Insert the TF card into the card slot (TF card needs to be formatted as FAT32)

Code Analysis

  • Initialize the TF card using SDSPI mode:

      SD_card_Init();
  • Test TF card read/write functionality:

     example_sdcard_task();

02_WIFI_AP

This demo can set the development board as a hotspot, allowing phones or other devices in STA mode to connect to the development board.

ESP32-C6-GEEK ESP-IDF Example 2 Figure 1

Code Analysis

  • In the file softap_example_main.c, find SSID and PASSWORD, and then your phone or other device in STA mode can use the SSID and PASSWORD to connect to the development board.

      #define EXAMPLE_ESP_WIFI_SSID      "waveshare_esp32"
    #define EXAMPLE_ESP_WIFI_PASSWORD "wav123456"

03_WIFI_STA

This example can configure the development board as a STA device to connect to a router, thereby enabling access to the system network.

ESP32-C6-GEEK ESP-IDF Example 3 Figure 1

Code Analysis In the file esp_wifi_bsp.c, find ssid and password, then modify them to the SSID and Password of an available router in your current environment.

  wifi_config_t wifi_config = {
.sta = {
.ssid = "PDCN",
.password = "1234567890",
},
};

04_Button

This example demonstrates how to use the Boot button as a multi-functional button, capable of performing different actions such as single-click, double-click, or long-press.

ESP32-C6-GEEK ESP-IDF Example 4 Figure 1

Code Analysis

  • Initialize the Boot button and bind the button event function:

      void button_init(void)
    {
    button_config_t btn_cfg = {0};
    button_gpio_config_t gpio_cfg = {
    .gpio_num = BOOT_BUTTON_NUM,
    .active_level = 0,
    .enable_power_save = true,
    };

    esp_err_t ret = iot_button_new_gpio_device(&btn_cfg, &gpio_cfg, &boot_btn);
    assert(ret == ESP_OK);
    ret |= iot_button_register_cb(boot_btn, BUTTON_SINGLE_CLICK, NULL, button_event_cb, NULL);
    ret |= iot_button_register_cb(boot_btn, BUTTON_DOUBLE_CLICK, NULL, button_event_cb, NULL);
    ret |= iot_button_register_cb(boot_btn, BUTTON_LONG_PRESS_START, NULL, button_event_cb, NULL);
    }

05_lvgl_example

Implement some multi-functional GUI interfaces on the screen by porting LVGL.

ESP32-C6-GEEK ESP-IDF Example 5 Figure 1

Code Analysis

  • Display text and LVGL version information:

      /* Task lock */
    lvgl_port_lock(0);

    lv_obj_t *label = lv_label_create(lv_scr_act());
    lv_snprintf(str, sizeof(str), "Hello LVGL \nVersion: V %d.%d.%d ", LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH);
    lv_label_set_text(label, str);
    lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);

    /* Task unlock */
    lvgl_port_unlock();