Insight Into ESP32 Features & Using It With Arduino IDE

Few years back, ESP8266 took the embedded IoT world by storm. For less than $3, you could get a programmable, WiFi-enabled microcontroller being able to monitor and control things from anywhere in the world. Now Espressif (The semiconductor company behind the ESP8266) has released a perfect super-charged upgrade: the ESP32. Being successor to ESP8266; not only does it have a WiFi support, but it also features Bluetooth 4.0 (BLE/Bluetooth Smart) – perfect for just about any IoT project.

ESP-WROOM-32 Module

The development board equips the ESP-WROOM-32 module containing Tensilica Xtensa® Dual-Core 32-bit LX6 microprocessor. This processor is similar to the ESP8266 but has two CPU cores (can be individually controlled), operates at 80 to 240 MHz adjustable clock frequency and performs at up to 600 DMIPS (Dhrystone Million Instructions Per Second).

ESP-WROOM-32 Chip
  • Xtensa® Dual-Core 32-bit LX6
  • Upto 240MHz Clock Freq.
  • 520kB internal SRAM
  • 4MB external flash
  • 802.11b/g/n Wi-Fi transceiver
  • Bluetooth 4.2/BLE
ESP32 Hardware Specifications - ESP-WROOM-32 Chip

There’s also 448 KB of ROM, 520 KB of SRAM and 4MB of Flash memory (for program and data storage) just enough to cope with the large strings that make up web pages, JSON/XML data, and everything we throw at IoT devices nowadays.

The ESP32 Integrates 802.11b/g/n HT40 Wi-Fi transceiver, so it can not only connect to a WiFi network and interact with the Internet, but it can also set up a network of its own, allowing other devices to connect directly to it. The ESP32 supports WiFi Direct as well, which is a good option for peer-to-peer connection without the need of an access point. The WiFi Direct is easier to setup and the data transfer speeds are much better than Bluetooth.

The chip also has dual mode Bluetooth capabilities, meaning it supports both Bluetooth 4.0 (BLE/Bluetooth Smart) and Bluetooth Classic (BT), making it even more versatile.

Power Requirement

As the operating voltage range of ESP32 is 2.2V to 3.6V, the board comes with a LDO voltage regulator to keep the voltage steady at 3.3V. It can reliably supply up to 600mA, which should be more than enough when ESP32 pulls as much as 250mA during RF transmissions. The output of the regulator is also broken out to one of the sides of the board and labeled as 3V3. This pin can be used to supply power to external components.

Power Requirement
  • Operating Voltage: 2.2V to 3.6V
  • On-board 3.3V 600mA regulator
  • 5 µA during Sleep Mode
  • 250mA during RF transmissions
ESP32 Hardware Specifications - Power Supply

Power to the ESP32 development board is supplied via the on-board MicroB USB connector. Alternatively, if you have a regulated 5V voltage source, the VIN pin can be used to directly supply the ESP32 and its peripherals.

Also the sleep current of the ESP32 chip is less than 5 µA, making it suitable for battery powered and wearable electronics applications.

Warning:

The ESP32 requires a 3.3V power supply and 3.3V logic levels for communication. The GPIO pins are not 5V-tolerant! If you want to interface the board with 5V (or higher) components, you’ll need to do some level shifting.

Peripherals and I/O

Although the ESP32 has total 48 GPIO pins, only 25 of them are broken out to the pin headers on both sides of the development board. These pins can be assigned to all sorts of peripheral duties, including:

  • 15 ADC channels – 15 channels of 12-bit SAR ADC’s. The ADC range can be set, in firmware, to either 0-1V, 0-1.4V, 0-2V, or 0-4V
  • 2 UART interfaces – 2 UART interfaces. One is used to load code serially. They feature flow control, and support IrDA too!
  • 25 PWM outputs – 25 channels of PWM pins for dimming LEDs or controlling motors.
  • 2 DAC channels – 8-bit DACs to produce true analog voltages.
  • SPI, I2C & I2S interface – There are 3 SPI and 1 I2C interfaces to hook up all sorts of sensors and peripherals, plus two I2S interfaces if you want to add sound to your project.
  • 9 Touch Pads – 9 GPIOs feature capacitive touch sensing.
Multiplexed I/Os
  • 15 ADC channels
  • 2 UART interfaces
  • 25 PWM outputs
  • 2 DAC channels
  • SPI, I2C & I2S interface
  • 9 Touch Pads
