Everything about Internet of Things and more

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?

ESP32 complete review and programming tutorial

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:

To have a better overview about what is under the hood, here is the ESP32 diagram block:

ESP32 Function Block Diagram

ESP32 Function Block Diagram

ESP32 available modules and development boards

ESP32 standalone module – BUY Now from Amazon with 40% DISCOUNT

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 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

Sparkfun ESP32 Development board pinout

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

Adafruit ESP32 Development Board WROOM32

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.

I have bought one of those (BUY Now from Amazon and SAVE money), and I will share with you some details. Below you can see how it looks:

ESP32 DOIT Devkit V1 Development board

ESP32 DOIT Devkit V1 Development board

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

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:

Makerfocus ESP32 OLED Development BoardBUY now from Amazon – SAVE MONEY %

ESP32 Makerfocus OLED development board

ESP32 Makerfocus OLED development board

 

0.96 OLED Display ESP32 WIFI Bluetooth Lora ModuleBUY  now from Amazon – SAVE MONEY %

0.96 OLED Display ESP32 WIFI Bluetooth Lora Module

0.96 OLED Display ESP32 WIFI Bluetooth Lora Module

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 codeCoreEmbedded flashConnectionPackage
ESP32-D0WDQ6Dual coreNo embedded flashWi-Fi b/g/n + BT/BLE Dual ModeQFN 6*6
ESP32-D0WDDual coreNo embedded flashWi-Fi b/g/n + BT/BLE Dual ModeQFN 5*5
ESP32-D2WDDual core16-Mbit embedded flashWi-Fi b/g/n + BT/BLE Dual ModeQFN 5*5
ESP32-S0WDSingle coreNo embedded flashWi-Fi b/g/n + BT/BLE Dual ModeQFN 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 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 modeActiveModem-sleepLight-sleepDeep-sleepHibernation
CPUONONPAUSEOFFOFF
Wi-Fi/BT baseband and radioONOFFOFFOFFOFF
RTC memory and RTC peripheralsONONONONOFF
ULP-coprocessorONONONON/OFFOFF

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 by Power mode

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

ESP32 Power consumption in active mode

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 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:

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:

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:

Probably the best books to learn C Programming language (Amazon DISCOUNTS):

C Programming Absolute Beginner’s Guide (3rd Edition) 
C Programming Language, 2nd Edition by Brian W. Kernighan – NOW 40% Discount

Programing the ESP32 with ESP-IDF

In order to develop applications with ESP-IDF you will need the following prerequisites:

ESP-IDF Pipeline setup

ESP-IDF Pipeline setup

Preparation of development environment consists of three steps:

  1. Setup of Toolchain
  2. Getting of ESP-IDF from GitHub
  3. Installation and configuration of Eclipse

You may skip the last step, if you prefer to use different editor.

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

  1. Configuration of a Project and writing the code
  2. Compilation of the Project and linking it to build an Application
  3. Flashing (uploading) of the Application to ESP32
  4. 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.

cd c:\esp
git clone --recursive https://github.com/espressif/esp-idf.git
ESP-IDF Guide - framework installation

ESP-IDF Guide – framework installation

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:

export IDF_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

ESP-IDF Development Framework Configuration

In the menu, navigate to Serial flasher config > Default serial port 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

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

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

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

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:

/* Hello World Example*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"

void app_main()
{
  printf("Hello world!\n");

 /* Print chip information */
  esp_chip_info_t chip_info;
  esp_chip_info(&chip_info);
  printf("This is ESP32 chip with %d CPU cores, WiFi%s%s, ",
    chip_info.cores,
   (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
   (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");

 printf("silicon revision %d, ", chip_info.revision);

 printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
  (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");

for (int i = 10; i >= 0; i--) {
  printf("Restarting in %d seconds...\n", i);
  vTaskDelay(1000 / portTICK_PERIOD_MS);
 }
  printf("Restarting now.\n");
  fflush(stdout);
  esp_restart();
}

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

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

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

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

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:

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 share this articlesubscribe 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!

Share on: Facebook Twitter Google+

2 Replies to “ESP32 – Cheapest IoT WiFi and Bluetooth ready module”

  1. Miha says:

    Good info in one place. Looking for some more BLE examples.

    • Working as we speak at ESP32 BLE & Bluetooth examples. Stay tuned!

Leave a Reply

Your email address will not be published.