ESP32 – Cheapest IoT WiFi and Bluetooth ready module

Introduction

While ESP8266 is still one of the most used WiFi development board in handmade IoT projects, the new ESP32 is getting allot attention. Although its not so new, the ESP32 popularity has began to grow in the last year mostly because of its Bluetooth capabilities, but not only. The ESP32 comes now with almost 32 I/O pins and a powerful 32bits dual core CPU ready to process more complex jobs. Despite those new features, the ESP32 development board can still be bought with under 15$, but does it worth it?

Getting started with ESP32, available board models, datasheet information and programing tutorial

ESP32 technical specifications

Same as ESP8266 and older ESP modules, ESP32 can be found in various models with different hardware features. You can see below main specs for the most common versions:

Processors:

Main: Tensilica Xtensa 32-bit LX6 microprocessor

Cores: 2 or 1 (depending on variation) – All chips in the ESP32 series are dual-core except for ESP32-S0WD, which is single-core.

RTC fast SRAM: 8 KiB – For data storage and main CPU during RTC Boot from the deep-sleep mode.

eFuse: 1 Kibit – Of which 256 bits are used for the system (MAC address and chip configuration) and the remaining 768 bits are reserved for customer applications, including Flash-Encryption and Chip-ID.

External flash & SRAM: ESP32 without embedded flash supports up to 4 × 16 MiB of external QSPI flash and 8 MiB SRAM with hardware encryption based on AES to protect developer’s programs and data. ESP32 chips with embedded flash do not support the address mapping between external flash and peripherals.

ESP32 available modules and development boards

Over the internet ESP32 can be found either as a standalone module, ready fol soldering, or as a full-featured development board. The standalone version has pretty much the same design as the ESP8266-12 series have. The difference between them is the ESP32 has way more pins, and it can be difficult to solder them if you don’t have professional tools. See below some pics with the standalone ESP32 module:

ESP32 Standalone module

ESP32 development board by Sparkfun

As you have used so far, there is nothing that SparkFun doesn’t do. They also sell a nice red ESP32 development board. Despite there are still allot of features under development, their version seems to be very stable, and also offers a LiPo power input. You can see all details in the images below:

Sparkfun ESP32 Development board

Sparkfun ESP32 Development board pinout

ESP32 development board by Adafruit

On the other side, Adafruit does a better job with the WROOM-32 chip, at least when talking about design. Their version look more classic, feels much solid, and has a similar design with the well known ESP8266 NodeMCU Lua boards. Images talk below:

Adafruit ESP32 Development board

Adafruit ESP32 Development Board WROOM32

Other ESP32 development boards

Nevertheless the direct competitors are, off-course, the cheapest too, the Chinese clones. The same way as with the Arduino UNO, clones or genuine, all have the same esp32 chip, manufactured by Espressif Systems. So the difference is only in the quality of the electronic components and the soldering precision. After a quick research on the internet, the most common clones seems to be made after the genuine Adafruit ESP32.

Interesting similarities with the Adafruit model no? You could easily confuse them, but at a closer look, the Adafruit has some protection components, and a different layout. Both have CP2102 as a USB bridge, a microusb port, but different voltage regulators. Also they feature two push buttons, one for reset function, and one for changing the boot modes. You can also find a red version which has the CH340 USB-UART Bridge, for those who have issues with CP2102 drivers.

WEMOS also manufacture a board which they call LOLIN32 (BUY Now from Amazon and save money) and integrates the ESP32 chip. It looks slim but solid, and some people found a version which claim to have incorporated battery slot like in the image below:

WeMos ESP32 Development Board

ESP32 Development boards with OLED display embedded are also very common over the internet. This boards are very appreciated by the students because they can be easily transformed into data-loggers or WiFi Access points stations, with live data display. Be aware that power consumption is higher on this devices. You can see bellow few of this models:

ESP32 Pin Layout and Electrical characteristics

IMPORTANT! Before reading any technical information, you should first know that ESP32 chip is manufactured in different versions. As you can see below, there are 4 different ordering codes:

Ordering code

Core

Embedded flash

Connection

Package

ESP32-D0WDQ6

Dual core

No embedded flash

Wi-Fi b/g/n + BT/BLE Dual Mode

QFN 6*6

ESP32-D0WD

Dual core

No embedded flash

Wi-Fi b/g/n + BT/BLE Dual Mode

QFN 5*5

ESP32-D2WD

Dual core

16-Mbit embedded flash

Wi-Fi b/g/n + BT/BLE Dual Mode

QFN 5*5

ESP32-S0WD

Single core

No embedded flash

Wi-Fi b/g/n + BT/BLE Dual Mode

QFN 5*5

The ESP32 chip has 48 pins, each block side having 12 symmetrical aligned. The block base is actually the GND contact, reason for which you will find that most datasheets claim 49 pins. Pin layout can have slight variation between chip versions. Below image is extracted from Espressif datasheet and represents the QFN 6*6 code version:

ESP32 Chip pinout layout

ESP32 power consumption

The power consumption of the ESP32 module varies very much depending on the running power mode. Same as his predecessors, ESP32 has multiple power modes, which may help you saving power when you don’t need all resources. You can see in the table below all power modes and resources availability:

Power mode

Active

Modem-sleep

Light-sleep

Deep-sleep

Hibernation

CPU

ON

ON

PAUSE

OFF

OFF

Wi-Fi/BT baseband and radio

ON

OFF

OFF

OFF

OFF

RTC memory and RTC peripherals

ON

ON

ON

ON

OFF

ULP-coprocessor

ON

ON

ON

ON/OFF

OFF

Now that we saw the available esp32 power-modes, let’s see what the producer officially declares regarding the power consumption:

ESP32 Power consumption by Power mode

ESP32 power consumption during Active power mode, with RF working:

ESP32 Power consumption in active mode

The ESP32 electrical absolute maximum ratings are very similar with ESP8266 and other devices which incorporates a 2,4 Ghz RF chip. Because this radio chips are working with a low range voltage, powering the entire module with a 5V supply is not yet possible without a third party voltage regulator. In the image below you can see the exact numbers for which the ESP32 operates properly:

ESP32 Maximum absolute ratings

ESP32 Bluetooth capabilities

One of the most interesting feature of esp32 which, in theory, should make it the absolute IoT module, is the Bluetooth. ESP32 integrates a Bluetooth link controller and Bluetooth baseband, which carry out the baseband protocols and other low-level link routines, such as modulation/demodulation, packets processing, bit stream processing, frequency hopping, etc. The Bluetooth stack of ESP32 is compliant with Bluetooth v4.2 BR / EDR and BLE specification.

ESP32 Bluetooth provides the following interfaces: UART HCI interface, up to 4 Mbps, SDIO / SPI HCI, I2C interface for the host to do configuration, PCM / I2S audio. Most of the classic Bluetooth functions like device discovery, multi-connections, scan, asynchronous data sending and transmission, broadcast encryption, sniff mode, ping are covered. Besides the classical functions, ESP32 also features BLE (Bluetooth Low Energy), a new function which can accomplish radio transmissions while consuming less power than regular bluetooth.

ESP32 WiFi capabilities

Espressif say that with the ESP32, the WiFi controller should have a better power consumption and up to 150 Mbps o data rate. Like in the predecessors, multiple infrastructure modes like BSS Station mode / P2P mode / SoftAP mode, are supported. The ESP32 Wi-Fi Radio and Baseband support the following features:

802.11b and 802.11g data rates

802.11n MCS0-7 in both 20 MHz and 40 MHz bandwidth

802.11n MCS32

802.11n 0.4 us guard-interval

up to 150 Mbps of data rate

Receiving STBC 2×1

Up to 20.5 dBm of transmitting power

Adjustable transmitting power

Antenna diversity and selection (software-managed hardware)

Because ESP32 incorporates both WiFi and Bluetooth protocols, it has configurable Packet Traffic Arbitration (PTA) that provides flexible and exact timing Bluetooth co-existence support. It is a combination of both Frequency Division Multiplexing (FDM) and Time Division Multiplexing (TDM), which coordinates the protocol stacks.

ESP32 integrated sensors

Although many people already have one of this module, most probably not many know that beside WiFi and Bluetooth, ESP32 also features a series of extra sensor which can add a great value to any project. Let’s see what is about:

Hall Sensor – ESP32 integrates a Hall sensor based on an N-carrier resistor. When the chip is in the magnetic field, the Hall sensor develops a small voltage laterally on the resistor, which can be directly measured by the ADC, or amplified by the ultra-low-noise analog pre-amplifier and then measured by the ADC.

Temperature Sensor – the temperature sensor generates a voltage that varies with temperature. The voltage is internally converted via an analog-to-digital converter into a digital code. The temperature sensor has a range of -40°C to 125°C. The offset of the temperature sensor varies from chip to chip, due to process variations or the heat generated by the Wi-Fi circuitry itself (which affects measurements). Therefore, the internal temperature sensor is only suitable for applications that detect changes in temperature, rather than absolute temperatures, and for calibration purposes as well. However, if the user calibrates the temperature sensor and uses the device for an application that uses minimal power, the results could be accurate enough.

Touch Sensor -ESP32 has 10 capacitive-sensing GPIOs, which detect variations induced by touching or approaching the GPIOs with a finger or other objects. The low-noise nature of the design and high sensitivity of the circuit allow relatively small pads to be used. Arrays of pads can also be used, so that a larger area or more points can be detected.

