Why ESP-IDF and What Is It?
ESP-IDF is the official programming development framework for ESP-based microcontrollers. You can kind of think of it as the next step up from the Arduino IDE, giving you more options for customization, organization, and control. It is also very similar in style to other industry frameworks such as STM32CubeIDE, utilizing Real-TimeOS (FreeRTOS) instead of the familiar Arduino super-loop. This is also great since it will teach you a lot about how many commercial technologies are programmed and provide you with the knowledge to switch around and use other microcontrollers later that aren’t supported by Arduino IDE. Being written in C, you also get access to lots of official libraries provided by the IC manufacturers themselves rather than 3rd party programmers.
All these awesome perks said, ESP-IDF is also more complicated than Arduino and can be frustrating to get started with and understand. With more options for customizability comes more things to potentially mess up, making it not very beginner-friendly. If you’ve never programmed in Arduino (or similar) this post is probably not for you, but definitely come back once you feel more comfortable! With this, let’s go through the ESP-IDF standard setup with Espressif-IDE.
If you’d prefer to install ESP-IDF through an existing IDE such as Eclipse or VSCode, you will have to refer to the setup instructions from Espressif’s website. I will only be explaining the setup with the official Espressif-IDE (which I personally think is way easier and more stable). Let’s get started!
First, you will want to navigate to the ESP-IDF installer which is linked here. After that, click on the option with ESP-IDF v5 and Espressif-IDE (or whatever the newest version is if you’re reading this at a later time). The download should start.
Note: At the time of writing this, the Online Installer has an issue where many of the ESP32 boards are not selectable as targets after installation. Not to worry though, since the offline installation is just as good and doesn’t have this problem.
After selecting your language and agreeing to the terms, let the system checker run and click apply fixes if any are recommended. After progressing through, you’ll want to make sure the Espressif-IDE is selected along with all the different ESP-based chips.
After finishing the installation, there should be a nice Espressif-IDE icon on your desktop. If not, you can search for it in Windows.
When you open it, you'll have the option to select a workspace to store your programs. I’d recommend creating a folder in OneDrive or somewhere similar where you can easily access them.
Once that’s done, welcome yourself to Espressif-IDE!
Having a problem with the installation? You can also check out Espressif’s instructions to cross-check. If something is still going wrong, feel free to leave a comment and I’ll do my best to help!
Creating Your First Program
With the installation complete, let’s go over creating an example program and flashing your first board.
To begin, close out of the welcome menu and go to File > New > Espressif IDF Project.
When that’s done, you’ll have the opportunity to name your project and select the save location/target. (The target is the board you’re going to upload the program to.) I chose the ESP32-S3 since I had a spare one lying around.
With that, you have a basic project created! You can navigate to the main.c
file within the project to see the starter code.
To test the workspace, I went and added a simple blink program to turn an LED on and off on pin 4.
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
#define BLINK_GPIO 4 // Or whichever pin
void app_main(void)
{
// Configure the GPIO pin for the LED
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
while(1) {
// Turn the LED on
gpio_set_level(BLINK_GPIO, 1);
// Wait for 1 second
vTaskDelay(pdMS_TO_TICKS(500));
// Turn the LED off
gpio_set_level(BLINK_GPIO, 0);
// Wait for 1 second
vTaskDelay(pdMS_TO_TICKS(500));
}
}
Next, you can build the program by selecting the “build” button in the top left. This will compile the program settings such as the MakeList and target. It may take a few minutes to complete but don’t worry, you won’t have to do it every time! Just whenever you mess with settings.
After that, it’s time to select the upload port. This can be done by hitting the gear next to the target and then choosing the port.
Then, you can upload the program with the green button next to the build button.
NOTE: Before uploading any code, you must put the board into bootloader mode. You can do this by holding the boot button > clicking the reset button (RST) > and then releasing the boot button.
And voila! You’ve successfully built and uploaded your first ESP-IDF program!
That’s Great, But Now What?
This is a great start but obviously, the Blink program isn’t outlining ESP-IDF’s potential very well. It seems no more complex than a standard Arduino program! Well, if you’re thinking this then you’d be right. In addition to its customizability, the power of ESP-IDF mainly comes through its ability to utilize multiple “tasks” which you can think of as multiple Arduino super-loops running simultaneously, each doing different things. Needless to say, this program did not cover that. However, I can refer you to some great resources to learn more about ESP-IDF and FreeRTOS (the operating system that ESP-IDF uses).
This is the holy manual of FreeRTOS, the Real Time Kernel. This extensive document covers the workings of FreeRTOS (and therefore ESP-IDF) so you can understand how it works and get to know the FreeRTOS functions/features. I highly recommend reading it whenever you can!
If that’s not enough or too much, there are also plenty of online resources to explore. For example, this is a nice course by learnesp32.com which I enrolled in when first learning ESP-IDF. It covers a lot from basic sketches to FreeRTOS functions, setting up libraries, and more. If you have some spare change lying around, I’d definitely recommend it!
I hope this helped get you started with ESP-IDF! If you have any questions or if there was an issue with the installation, feel free to leave a comment letting me know the issue and I’ll see what I can do. Thanks for reading!
Be sure to follow me on Instagram! :)