ESP32 Hardware Specifications - Multiplexed GPIO pins

Thanks to the ESP32’s pin multiplexing feature (Multiple peripherals multiplexed on a single GPIO pin). Meaning a single GPIO pin can act as an ADC input/DAC output/Touch pad.

Input Only GPIOs

Pin D34, D35, VP and VN cannot be configured as outputs, but they can be used as either digital inputs, analog inputs, or for other unique purposes. Also note that they do not have internal pull-up or pull-down resistors, like the other GPIO pins.

Also GPIO pins VP and VN are an integral part of the ultra-low-noise pre-amplifier for the ADC, which help to configure the sampling time and noise of the pre-amp.

On-board Switches & LED Indicators

The ESP32 development board features two buttons. One marked as EN located on the top left corner is the Reset button, used of course to reset the ESP32 chip. The other Boot button on the bottom left corner is the download button used while downloading the new sketch/programs.

Switches & Indicators
  • EN – Reset the ESP32 chip
  • Boot – Download new programs
  • Red LED – Power Indicator
  • Blue LED – User Programmable
ESP32 Hardware Specifications - Reset Boot Buttons & LED Indicators

The board also has 2 LED indicators viz. Red LED & Blue LED. A Red LED indicates that the board is powered up and has 3.3V from the regulator. The Blue LED is user programmable and is connected to the D2 pin of the board.

Serial Communication

The board includes CP2102 USB-to-UART Bridge Controller from Silicon Labs, which converts USB signal to serial and allows your computer to program and communicate with the ESP32 chip.

Serial Communication
  • CP2102 USB-to-UART converter
  • 5 Mbps communication speed
  • IrDA support
ESP32 Hardware Specifications - USB to TTL Converter

If you have an older version of CP2102 driver installed on your PC, we recommend upgrading now.

ESP32 Development Board Pinout

The ESP32 development board has total 30 pins that interface it to the outside world. The connections are as follows:

ESP32 Development Board Pinout

For the sake of simplicity, we will make groups of pins with similar functionalities.

Power Pins There are two power pins viz. VIN pin & 3.3V pin. The VIN pin can be used to directly supply the ESP32 and its peripherals, if you have a regulated 5V voltage source. The 3.3V pin is the output of an on-board voltage regulator. This pin can be used to supply power to external components.

GND is a ground pin of ESP32 development board.

Arduino Pins are nothing but ESP32’s hardware I2C and SPI pins to hook up all sorts of sensors and peripherals in your project.

GPIO Pins ESP32 development board has 25 GPIO pins which can be assigned to various functions programmatically. Each digital enabled GPIO can be configured to internal pull-up or pull-down, or set to high impedance. When configured as an input, it can also be set to edge-trigger or level-trigger to generate CPU interrupts.

ADC Channels The board integrates 12-bit SAR ADCs and supports measurements on 15 channels (analog enabled pins). Some of these pins can be used to build a programmable gain amplifier which is used for the measurement of small analog signals. The ESP32 is also designed to measure the voltages while operating in the sleep mode.

DAC Channels The board features two 8-bit DAC channels to convert digital signals into true analog voltages. This dual DAC can drive other circuits.

Touch Pads The board offers 9 capacitive sensing GPIOs which detect capacitive variations introduced by the GPIO’s direct contact or close proximity with a finger or other objects.

UART Pins ESP32 development board has 2 UART interfaces, i.e. UART0 and UART2, which provide asynchronous communication (RS232 and RS485) and IrDA support, and communicate at up to 5 Mbps. UART provides hardware management of the CTS and RTS signals and software flow control (XON and XOFF) as well.

SPI Pins SPI Pins ESP32 features three SPIs (SPI, HSPI and VSPI) in slave and master modes. These SPIs also support the following general-purpose SPI features:

  • 4 timing modes of the SPI format transfer
  • Up to 80 MHz and the divided clocks of 80 MHz
  • Up to 64-Byte FIFO

All SPIs can also be used to connect to the external Flash/SRAM and LCD.

~ PWM Pins The board has 25 channels (Nearly All GPIO pins) of PWM pins controlled by Pulse Width Modulation (PWM) controller. The PWM output can be used for driving digital motors and LEDs. The controller consists of PWM timers and the PWM operator. Each timer provides timing in synchronous or independent form, and each PWM operator generates the waveform for one PWM channel.