Pulse counter – the pulse counter captures pulse and counts pulse edges through seven modes. It has eight channels, each of whom captures four signals at a time. The four input signals include two pulse signals and two control signals. When the counter reaches a defined threshold, an interrupt is generated.

LED PWM – the LED PWM controller can generate 16 independent channels of digital waveforms with configurable periods and duties. The 16 channels of digital waveforms operate at 80 MHz APB clock, eight of which have the option of using the 8 MHz oscillator clock. Each channel can select a 20-bit timer with configurable counting range, while its accuracy of duty can be up to 16 bits within a 1 ms period. The software can change the duty immediately. Moreover, each channel supports step-by-step duty increasing or decreasing automatically, which makes it useful for the LED RGB color-gradient generator.

For the complete list with peripherals and sensors and their PIN assignment and availability consult the official ESP32 datasheet.

ESP32 Programing Guide

This is probably the most important chapter because comparing with the old ESP8266, the ESP32 comes with considerable changes. ESP8266 is so popular because all features that he offers can be exploited trough the Arduino code or directly with AT commands. With the new ESP32 the world of Arduino, LUA or AT has probably got to an end.

While some functionalities can still be exploited using Arduino IDE or AT commands, in order to take advantage of the full ESP32 capabilities Espressif

systems has developed a more complex firmware called ESP-IDF. The software development framework by Espressif is intended for rapidly developing Internet-of-Things (IoT) applications, with Wi-Fi, Bluetooth, power management and several other system features.

This directive rise the ESP32 to another level, making it less accessible to regular users which do not have advanced programming skills. ESP8266 got so popular because it was really easy to use. You didn’t had to be a software developer in order to use the Arduino IDE or write the Arduino “pseudo-code”. This new way of dealing with the ESP32 imply working with a complex deployment pipeline in order to flash projects and also writing C code in a dedicated IDE.

If you are interested to learn quickly the C language I recommend the following best sellers materials:

Having environment set up, you are ready to start the most interesting part – the application development. This process may be summarized in four steps:

Configuration of a Project and writing the code

Compilation of the Project and linking it to build an Application

Flashing (uploading) of the Application to ESP32

Monitoring / debugging of the Application

Setting up the Toolchain framework

If you already are an experienced C developer, setting up the environment will be more natural, but for regular user I advise you to be patient and follow every steps of the guide.

First thing first. In order to setup the Toolchain, you need to download it from the dl.espressif.com. For Windows user you can get it from here. Unzip the archive content in C:\ and then run C:\msys32\mingw32.exe. On C:\ create a folder and name it C:\esp.

In the mingw32 terminal, change the directory to the new esp folder created and download the ESP-IDF by cloning it from git.

After cloning process has finished, ESP-IDF will be downloaded into C:/esp/esp-idf. In order to update all modules you need to run the following command:

cd c:/esp/esp-idf
git submodule update --init

Setting up the ESP-IDF environment path

Next step is to setup a OS path environment variable for ESP-IDF. The toolchain programs access ESP-IDF using IDF_PATH environment variable. This variable should be set up on your PC, otherwise projects will not build. Setting may be done manually, each time PC is restarted. Another option is to set up it permanently by defining IDF_PATH in user profile. To do so you need to run in to the terminal the following command:

exportIDF_PATH="C:/esp/esp-idf"

If you want to skip this process every time when you start mingw terminal, you can create a .sh script in the C:/msys32/etc/profile.d/ directory and name it export_idf_path.sh. Put the above command in it, and then open a new terminal window. Then ESP-IDF should now be available. You can test it by executing command PRINTENV IDF_PATH.

You are almost there. To get further, we need to connect the ESP32 board to PC via the USB. After you connected the module, check under what serial port the board is visible and if communication via serial works. For windows users, port should be prefixed with COM (ex. COM5), as for unix it usually appear under a path (ex. /etc/tinyusb). If everything goes well, the next step is to setup a Hello-World project.

Configuring a new project

Being in the mingw32 terminal, copy the already existing Hello World example from the ESP-IDF suite, into the esp root folder using next commands:

cd ~/esp
cp -r $IDF_PATH/examples/get-started/hello_world .

Now, the next step is to configure the runtime parameters for the current project. To do that, change the path to the hellow_world folder which you copied into the esp folder and execute the make menuconfig command:

cd ~/esp/hello_world
make menuconfig

If the above steps were done correctly, you should see the following screen:

ESP-IDF Development Framework Configuration

In the menu, navigate to Serialflasherconfig > Defaultserialport to configure the serial port, where project will be loaded to. Confirm selection by pressing enter, save configuration by selecting <Save> and then exit application by selecting <Exit>.

