members
Basics: Project 072x ESP32 Development board - Espressif IoT Development Framework
of Acoptex.com in ESP8266 ESP-32
Basics: Project 072x
Project name: ESP32 Development board - Espressif IoT Development Framework
Tags: ESP32 Dev Module, ESP32 development board, ESP32 Development board with WiFi and Bluetooth, ESP32-DevKitC V4 development board, ESP-WROOM-32 module with ESP32‑D0WDQ6 chip, Espressif Systems, ESP32-based development board, ESP32 modules, ESP32-WROOM-32, ESP32-WROOM-32U, ESP32-WROOM-32D, ESP32-SOLO-1, USB-UART bridge, IOT, ESP-WROOM-32 Dev Module, ESP32 DEVKITV1, Installing the ESP32 Board in Arduino IDE, Uploading sketch, Espressif IoT Development Framework, esp-idf, Espressif ESP32, Toolchain
In this project, you need these parts :
1. ESP32 development board with WiFi and Bluetooth and USB A / micro USB B cable 1 pc
2. MSYS2 ( you can download it here )
General
We will learn how to set up the software environment for development of applications using hardware based on the Espressif ESP32. We would like to show you how to use ESP-IDF (Espressif IoT Development Framework), including the menu based configuration, compiling the ESP-IDF and firmware download to ESP32 boards.
ESP-IDF is the official development framework for the ESP32 chip. Espressif provides the basic hardware and software resources that help application developers to build their ideas around the ESP32 series hardware. 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.
What do you need to develop applications for ESP32?
You will need:
- PC with Windows or Linux or Mac operating system (OS);
- Toolchain to build the application for ESP32;
- ESP-IDF that essentially contains API for ESP32 and scripts to operate the Toolchain;
- A text editor to write programs (projects) in C, e.g. Eclipse;
- The ESP32 development board and a USB cable to connect it to the PC.
Preparation of development environment and application development process consists of these steps:
- Setup of Toolchain;
- Getting of ESP-IDF from GitHub;
- Installation and configuration of Eclipse. You can use a different editor;
- 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 development board;
- Monitoring / debugging of the application.
There are a lot of different development boards made. You can find more information about them here.
Understanding the ESP32 Development board with WiFi and Bluetooth
We will discuss here an Espressif Systems products. Our development board is using ESP-WROOM-32 module from Espressif Systems.
Espressif offers a wide range of fully-certified Wi-Fi & BT modules powered by their own advanced SoCs.
1. Dual-core Modules with Wi-Fi & Dual-mode Bluetooth
Features
- Two independently-controlled CPU cores with adjustable clock frequency, ranging from 80 MHz to 240 MHz
- +19.5 dBm output at the antenna ensures a good physical range
- Classic Bluetooth for legacy connections, also supporting L2CAP, SDP, GAP, SMP, AVDTP, AVCTP, A2DP (SNK) and AVRCP (CT)
- Support for Bluetooth Low Energy (BLE) profiles including L2CAP, GAP, GATT, SMP, and GATT-based profiles like BluFi, SPP-like, etc
- Bluetooth Low Energy (BLE) connects to smart phones, broadcasting low-energy beacons for easy detection
- Sleep current is less than 5 μA, making it suitable for battery-powered and wearable-electronics applications
- Integrates 4 MB flash
- Peripherals include capacitive touch sensors, Hall sensor, low-noise sense amplifiers, SD card interface, Ethernet, high-speed SPI, UART, I2S and I2C
- Fully certified with integrated antenna and software stacks
2. Single-core Modules with Wi-Fi & Dual-mode Bluetooth
Features
- High-performance 160 MHz single-core CPU
- +19.5 dBm output at the antenna ensures a good physical range
- Classic Bluetooth for legacy connections, also supporting L2CAP, SDP, GAP, SMP, AVDTP, AVCTP, A2DP (SNK) and AVRCP (CT)
- Support for Bluetooth Low Energy (BLE) profiles including L2CAP, GAP, GATT, SMP, and GATT-based profiles like BluFi, SPP-like, etc
- Bluetooth Low Energy (BLE) connects to smart phones, broadcasting low-energy beacons for easy detection
- Sleep current is less than 5 μA, making it suitable for battery-powered and wearable-electronics applications
- Peripherals include capacitive touch sensors, Hall sensor, low-noise sense amplifiers, SD card interface, Ethernet, high-speed SPI, UART, I2S and I2C
- Fully certified with integrated antenna and software stacks
3. Single-core Modules with 802.11b/g/n 2.4 GHz Wi-Fi
Features
- High-performance 160 MHz single-core CPU
- +19.5 dBm output at the antenna ensures a good physical range
- Sleep current is less than 20 μA, making it suitable for battery-powered and wearable-electronics applications
- Peripherals include UART, GPIO, I2C, I2S, SDIO, PWM, ADC and SPI
- Fully certified with integrated antenna and software stacks
There are different development Boards made by Espressif Systems and other manufacturers. We will publish some information about Espressif Systems boards but you can also find out more information about other development boards here.
1. 2.4 GHz Wi-Fi & BT/BLE Development Boards
Features
- PC connectivity: USB
- Power supply options: USB (by default), or 5V/GND header pins, or 3V3/GND header pins
- SDK: ESP-IDF source code and example applications
2. 2.4 GHz Wi-Fi Development Boards
Features
- PC connectivity: USB
- SDK: ESP8266 SDK source code and example applications
3. 2.4 GHz Wi-Fi + BT/BLE + Sensor Development Boards
Features
- PC connectivity: USB
- SDK: ESP-IOT-SOLUTION source code and example applications
You can find more information (datasheets, schematics, pins descriptions, functional desgn descriptions) about each board by pressing Getting started link close to each board here.
ESP32 chip
ESP32 is a series of low cost, low power system on a chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth. The ESP32 series employs a Tensilica Xtensa LX6 microprocessor in both dual-core and single-core variations and includes in-built antenna switches, RF balun, power amplifier, low-noise receive amplifier, filters, and power management modules. ESP32 is created and developed by Espressif Systems, a Shanghai-based Chinese company, and is manufactured by TSMC using their 40 nm process. It is a successor to the ESP8266 microcontroller.
ESP32 can perform as a complete standalone system or as a slave device to a host MCU, reducing communication stack overhead on the main application processor. ESP32 can interface with other systems to provide Wi-Fi and Bluetooth functionality through its SPI / SDIO or I2C / UART interfaces.
ESP32 is highly-integrated with in-built antenna switches, RF balun, power amplifier, low-noise receive amplifier, filters, and power management modules. ESP32 adds priceless functionality and versatility to your applications with minimal Printed Circuit Board (PCB) requirements.
ESP32 is capable of functioning reliably in industrial environments, with an operating temperature ranging from –40°C to +125°C. Powered by advanced calibration circuitries, ESP32 can dynamically remove external circuit imperfections and adapt to changes in external conditions.
Engineered for mobile devices, wearable electronics and IoT applications, ESP32 achieves ultra-low power consumption with a combination of several types of proprietary software. ESP32 also includes state-of-the-art features, such as fine-grained clock gating, various power modes and dynamic power scaling.
Functional Block Diagram:

