guia-de-programacion-del-esp32-en-entorno-arduino

ESP32 programming guide in Arduino environment

  • 5 min

In this article, we will see how to program an *ESP32 with the Arduino environment, and the differences between programming an ESP32 and an Arduino.

Espressif has made a very significant effort in porting the ESP32 Core to Arduino to make it very similar to programming a conventional Arduino.

However, the ESP32 has many more options and possibilities than a traditional Arduino. So some things are somewhat different.

Time Functions

Millis and Delay

The time functions millis() and micros() work the same as in Arduino.

delay() and delayMicroseconds() also work. However, delay is non-blocking, while delayMicroseconds is blocking.

Yielding

Just as with the ESP8266, Yielding is one of the most important characteristics and one that causes the most errors and reboots.

The ESP32 needs to perform WiFi connection management and TCP/IP stack tasks. If it doesn’t attend to them, it will likely reboot.

For everything to work, we need to let the ESP32 “breathe”. For that, we need to call the yield function, which allows the ESP32 to attend to its own tasks.

Fortunately, the yield function is executed in every delay and at the end of the loop. However, the delayMicroseconds() function does not call yield().

Therefore, it basically translates to you not being able to do long blocking processes (>100ms) or your ESP32 will reboot.

Connections and Hardware

Communication

Serial Port

Using the serial port on the ESP32 is very similar to its use in Arduino and employs all the functions we are accustomed to for sending and receiving data (read, write, print, println…)

But on the ESP32 we have several UARTs available, and additional functions.

I2C Bus

Using I2C on the ESP32 is similar to Arduino and uses the same functions. But on the ESP32 we have several I2Cs available, and additional functions.

SPI Bus

Again, the SPI on the ESP32 its use is similar and employs the same functions as in a conventional Arduino. But on the ESP32 we have several SPIs available, and additional functions.

WiFi Communication

Like the ESP8266, WiFi capability is one of the most important points of the ESP32. Therefore, we will cover it intensively in the rest of the tutorials in the series.

Arduino Libraries

The final question: will my Arduino library work on the ESP32? Well, just as with the ESP8266, in general it will not work for you.

If you use a library, it will have to be one compatible with your ESP32. Moreover, with your specific model of ESP32, because an ESP32-S2 is not the same as an ESP32-S3.