ESP-IDF Development Framework Configuration

You can also change the flash parameters like SPI mode, SPI speed and Flash size according with your ESP32 version. Save this configuration and get back to the terminal.

Building and deploying

Now, the only thing that we need to do is to flash the project on the module. To do that, the make flash command needs to be executed. This process may take some time depending on the project size, just be patient. You should see something like this in the terminal:

ESP-IDF make flash command

Monitoring results

To see if the application is indeed running, you need to start the IDF Monitor, which is launched by the make monitor command. After that, the IDF Monitor will display the output of the ESP32 module like in the image bellow:

ESP-IDF Monitor

There you go! We have made it to build, deploy and test an application using the ESP-IDF software development framework. You can try different projects from the ESP-IDF example suite. There are allot, and cover all features and functions.

ESP-IDF framework folder structure

Just to make an idea about how the code looks (if you are not familiar with C), see below the code for the hello_world example which we deployed above:

There are different ways to build/make in C language, some of available IDEs have native embedded compilers. Before starting a new project using ESP-IDF you first need to get familiar with the newest API and libraries. You can find here (ESP-IDF API Guides) and here (ESP-IDF API Reference) everything you need to know in order to exploit all ESP32 features with ESP-IDF framework.

Programming ESP32 with Arduino

As I told you before, Arduino will only bottleneck the real power of ESP32, but nevertheless we need at least to give it a chance hoping that the Arduino community will add support for this board too.

Because the pair of Tensilica cores in the ESP32 are Xtensa-based – not your standard ARM or AVR, native Arduino support is not available, so you wont be able to find the ESP32 in Arduino IDE Board Manager. Fortunately there is a GNU compiler available for the ESP32, the ESP Core, supported by Espressif.

First you need to clone or download the sources from Espressif’s official ESP32 Arduino git hosting. To install the ESP32 board definitions, you’ll need download the contents of the esp32-arduino repository, and place them in a “hardware/espressif/esp32” directory in your Arduino sketchbook directory. Alternatively, these files can be installed in your Arduino’s base directory. On Windows, that may be C:/Program Files (x86)/Arduino/hardware and on Mac that may be /Applications/Arduino.app/Contents/Java/hardware.

ESP32 Arduino integration resources

To compile code for the ESP32, you need the Xtensa GNU compiler collection (GCC) installed on your machine. Windows users can run get.exe, found in the “esp32/tools” folder.

ESP32 Arduino integration resources

Mac and Linux users should run the tools/get.py python script to download the tools. Using a terminal, navigate to the esp32/tools folder. Then type: python get.py. If everything works well, after you restart the Arduino IDE, the ESP32 board should be available in board selection:

ESP32 Arduino Board Manager

With everything ready, now you can proceed further and upload Arduino applications in the same way as you do with ESP8266 and other Arduino capable boards. There are also few examples available once you install Espressif resources, which you can tryout:

ESP32 Arduino examples

Conclusion – ESP32 pros and cons

There are millions of IoT projects created with ESP8266 in the world. Although ESP32 brings way more features and claims improvements, it may not be a good replace for ESP8266. In the last months I had the chance to play with an ESP32, and I can tell you that there are some downsides:

Despite the sketches uploaded were not so large, for some reason the WROOM-32 metallic enclosure get pretty hot (sometimes 45 C). This may be a big problem if you try to embed ESP32 into a temperature monitoring system, as it can directly influence the ambient temperature.

Uploading the code takes a bit longer sometimes, but this is random. Its probably from the USB/UART bridge. I waited 30 seconds the most.

Bluetooth capabilities are pretty hard to implement, when comparing with WiFi features.

Despite my module has Dual-Core, I couldn’t find a way to do multi-threading, to really take advantage when complex processing is needed.

Power consumption is higher than ESP8266 (make sense because of dual-core, but it’s a drawback if you have battery-powered projects)

Built-in temperature sensor is useless in real life projects.

When running both WiFi and Bluetooth functions, sometimes high power spikes appear (biggest was 790mA)

Making a simple project requires above medium programming skills.

At the end of the day, there is noting perfect. Even ESP8266 and the other predecessors had issues and they still did the job. The advantages are clearly obvious. The tones of features that this module has to offer, overtake the cons, which probably, as most bugs, will be solved in future versions. Also, seems that Espressif constantly updates ESP-IDF with new features and better APIs. The only thing sad is that, getting so feature full and complex will slowly narrow the people segment that can easily use it.

Where can you buy ESP32 modules?

I have made a selection with, probably, the best offers on Amazon for ESP32 hoping that this will make your life easier:

Hoping that this article inspired you, i kindly invite you sharethis article, subscribe my YouTube channel and join the communities on social networks. Please feel free to comment or send suggestions / remarks so i can improve the content quality!