Features of the ESP32 include the following:
Processors:
- CPU: Xtensa dual-core (or single-core) 32-bit LX6 microprocessor, operating at 160 or 240 MHz and performing at up to 600 DMIPS
- Ultra low power (ULP) co-processor
- Memory: 520 KiB SRAM
Wireless connectivity:
- Wi-Fi: 802.11 b/g/n
- Bluetooth: v4.2 BR/EDR and BLE
Peripheral interfaces:
- 12-bit SAR ADC up to 18 channels
- 2 × 8-bit DACs
- 10 × touch sensors (capacitive sensing GPIOs)
- Temperature sensor
- 4 × SPI
- 2 × I²S interfaces
- 2 × I²C interfaces
- 3 × UART
- SD/SDIO/CE-ATA/MMC/eMMC host controller
- SDIO/SPI slave controller
- Ethernet MAC interface with dedicated DMA and IEEE 1588 Precision Time Protocol support
- CAN bus 2.0
- Infrared remote controller (TX/RX, up to 8 channels)
- Motor PWM
- LED PWM (up to 16 channels)
- Hall effect sensor
- Ultra low power analog pre-amplifier
Security:
- IEEE 802.11 standard security features all supported, including WFA, WPA/WPA2 and WAPI
- Secure boot
- Flash encryption
- 1024-bit OTP, up to 768-bit for customers
- Cryptographic hardware acceleration: AES, SHA-2, RSA, elliptic curve cryptography (ECC), random number generator (RNG)
Power management:
- Internal low-dropout regulator
- Individual power domain for RTC
- 5uA deep sleep current
- Wake up from GPIO interrupt, timer, ADC measurements, capacitive touch sensor interrupt
You can find ESP32 chip datasheet here, hardware design here, technical reference manual here.
Signals and connections of the ESP32 Development board with WiFi and Bluetooth
You can find more information (datasheets, schematics, pins descriptions, functional desgn descriptions) about each board (made by Espresiff Systems) by pressing Getting started link close to each board here.
Let's check our development board - ESP32 DEVKITV1 with ESP-WROOM-32 module from Espressif Systems:
Pinout diagram for the ESP Wroom 32 breakout:
ESP32-WROOM-32 - ESP32-WROOM-32 module soldered to the development board. Optionally ESP32-WROOM-32D, ESP32-WROOM-32U or ESP32-SOLO-1 module may be soldered instead of the ESP32-WROOM-32.
USB-UART Bridge - A single chip USB-UART bridge provides up to 3 Mbps transfers rates.
BOOT button - Download button: holding down the Boot button and pressing the EN button initiates the firmware download mode. Then user can download firmware through the serial port.
EN button - Reset button: pressing this button resets the system.
Micro USB Port - USB interface. It functions as the power supply for the board and the communication interface between PC and the ESP module.
TX0, TX2 - transmit pin. GPIO pin
RX0, RX2 - receive pin. GPIO pin
3V3 (or 3V or 3.3V) - power supply pin (3-3.6V).
GND - ground pin.
EN - Chip enable. Keep it on high (3.3V) for normal operation.
Vin - External power supply 5VDC.
Wiring
Step by Step instruction
The ESP32 is currently being integrated with the Arduino IDE like it was done for the ESP8266. There’s an add-on for the Arduino IDE that allows you to program the ESP32 using the Arduino IDE and its programming language.
1. Adding ESP32 add-on to the Arduino IDE (Windows)
- Download and install the latest Arduino IDE Windows Installer from arduino.cc
- Download and install Git and Git GUI from git-scm.com
- Search for Git GUI, right-click the icon and select “Run as administrator“
- Select the Clone Existing Repository option.
- Select source and destination. Source Location: https://github.com/espressif/arduino-esp32.git
- Target Directory:C:/Users/[YOUR_USER_NAME]/Documents/Arduino/hardware/espressif/esp32
- Do not create the espressif/esp32 folders, because they will be created automatically.
- Click Clone to start cloning the repository.Wait a few seconds while the repository is being cloned.
- Open the folder: C:/Users/[YOUR_USER_NAME]/Documents/Arduino/hardware/espressif/esp32/tools
- Right-click the get.exe file and select “Run as administrator“.
- You will see that necessary files will be downloaded and upzipped. It will take some time.
- When get.exe finishes, you should see the following files in the directory.
2. Setup of the Toolchain
The esp-idf build system does not support spaces in paths to esp-idf or to projects. Before installation make sure that Your_Name or User_name is a single word otherwise you will have a problems later. For example: C:\Users\John Best is wrong as it has two words but C:\Users\JohnBest is right as it is the single word. See on the picture below:
We need to install a prebuilt toolchain before we start a development with ESP32 development board. Let's have a look how to do it in Windows OS (instructions for Linux OS and Mac OS)
Windows doesn’t have a built-in “make” environment, so as well as installing the toolchain you will need a GNU-compatible environment. We use the MSYS2 environment to provide this. You don’t need to use this environment all the time (you can use Eclipse or some other front-end), but it runs behind the scenes.
- Go to msys2.org website and download and run the installer "i686" for 32-bit Windows (Espressif only supports a 32-bit MSYS environment, it works on both 32-bit and 64-bit Windows).
- Press Next button.
- Specify an installation folder (ASCII, no accents, spaces nor symlinks, short path). Press Next button.
- Press Next button.
- Uncheck Run MSYS2 32-bit now checkbox and press Finish button.
- Open Start Menu and find MSYS2 MinGW 32-bit to run the terminal. Why do we launch this different terminal? MSYS2 has the concept of different kinds of environments. The default MSYS environment is Cygwin-like and uses a translation layer for all Windows API calls. We need the MinGW environment in order to have a native Python which supports COM ports.
- The ESP-IDF repository on github contains a script in the tools directory titled windows_install_prerequisites.sh. If you haven’t got a local copy of the ESP-IDF yet - you can just download this file in Raw format from here and save it somewhere on your PC (we saved it to msys32 folder).
- Type the path to the saved file windows_install_prerequisites.sh into the MSYS2 terminal window: C:/msys32/windows_install_prerequisites.sh.
- This script will download and install packages for ESP-IDF support and the ESP32 toolchain.
- Close terminal window when process finished.
- Open Start Menu and find MSYS2 MinGW 32-bit to run the terminal again.
- Type the path to the saved file windows_install_prerequisites.sh into the MSYS2 terminal window: C:/msys32/windows_install_prerequisites.sh.
- This script will check, download and install updated packages for ESP-IDF support and the ESP32 toolchain.
- MSYS2 environment is now ready to use ESP-IDF. Run command in MSYS2 terminal window: source /etc/profile to add the toolchain to your path. This command produces no output. You only need to do this once, future terminals do this automatically when opened.
- Close the MSYS2 terminal window.
3. Downloading and installing ESP-IDF
- Besides the toolchain (that contains programs to compile and build the application), you also need ESP32 specific API / libraries. They are provided by Espressif in ESP-IDF repository.
- Go to C:\msys32\home\Your_Name and create the esp folder.
- Open Start Menu and find MSYS2 MinGW 32-bit to run the terminal. Then navigate to the directory you want to put ESP-IDF and clone the repository using git clone commands: cd ~/esp and
- git clone --recursive https://github.com/espressif/esp-idf.git
- ESP-IDF will be downloaded into C:\msys32\home\Your_Name\esp\esp-idf. This command will clone the master branch, which has the latest development (“bleeding edge”) version of ESP-IDF. It is fully functional and updated on weekly basis with the most recent features and bugfixes.
4. Setup Path to 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. We will have a look how to do it on Windows 10. (instructions specific to Linux and MacOS in section Add IDF_PATH to User Profile)
- The user profile scripts are contained in C:/msys32/etc/profile.d/ directory. They are executed every time you open an MSYS2 window. Create a new script file in C:/msys32/etc/profile.d/ directory. Name it export_idf_path.sh.
- Identify the path to ESP-IDF directory. It is specific to your system configuration and may look something like C:\msys32\home\Your_Name\esp\esp-idf. Make sure that Your_Name is a single word otherwise you will have an error later.
- Add the export command to the export_idf_path.sh file: export IDF_PATH="C:/msys32/home/Your_Name/esp/esp-idf" and save it.
- Close MSYS2 terminal window.
- Open Start Menu and find MSYS2 MinGW 32-bit to run the terminal. Check if IDF_PATH is set, by typing: printenv IDF_PATH . The path previusly entered in the script file should be printed out.
- If you do not like to have IDF_PATH set up permanently in user profile, you should enter it manually on opening of an MSYS2 terminal window: export IDF_PATH="C:/msys32/home/user-name/esp/esp-idf"
5. Install the Required Python Packages
-
Python packages required by ESP-IDF are located in the $IDF_PATH/requirements.txt file. You can install them by running:python -m pip install --user -r $IDF_PATH/requirements.txtPython packages required by ESP-IDF are located in the $IDF_PATH/requirements.txt file.
- Open Start Menu and find MSYS2 MinGW 32-bit to run the terminal. Please invoke that version of the Python interpreter which you will be using with ESP-IDF. The version of the interpreter can be checked by running command: python --version and depending on the result, you might want to use python2, python2.7 or similar instead of python, for example python2.7 packages can be installed by running: python2.7 -m pip install --user -r $IDF_PATH/requirements.txt
-
- Close MSYS2 terminal window.
6. Start project
- Now you are ready to prepare your application for ESP32 development board. To start off quickly, we will use get-started/hello_world project from examples directory in IDF.
- Open Start Menu and find MSYS2 MinGW 32-bit to run the terminal.
- Copy get-started/hello_world to ~/esp directory by running this command first: cd ~/esp
- Then run: cp -r $IDF_PATH/examples/get-started/hello_world .
- You can also find a lot of other projects in the examples directory in ESP-IDF. These example project directories can be copied in the same way as presented above to begin your own projects.
- Plug the ESP32 development board to your PC and wait for the drivers to install (or install manually any that might be required).
- Check under what serial port the board is visible. Just press the WIN (Windows) key and the X key together on your keyboard. You will see the Power User Menu opened. Select the Device Manager and open Ports - you will see UART bridge port (We have COM8).
- If you don’t see it in Device Manager, you need to install the ESP32 CP210x USB to UART Bridge VCP Drivers.
- Please note the port number, as it will be required soon. Go to directory of hello_world application by typing command in MSYS2 terminal window: cd ~/esp/hello_world
- Start project configuration utility menuconfig by typing command in MSYS2 terminal window: make menuconfig
- If previous steps have been done correctly, the following menu will be displayed:
- Select Serial flasher config and press Enter button on your keyboard. Use up & down arrow keys to navigate the menu. Use Enter key to go into a submenu, Escape key to go out or to exit.
- Select Default serial port to configure the serial port, where project will be loaded to. On Windows, serial ports have names like COM1. On MacOS, they start with /dev/cu.. On Linux, they start with /dev/tty. We have ESP32 attached to COM8 port so we changed default port to COM8.
- Confirm selection by pressing Enter button on your keyboard. Then save configuration by selecting Save. Press Enter button on your keyboard.
- Then exit application by selecting Exit button twice.
- Run the command in MSYS2 terminal window: C:/msys32/mingw32/bin/python.exe -m pip install --user -r C:/msys32/home/User_name/esp/esp-idf/requirements.txt
- Now you can build and flash the application. Run the command in terminal window: make flash . You need to hold the ESP32 on-board Boot button while uploading. This will compile the application and all the ESP-IDF components, generate bootloader, partition table, and application binaries, and flash these binaries to your ESP32 board. If you would like to use the Eclipse IDE instead of running make, check out the Eclipse guide.
- If there are no issues, at the end of build process, you should see messages describing progress of loading process. Finally, the end module will be reset and hello_world application will start.
- Press the ESP32 on-board EN button to reboot it.
- To see if hello_world application is running, type command in MSYS2 terminal window: make monitor . This command will launch IDF Monitor application.
- Several lines below, after start up and diagnostic log, you should see “Hello world!” printed out by the application.
- To exit the monitor use shortcut Ctrl+].
Troubleshooting
- While the install script runs, MSYS may update itself into a state where it can no longer operate. You may see errors like the following: *** fatal error - cygheap base mismatch detected - 0x612E5408/0x612E4408. This problem is probably due to using incompatible versions of the cygwin DLL. If you see errors like this, close the terminal window entirely (terminating the processes running there) and then re-open a new terminal. Re-run windows_install_prerequisites.sh (tip: use the up arrow key to see the last run command). The update process will resume after this step.
- MSYS2 is a “rolling” distribution so running the installer script may install newer packages than what is used in the prebuilt environments. If you see any errors that appear to be related to installing MSYS2 packages, please check the MSYS2-packages issues list for known issues. If you don’t see any relevant issues, please raise an IDF issue.
- If instead of the messages above, you see a random garbage similar to:e���)(Xn@�y.!��(�PW+)��Hn9a/9�!�t5��P�~�k��e�ea�5�jA~zY��Y(1�,1�� e���)(Xn@�y.!Dr�zY(�jpi�|�+z5Ymvp or monitor fails shortly after upload, your board is likely using 26MHz crystal, while the ESP-IDF assumes default of 40MHz. Exit the monitor, go back to the menuconfig, change CONFIG_ESP32_XTAL_FREQ_SEL to 26MHz, then build and flash the application again. This is found under make menuconfig under Component config –> ESP32-specific –> Main XTAL frequency. To execute make flash and make monitor in one go, type make flash monitor. Check section IDF Monitor for handy shortcuts and more details on using this application.
- The esp-idf build system does not support spaces in paths to esp-idf or to projects. Before installation make sure that Your_Name or User_name is a single word otherwise you will have a problems later. For example: C:\Users\John Best is wrong as it has two words but C:\Users\JohnBest is right as it is the single word. See on the picture below:
-
If you are getting this error when running make flash and make monitor: The following Python requirements are not satisfied:pyserial>=3.0future>=0.16.0 please run command in MSYS2 terminal window: C:/msys32/mingw32/bin/python.exe -m pip install --user -r C:/msys32/home/User_name/esp/esp-idf/requirements.txt for resolving the issue.
-
If you are getting this error when running make flash: import serial.tools.list_ports as list_portsImportError: No module named serial.tools.list_portsmake[1]: *** [/home/User_name/esp/esp-idf/components/esptool_py/Makefile.projbuild:59: /home/Jonas/esp/hello_world/build/bootloader/bootloader.bin] Error 1make: *** [/home/User_name/esp/esp-idf/components/bootloader/Makefile.projbuild:41: /home/Jonas/esp/hello_world/build/bootloader/bootloader.bin] Error 2 please run command in MSYS2 terminal window: C:/msys32/mingw32/bin/python.exe -m pip install --user -r C:/msys32/home/User_name/esp/esp-idf/requirements.txt for resolving the issue and then run the command: make flash again.
Updating
After some time of using ESP-IDF, you may want to update it to take advantage of new features or bug fixes. The simplest way to do so is by deleting existing esp-idf folder and cloning it again, exactly as when doing initial installation described in sections Get ESP-IDF.
If downloading to a new path, remember to Add IDF_PATH to User Profile so that the toolchain scripts know where to find the ESP-IDF in its release specific location.
Another solution is to update only what has changed. The update procedure depends on the version of ESP-IDF you are using.
When IDF is updated, sometimes new toolchains are required or new system requirements are added to the Windows MSYS2 environment.
Rather than setting up a new environment, you can update an existing Windows environment & toolchain:
- Update IDF to the new version you want to use.
- Run the tools/windows/windows_install_prerequisites.sh script inside IDF. This will install any new software packages that weren’t previously installed, and download and replace the toolchain with the latest version.
The script to update MSYS2 may also fail with the same errors mentioned under Troubleshooting.
If you need to support multiple IDF versions concurrently, you can have different independent MSYS2 environments in different directories. Alternatively you can download multiple toolchains and unzip these to different directories, then use the PATH environment variable to set which one is the default.
Summary
We have learnt how to set up the software environment for development of applications using hardware based on the Espressif ESP32.
Libraries
- No libraries required for this project
Sketch
- No sketch
Other projects of Acoptex.com










Viewed: 2440 times