Compiling the Blink Program

This section takes the Blink program as an example to demonstrate the compilation process of a simple ESP-IDF program. It is important to note that this section uses the high/low level of GPIO to drive the LED. However, the WS2812 indicator light requires a special communication protocol. You can refer to the example program in esp-idf/examples/peripherals/rmt/led_strip for more information.

1. Open a new terminal and import the ESP-IDF environment variables

For Linux and Mac systems, use cd ~/esp/esp-idf to navigate to the ESP-IDF folder. Then, import the ESP-IDF environment variables using the command . ./export.sh. This process also performs a complete integrity check of the development environment.

💡 Tip

Please note that the dot before the space should not be omitted in . ./export.sh. The dot is equivalent to the source directive, which refers to executing the script and changing the environment variables in the current shell.

For Windows systems, you can directly find and open ESP-IDF 4.3 CMD or ESP-IDF 4.3 PowerShell in the program list. After the terminal is opened, the environment variables will be automatically added, as shown in Figure 4.16.

Figure 4.16. Automatic addition of environment variables in Windows system

Before compiling the project, navigate to the root directory of the project. To do this, use the command cd examples/get-started/blink.

3. Set the compilation target to ESP32-C3

Use the command idf.py set-target esp32c3 to set the compilation target to ESP32-C3, as shown in Figure 4.17. If this step is skipped, the compilation target defaults to ESP32.

Figure 4.17. Set the compilation target to ESP32-C3

4. Configure GPIOs

Use the command idf.py menuconfig to enter the configuration interface. Navigate using the up/down keys and press Enter key to enter the Example Configuration. Enter a number to change the GPIO to the specified pin, as shown in Figure 4.18. Save the configuration by following the prompts.

Figure 4.18. Configure GPIO using menuconfig

5. Build the code

Use the command idf.py build to build the code. The code building process is shown in Figure 4.19. Relevant prompts and flash commands will be printed once the build is complete, as shown in Figure 4.20.

Figure 4.19. Code compilation process
Figure 4.20. Prompt after code compilation is completed