In this entry, we will see how to set up the standard Arduino IDE to program the ESP32 and the boards based on this popular SoC.
The process is quite simple, thanks to the work that Espressif has done to create a Core compatible with the Arduino environment.
All the code is Open Source and is available in the project repo at GitHub - espressif/arduino-esp32: Arduino core for the ESP32
The process is only valid for the ESP32. If you are looking for the same tutorial for the ESP8266, you can find it in this entry Cómo programar ESP8266 con el IDE de Arduino
I assume you have the Arduino IDE installed and updated to the latest version. If not, logically, go to the official Arduino page and install it on your computer.
Install ESP32 in Arduino IDE
The ESP32 is not included in the Arduino IDE by default, but we can easily add it using the “Board Manager”.
Open the Arduino IDE and go to File > Preferences. In the “Additional board URLs” field, add the following URL:
https://espressif.github.io/arduino-esp32/package_esp32_index.json
If you want the development branch, instead add this URL.
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
Then, go to Tools > Board > Board Manager.
In the panel that appears, we search for “ESP32” in the search bar, and click “Install” on the package that appears.
Once the installation is complete, you will be able to select the ESP32 models from the dropdown, and you will be ready to program the ESP32.
Testing the ESP32 in Arduino IDE
Let’s test that everything works correctly. Connect the ESP32 to your computer using a USB cable.
In the Arduino IDE, select the board that you are using. Go to Tools > Board and select “ESP32 Dev Module” as the board you are using.
Then select the port COM to which the ESP32 is connected in Tools > Port
If you are not sure which port it is, you can disconnect the ESP32 and return to this section to see which port disappears and reappears when you connect the device.
Hello World on the ESP32
Now that you have your development environment set up, let’s test it with a simple ‘Blink’, where we will make the built-in LED on the ESP32 blink every second.
Copy this code into the Arduino IDE
void setup()
{
pinMode(LED_BUILTIN, OUTPUT); // Set the built-in LED pin as output
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH); // Turn on the LED
delay(1000); // Wait for one second
digitalWrite(LED_BUILTIN, LOW); // Turn off the LED
delay(1000); // Wait for one second
}
Press Verify to ensure there are no syntax errors. If everything is fine, press the Upload button to upload the program to the ESP32.
After a few seconds, you should see the built-in LED blinking at one-second intervals.
As we can see, programming an ESP32 with the Arduino environment is very straightforward, thanks to the work done by Espressif to create a compatible Core.
In the following tutorials, we will see how to use the different features of the ESP32 and its differences from a “normal” Arduino.