EN Pin is used to enable ESP32. The chip is enabled when pulled HIGH. When pulled LOW the chip works at minimum power.

ESP32 Development Platforms

Now, let’s move on to the interesting stuff!

There are a variety of development platforms that can be equipped to program the ESP32. You can go with Espruino – JavaScript SDK and firmware closely emulating Node.js, or use Mongoose OS – An operating system for IoT devices (recommended platform by Espressif Systems and Google Cloud IoT) or use a software development kit (SDK) provided by Espressif or one of the platforms listed on WiKiPedia.

Fortunately, the amazing ESP32 community recently took the IDE selection a step further by creating an Arduino add-on. If you’re just getting started programming the ESP32, this is the environment we recommend beginning with, and the one we’ll document in this tutorial. Check out the ESP32 Arduino GitHub repository for more information.

Installing the ESP32 Core On – Windows OS

Espressif’s official ESP32 Arduino core is hosted here on GitHub. They don’t have an Arduino board manager install yet (Like we do while installing ESP8266 core on Arduino IDE). It should be available soon. Until then, we have to install it manually.

Let’s proceed with the installing ESP32 Arduino core.

The first thing is having latest Arduino IDE (Arduino 1.8.5 or higher) installed on your PC. If not, we recommend upgrading now.

Next, you need to download the contents of the esp32-arduino GitHub repository. You can visit GitHub and download it manually or simply click below download button.

Now go to your Arduino sketchbook directory. It’s by default Arduino directory in My Documents unless otherwise changed. You can verify it by opening Arduino IDE > File > Preferences > Sketchbook Location.

Arduino IDE Preferences
Sketchbook Directory Location Arduino IDE

Now considering your sketchbook directory is located in My Documents > Arduino, open the directory. You should see libraries directory inside it.

Arduino IDE Sketchbook Director In MyDocuments

Now create a new directory called hardware. Inside it create another directory called espressif. Inside it create another directory called esp32.

The directory structure should look like My Documents > Arduino > hardware > espressif > esp32

Installing ESP32 Core on Arduino IDE - Creating Folder Structure

Now extract the previously downloaded ESP32 core in esp32 directory.

Installing ESP32 Core on Arduino IDE - Extracting ESP32 Core

Once you are done, verify that “boards.txt”, “platform.txt”, and the cores, doc, tools, etc. folders are there inside esp32 directory.

In order to compile code for the ESP32, you need the Xtensa GNU compiler collection (GCC) installed on your machine. Go to esp32 > tools folder and execute get.exe

Installing ESP32 Core on Arduino IDE - Executing get.exe

This executable will download the Xtensa GNU tools and the ESP32 software development kit (SDK), and unzip them to the proper location.

Installing ESP32 Core on Arduino IDE - Downloading Xtensa GNU tools and ESP32 SDK

You should see a few new folders in the “tools” directory, including “sdk” and “xtensa-esp32-elf” once it’s done.

Installing ESP32 Core on Arduino IDE - Verifying Installation

Installing the ESP32 Core On – Mac OS

Espressif’s official ESP32 Arduino core is hosted here on GitHub. They don’t have an Arduino board manager install yet (Like we do while installing ESP8266 core on Arduino IDE). It should be available soon. Until then, we have to install it manually.

Let’s proceed with the installing ESP32 Arduino core.

The first thing is having latest Arduino IDE (Arduino 1.8.5 or higher) installed on your PC. If not, we recommend upgrading now.

Next, Open your Terminal and execute the following commands.

curl -o get-pip.py https://bootstrap.pypa.io/get-pip.py && \
sudo python get-pip.py && \
sudo pip install pyserial
mkdir -p ~/Documents/Arduino/hardware/espressif && \
cd ~/Documents/Arduino/hardware/espressif && \
git clone https://github.com/espressif/arduino-esp32.git esp32 && \
cd esp32 && \
git submodule update --init --recursive && \
cd tools && \
python get.py

Here ~/Documents/Arduino represents your sketch book location as per Arduino IDE > File> Preferences > Sketchbook location. Adjust the command above accordingly if necessary!

If you get the below error, Install the command line dev tools and try above commands again:

Invalid Active Developer Path
xcode-select --install

