The objective of this post is to explain how to do a simple “Hello World” program with the ESP32, using the Arduino IDE as development environment.
Introduction
The objective of this post is to explain how to do a simple “Hello World” program with the ESP32. This will be a very simple introduction, so this tutorial will just consist on printing the message to the serial console and read it with the Arduino IDE.
If you prefer, you can check the video version of this tutorial in my Youtube channel:
At the time of writing, I didn’t find a way to install the libraries for the Arduino IDE using the Boards manager, as we previously did for the ESP8266 (see the post here). Nevertheless, it’s probably a matter of time until it is supported.
For now, there is a very well explained tutorial on how to install the ESP32 Arduino support on Windows, on Espressif’s github page. Please check here for the mentioned tutorial. Also, note that there are other operating systems supported, as can be seen here.
Please note that in the previously mentioned tutorial, the directory where to clone the git repository may be different from yours. In my case, for example, the Arduino installation was in C/Programs(x86)/Arduino. Also, the hardware directory already existed, so only the /espressif/esp32 folders were automatically created by Git.
Other important thing is that you may need to run both Git GUI and the get.exe file as administrator, in order for the correct folders to be created. In both cases, you just need to right click the executable file and select “Execute as administrator“. It should work fine.
The code
The code for this tutorial is really simple, specially if you have previous experience with Arduino or the ESP8266.
So, in the Setup function, we start by opening a serial connection, with a baud rate of 115200. To do so, we just call the begin method of the Serial object and pass as input the mentioned baud rate.
Next, on the loop function, we just call the println method, to print the “Hello World” message with a new line at the end. After that, we do a short delay of 2 seconds (2000 milliseconds), using the delay function.
void setup() { Serial.begin(115200); } void loop() { Serial.println("Hello World"); delay(2000); }
Running the code
Since we are still in the early stages of the ESP32 product life, most of the vendors still call the boards as “ESP32 development board” or something similar. In my case, I’m using one of those generic boards sold at eBay. So, I’ve selected the “ESP32 Dev Module” in the Arduino IDE, as can be seen in figure 1.
Figure 1 – ESP32 currently available boards for the Arduino IDE.
Nevertheless, the code compiles and uploads just fine. As can be seen in figure 2, we get the correct “Hello World” output at the serial console. Don’t forget to use the correct baud rate defined in the code, as highlighted in the figure.
Figure 2 – Output of the “Hello World” program.
Hi, may I know if you are using MacOS? I’m not able to connect to my ESP32 development board using MacOS, but is able to do it using Windows. Do you have any suggestion? Thanks.
Hi! I’m also using Windows (version 8). Unfortunately I never tried it on Mac or Linux. But they have a different set of instructions on Mac:
https://github.com/espressif/arduino-esp32#instructions-for-mac
Have you tried them yet? If you already did, my recommendation is that you look in the issues on git for something similar to your problem and if you don’t find, open a new issue.
If you can solve it please let us know, so others that find this post are able to solve it 🙂
Best regards,
Nuno Santos
Yes, I’ve followed the instructions to install.
I do not seem to be able to detect the esp32 with the USB interface.
Will update here if I find a solution.
Thanks.
You will need the UART driver to talk to the ESP. The interface should look like /dev/cu.SLAB_USBtoUART after install.
The driver can be found at:
https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers
Hi, may I know if you are using MacOS? I’m not able to connect to my ESP32 development board using MacOS, but is able to do it using Windows. Do you have any suggestion? Thanks.
Hi! I’m also using Windows (version 8). Unfortunately I never tried it on Mac or Linux. But they have a different set of instructions on Mac:
https://github.com/espressif/arduino-esp32#instructions-for-mac
Have you tried them yet? If you already did, my recommendation is that you look in the issues on git for something similar to your problem and if you don’t find, open a new issue.
If you can solve it please let us know, so others that find this post are able to solve it 🙂
Best regards,
Nuno Santos
Yes, I’ve followed the instructions to install.
I do not seem to be able to detect the esp32 with the USB interface.
Will update here if I find a solution.
Thanks.
You will need the UART driver to talk to the ESP. The interface should look like /dev/cu.SLAB_USBtoUART after install.
The driver can be found at:
https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers