Introduction
ESP32 is a powerful Wi-Fi and Bluetooth integrated microcontroller, widely used in IoT applications and remote control. ESP-IDF (Espressif IoT Development Framework) is the official development toolkit for ESP32 by Espressif, providing the necessary APIs and libraries for programming and managing the microcontroller.
Requirements
- ESP32: ESP32 microcontroller.
- Computer: PC or laptop with Windows, macOS, or Linux operating system.
- USB Cable: To connect ESP32 to the computer.
- ESP-IDF Software: The official development toolkit by Espressif.
Step 1: Install ESP-IDF
- Download ESP-IDF
Visit the official ESP-IDF website: ESP-IDF GitHub Repository.
Download the latest version or stable version according to the instructions on the GitHub page.
This is a new tutorial series where we will cover the ESP32 microprocessor with Espressif-IDE. ESP32 is becoming more and more popular, but there are not many tutorials covering this microprocessor with eclipse based IDE. That is why I decided to cover Espressif-IDE instead of arduino. This way we will understand the process better, and we will have more control over our application.
IDE Setup
Click next and wait for the IDE to be installed.
#define BLINK_GPIO GPIO_NUM_2
static uint8_t s_led_state = 0;
The LED on the ESP32 WROOM board is connected to GPIO_2, and so I defined BLINK_GPIO as GPIO_NUM_
Besides that, we also have s_led_state, which will be used later to change the state of the LED.
LED functions
static void configure_led(void)
{
gpio_reset_pin(BLINK_GPIO);
/* Set the GPIO as a push/pull output */
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
}
static void blink_led ( void )
{
/* Set the GPIO level according to the state (LOW or HIGH)*/
gpio_set_level ( BLINK_GPIO , s_led_state ) ;
}
The first function, configure_led, configures the LED pin (GPIO_2) as an output pin.
The second function, blink_led, will be called in the main function and is used to set the level of the LED pin.
main function
void app_main(void)
{
/* Configure the peripheral according to the LED type */
configure_led ( ) ;
while ( 1 ) {
blink_led ( ) ;
/* Toggle the LED state */
s_led_state = ! s_led_state ;
vTaskDelay ( 1000 / portTICK_PERIOD_MS ) ;
} In the main function, we will first configure the LED pin.
Then in the while loop, we will blink the LED every 1000 ms.
The value of s_led_state will change after each call to the blink function, and its value will be either 0 or 1, depending on the final value.
Result
Below is a picture of the LED on the board in ON and OFF
Additional Learning Resources
- Official Documentation: Espressif Documentation
- Support Forum: Espressif Community
- Practical Guide: Articles and tutorial videos on YouTube and Espressif’s website.
Conclusion
By following the steps above, you have successfully set up the ESP-IDF development environment and run your first code on the ESP32. With ESP-IDF, you can develop powerful IoT applications and explore the many features of the ESP32.