Installing the ESP32 Core On – Debian/Ubuntu Linux OS

Espressif’s official ESP32 Arduino core is hosted here on GitHub. They don’t have an Arduino board manager install yet (Like we do while installing ESP8266 core on Arduino IDE). It should be available soon. Until then, we have to install it manually.

Let’s proceed with the installing ESP32 Arduino core.

The first thing is having latest Arduino IDE (Arduino 1.8.5 or higher) installed on your PC. If not, we recommend upgrading now.

Next, Open your Terminal and execute the following commands

sudo usermod -a -G dialout $USER && \
sudo apt-get install git && \
wget https://bootstrap.pypa.io/get-pip.py && \
sudo python get-pip.py && \
sudo pip install pyserial && \
mkdir -p ~/Arduino/hardware/espressif && \
cd ~/Arduino/hardware/espressif && \
git clone https://github.com/espressif/arduino-esp32.git esp32 && \
cd esp32 && \
git submodule update --init --recursive && \
cd tools && \
python2 get.py

If you have Arduino.app installed to /Applications/, modify the installation as follows, beginning at mkdir -p ~/Arduino…:

cd /Applications/Arduino_*/Contents/java/hardware/
mkdir -p espressif && \
cd espressif && \
git clone https://github.com/espressif/arduino-esp32.git esp32 && \
cd esp32 && \
git submodule update --init --recursive && \
cd tools && \
python2 get.py```

To make sure ESP32 Arduino core and the ESP32 development board are properly set up, we’ll upload the simplest sketch of all – The Blink!

We will use the on-board LED for this test. As mentioned earlier in this tutorial, D2 pin of the board is connected to on-board Blue LED & is user programmable. Perfect!

Before we get to uploading sketch & playing with LED, we need to make sure that the board is selected properly in Arduino IDE. Open Arduino IDE and select ESP32 Dev Module option under your Arduino IDE > Tools > Board menu.

Selecting ESP32 Dev Module in Arduino IDE

Now, plug your ESP32 development board into your computer via micro-B USB cable. Once the board is plugged in, it should be assigned a unique COM port. On Windows machines, this will be something like COM#, and on Mac/Linux computers it will come in the form of /dev/tty.usbserial-XXXXXX. Select this serial port under the Arduino IDE > Tools > Port menu.

Also the upload speed is selected to 921600 by default. Try lowering it to Upload Speed : 115200 as many users complained about getting espcomm_sync failed error when trying to upload the sketch at 921600 speed.

Selecting COM port in Arduino IDE

Once you are done, try the example sketch below.

int ledPin = 2;
void setup()
{
	pinMode(ledPin, OUTPUT);
}
void loop()
{
	digitalWrite(ledPin, HIGH);
	delay(500);
	digitalWrite(ledPin, LOW);
	delay(500);
}

Once the code is uploaded, LED will start blinking. You may need to tap the EN button to get your ESP32 to begin running the sketch.

ESP32 Development Board Blink Sketch Working Arduino IDE

Troubleshooting – Booting up ESP32

Especially when try to upload a new sketch to your ESP32 in the Arduino IDE, it may fail to connect to your board saying ‘A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header’.

Failed to connect to ESP32 Error while Uploading Sketch in Arduino IDE

This is a common problem and it means that your ESP32 is not in flashing/uploading mode. You can follow below steps to fix this problem.

  • Make sure that you have selected proper COM port, upload speed to 115200 or lower and board as ESP32 Dev Module.
  • Hold-down the BOOT button in your ESP32 board.
  • Press the Upload button in the Arduino IDE to upload a new sketch.
  • When you see the Writing at 0x00001000… (100 %) message after Connecting…. message in your Arduino IDE log, release the finger from the BOOT button.
  • After that, you should see the Done uploading

In short, you need to press and hold the BOOT button before hitting the Upload button and keep it pressed until Arduino IDE starts writing to ESP32.

That’s it. Your ESP32 should have the new sketch running. After uploading a new sketch, press the ENABLE button to restart the ESP32 and run the new uploaded sketch.

Remember! You’ll also have to repeat that button sequence every time you want to upload a new sketch.

To be honest we’re not sure why that happens with the newer boards. We don’t have any ESP32 board with that behavior. We think there might be something different with your specific board or the Arduino IDE fails to send the right command sequence to put the ESP32 automatically in flashing/uploading mode.