ESP32 (with Arduino)

ESP32 microcontroller

ESP32 is a series of cheap microcontrollers with itegrated WI-Fi and Bluetooth. They run either 160MHZ or 240MHZ and therefore much more capable that the standard Arduino Uno v3.

There are many different actual physical formfactor boards with the chip embedded. It can be quite overwhleming to choose which one to use. In general they all work and what is most confusing is the pin mapping.


Technical differences between Arduino Uno and ESP32

  • The esp32 has two cores and can run concurrent code.

  • The esp32 has multiple pins that can detect capacitance.

  • It has Wi-Fi and Bluetooth.

  • It runs much faster. 16MHZ vs. 160MHz

  • Some of the analog pins only work when wifi is not used.

The ESP32 Mini form factor

This formfactor version of ESP32 is called Wemos D1 ESP32 or MH ET LIVE ESP32DevKIT or ESP32 Mini kit.

One version of the ESP32 board matches the Wemos D1 Mini footprint. This version works with some of the small wemos shields.

The small formfactor and the avaliability of shields makes it a good starting point and we will use this version for the toturials here.

Getting started

For ESP32 to run as an Arduino board we need to install the board definition in the Arduino IDE and we need to install USB serial drivers.

1.

Install USB Serial driver

To be able to communicate with the Wemos board you will need to install the Serial drivers. On the following link you can find the latest driver:

https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers

Restart you computer

2.

Install Arduino

Download Arduino ide from here wwww.arduino.cc -> Download -> Arduino IDE (not Online version).

3.

Add the board in settings

Start Arduino and open Preferences window (Arduino or Files -> Preferences).

Enter the following line into Additional Board Manager URLs field:

https://dl.espressif.com/dl/package_esp32_index.json

4.

Install ESP32 Board specifications

Open Boards Manager from Tools > Board menu and install ESP32 platform.

Select your ESP32 board from Tools > Board menu after installation

5.

Choose the board

Open Boards Manager from Tools > Board menu and install ESP32 platform.

Select your ESP32 board from Tools > Board menu after installation

"MH ET LIVE ESP32DevKIT"


6.

Choose the the right port

For Mac OSX / LINUX: It will usually be alled something lik USBUart (see image).

For Windows: I will usually be the largest port number.

In both case the simplest way to find the right port is to unplug the board. Se which ports that are avaliable. Then plun-in the board and choose the port that showed up.

If not port show up then try to restart your computer. Look in your devicemanger to see if the driver has been installed and look online for a more recent or alternative driver.

While you are at it, you can also change the upload speed to "921600". It will make the upload significantly quicker.

7.

Verify that everything is setup properly

When you have gone through the different steps then your Board configuration should look like this:

  • The correct Board

  • The upload speed can be set to 921600

  • The correct port

8.

Upload test code

Copy the code below into the editor

void setup() {

Serial.begin(9600);

}


void loop() {

Serial.println(millis());

delay(1000);

}

Press the right pointing arrow button in the icon menu.

If everything works the status bar below should say "Done Uploading" as seen on the image.

9.

Show the serial monitor

  1. Press the magnifying glass icon on the rop right corner.

  2. Choose the 9600 Baud in the bottom right corner of the serial prompt.

  3. If everything is right you should see a number incriment with about 1000 every second.


10.

Show the serial plotter

  1. Close the serial monitor. You cannot open the serial plotter while the serial monitor is open.

  2. Open the tools menu and choose serial plotter.

  3. Choose 9600 Baud rate in the bottom right corner of the serial plotter window.

  4. If everything is right you should see a graph of the same numbers incrimenting every second.


11.

Understanding the pin naming convention

The board has two rows of pins on each side. E.g. pin IO25 would be the third pinholde from the top on the the outer row on the right side. The pins with a IO + number can be used as either an input or an output. To read a digital input (e.g. a button) from pin IO25 you would write something like:

void setup() {

Serial.begin(9600);

pinMode(25, INPUT_PULLUP);

}


void loop() {

boolean value = digitalRead(25);

Serial.println(value);

delay(1000);

}

Below is the diagram of a button connected to IO25 and ground.

Congratulations

You now have ESP32 running as an Arduino board and you can now use the board in the same ways as you would with a normal Arduino board. As you dig into the details you find that there integrate differences (see below).

Have a look in the files->Examples menu in the ESP32 section. It is filled with eamples of what you can do with the board.

Also, have a look in the Arduino section of the website for how to use input and output.

Also, have look that smart light toturial get started with working with wi-fi and browser based control.

The pin maping of the ESP32 Mini

This is a relatively technical diagram. You will not need this in the beginning but at a later state this will help you to look up the different pins and what they can do. The green boxes indicate the the pin can be used to read analog signals (0v to 3.3v). The pink boxes indicates that the pin can be used as touch sensor.