Esp32 Dev Board C
In this article, we are going to introduce you to a new microcontroller ESP32. We all have some idea about Arduino development boards and how they are widely used. But when it comes to ESP32 then it is has many advantages over Arduino development boards. The older version of this board is ESP8266. So let’s discuss this microcontroller in detail. We will have a look at its specifications, key features, pins layout, powering of this board, preference over Arduino and blinking led code that can run on this microcontroller. So let’s get started.
- Esp32 Board Manager
- Makerfocus Esp32 Development Board
- Esp32 Dev Board Power Consumption
- Esp32 Dev Board Circuit
- Esp32 Dev Board C E
if you want to purchase ESP32 development board, you can purchase from this link: ESP32
INTRODUCTION to ESP32 development board
- ESP32-DevKitC is a low-footprint, breadboard-friendly, minimum system development board which is powered by the ESP32-WROOM-32D module. ESP32-DevKitC Features: Amazon-Qualified Device ESP32-DevKitC is an AWS-qualified development board. In addition to Espressif’s own ESP-IDF SDK, you can use Amazon FreeRTOS on ESP32-DevKitC.
- The easiest way to power your ESP32 dev kit is to use the USB port. The dev kit includes a micro USB port through which you can both supply power to the board, and implement serial communication with the host computer for uploading a sketch.
The development board breaks out all the module’s pins to 0.1″ headers and provides a CP2102 USB-TTL serial adapter, programming and reset buttons, and a power regulator to supply the ESP32 with a stable 3.3 V. Espressif doubled-down on the CPU resources for the ESP32 with a dual core, running at 160MHz and tons more pins and peripherals. ESP32-DevKitC V4 is a small-sized ESP32-based development board produced by Espressif. Most of the I/O pins are broken out to the female pin headers on both sides for easy interfacing. Developers can connect these pins to peripherals as needed. Serum free trial vst. Standard female headers also make development easy and convenient when using Dupont wires.
ESP32 is in the series of low power and low cost on chip microcontroller. It comes up with already integrated dual mode Bluetooth and Wi-Fi. It is especially aimed to provide versatility, robustness and reliability in a large number of applications. Some applications in which this microcontroller is extensively used are MP3 decoding, voice encoding and music streaming. Best RF and power performance can be easily achieved using this microcontroller. ESP32 comes up with a USB port so we can say that it is a plug and play device i.e. just plug in cable and your device is turned on and you are able to program it just like Arduino development boards. We will go in details of programming this board later.
COMPARISON OF ESP32 WITH ARDUINO
If we compare this microcontroller with Arduino boards then we have a big advantage of this microcontroller over Arduino development boards and that is of Wi-Fi. Although Wi-Fi can be used with many Arduino boards but this feature comes up in form of shields / adapters. If we attach Wi-Fi shield with our Arduino board then we can access internet in our Arduino board otherwise it’s not possible. ESP32 comes up with integrated Wi-Fi module. Same is the case with Bluetooth which is available in Arduino in form of some modules and when it comes to ESP32, this feature is already integrated. So if we are interested in using Wi-Fi and Bluetooth then this board is less expensive as compared to Arduino boards as these adapters for Wi-Fi and Bluetooth are expensive.
KEY FEATURES OF ESP32
- Built in Wi-Fi module of standard 802.11
- Wi-Fi module operate in range of 2.4 GHz – 2.5 GHz
- Three modes of operation: 1. Access point. 2. Client. 3. Access point + station
- Dual core microprocessor of 32 – bit
- Operating voltage is 3.3 V
- Clock frequency from 80 MHz and goes up to 240 MHz
- SRAM memory is of 512 KB
- ROM memory is 448 KB
- External flash memory is supported and is up to 32 Mb i.e. 4MB
- Maximum current in each pin is 12 mA but 6 mA is recommended to use
- It has 36 general purpose input / output pins
- General purpose input / output pins comes up with PWM / I2C and SPI functionality
- Bluetooth version 4.2 is available and Bluetooth low energy (BLE) version
- 2 to 3.6 V operating voltage
- Deep sleep current of 2.5 µA
- 10 electrode capacitive touch support
- Hardware supported encryption for AES, ECC, RSA – 4096, SHA2
- On board PCB antenna or IPEX connector which act as external antenna
- Operating temperature lies in range of -40°C to +125°C
PINS SPECIFICATIONS OF ESP32
ESP32 supports pin multiplexing feature i.e. we can decide that from 28 broken input / output pins which peripherals can be connected. It simply means that it’s up to us that we have to decide for these pins and they can act as MISO, RX, SCLK, MOSI, TX, SCL, SDA and many more. However pins for analog to digital convertor and digital to analog convertor are static
- Analog to digital convertor (ADC) channels are 18
- SPI interfaces are 3
- UART interfaces are 3
- I2C interfaces are 2
- PWM outputs are 16
- Digital to analog convertors (DAC) are 2
- I2S interfaces are 2
SENSORS ON ESP32
- Hall sensors
- 32 kHz crystal oscillator
- Ultra low noise analog amplifier
- 10x capacitive touch interfaces
POWERING ESP32 DEVELOPMENT BOARD
In order to turn on your ESP32 development board we can either make use of USB port or LiPo battery. If we use these both devices in our board then the charge controller that is already present on board will charge our LiPo battery. There is also a 3.3 V voltage regulator present on board which will deliver current of 600 mA. During the RF transmission our board can pull up as much as 250 mA. Our general purpose input output pins cannot tolerate 5 V. So if we need to interface our board with 5 V then we have to so level shifting.
PROGRAMMING OF ESP32
Arduino IDE can be used for programming of this board. But we have to install some drivers and libraries in order to make it compatible in Arduino IDE and ready to use just like we use other Arduino boards in Arduino IDE. So a brief explanation of drivers and libraries that are needed is given below.
INSTALL DRIVERS
The very first and important thing to program this board is to install CP210x USB – UART drivers. Depending on your operating system, install the proper drivers.
INSTALL LIBRARIES FOR ESP32
You can install libraries for ESP32 by using GitHub. After installing all these drivers and libraries you are ready to program your board. You can use Terminal in MAC or command line in windows operating system to install these libraries from GitHub.
Once you are done with installation of required drivers and libraries you have to restart Arduino IDE and you are ready to go. After restarting your Arduino IDE you will see several boards added in the tools menu of Arduino IDE. Now select your appropriate board.
BLINKING A LED:
So the first program we are going to discuss is blinking of a LED. All code for LED blinking will be written in Arduino IDE. There is a built in led in ESP32 development kit that is connected to general purpose input / output pin 02. One more thing we need to check before writing our code is to ensure that our built in led in ESP32 development board is supported by Arduino IDE. If it is recognized by Arduino IDE then you are ready to write your code otherwise you have to make it recognizable by Arduino IDE by using following piece of code
Esp32 Board Manager
- int LED_BUILTIN = 2;
Each ESP32 board is having an internal led connected but they are connected to different general purpose input output pins. In our case, an internal blue led is connected at general purpose input output pin. So let’s write our piece of code.
Program flow of every code that we write in Arduino IDE is that first we initialize variables. Variables can be local or global. We will not go in the details of these local and global variables. After variables initialization, our setup function will be called that is used to assign values of initialized variables and then our loop function is called. Setup function will be called only once while loop function as obvious from name will run continuously in organized manner. If we want to call setup function again then we have to re-run our program or restart our development board either by using rest button on board or by disconnecting and connecting our board again.
So if we have a look at our code by keeping the points stated above in our mind, we first have initialized our built-in LED at general purpose input output pin 2. After initialization of this built-in LED we can see that the initialization and purpose of this led that whether it is acting as input or output. After assigning it as output we go the loop function which will run endlessly unless and until we disconnect our board or stop running this program. In our loop function we first turned on our led using DigitalWrite function and assigning our led high voltage, then we waited for 1 second delay and then turned off our led by assigning low voltage to our led and then waited for another sec and so the loop continues i.e. this loop will turn on the led for 1 sec and then turn if off for 1 sec and it continues. you can now check these:
We are done in giving you a daily dose of useful information. Any question related to this article can be asked in comment section below.
(See the README.md file in the upper level 'examples' directory for more information about examples.)
This example demonstrates how to use an SD card with ESP32 or ESP32-S2. Example does the following steps:
- Use an 'all-in-one'
esp_vfs_fat_sdmmc_mount
function to:- initialize SDMMC peripheral,
- probe and initialize the card connected to SD/MMC slot 1 (HS2_CMD, HS2_CLK, HS2_D0, HS2_D1, HS2_D2, HS2_D3 lines),
- mount FAT filesystem using FATFS library (and format card, if the filesystem can not be mounted),
- register FAT filesystem in VFS, enabling C standard library and POSIX functions to be used.
- Print information about the card, such as name, type, capacity, and maximum supported frequency.
- Create a file using
fopen
and write to it usingfprintf
. - Rename the file. Before renaming, check if destination file already exists using
stat
function, and remove it usingunlink
function. - Open renamed file for reading, read back the line, and print it to the terminal.
This example support SD (SDSC, SDHC, SDXC) cards and eMMC chips.
Hardware
Connections for ESP32
This example runs on ESP-WROVER-KIT boards without any extra modifications required, only the SD card needs to be inserted into the slot.
Other ESP32 development boards need to be connected to SD card as follows:
ESP32 pin | SD card pin | SPI pin | Notes |
---|---|---|---|
GPIO14 (MTMS) | CLK | SCK | 10k pullup in SD mode |
GPIO15 (MTDO) | CMD | MOSI | 10k pullup, both in SD and SPI modes |
GPIO2 | D0 | MISO | 10k pullup in SD mode, pull low to go into download mode (see Note about GPIO2 below!) |
GPIO4 | D1 | N/C | not used in 1-line SD mode; 10k pullup in 4-line SD mode |
GPIO12 (MTDI) | D2 | N/C | not used in 1-line SD mode; 10k pullup in 4-line SD mode (see Note about GPIO12 below!) |
GPIO13 (MTCK) | D3 | CS | not used in 1-line SD mode, but card's D3 pin must have a 10k pullup |
N/C | CD | optional, not used in the example | |
N/C | WP | optional, not used in the example |
This example doesn't utilize card detect (CD) and write protect (WP) signals from SD card slot.
With the given pinout for SPI mode, same connections between the SD card and ESP32 can be used to test both SD and SPI modes, provided that the appropriate pullups are in place.See the document about pullup requirements for more details about pullup support and compatibility of modules and development boards.
In SPI mode, pins can be customized. See the initialization of spi_bus_config_t
and sdspi_slot_config_t
structures in the example code.
Connections for ESP32-S2
Note that ESP32-S2 doesn't include SD Host peripheral and only supports SD over SPI. Therefore only SCK, MOSI, MISO, CS and ground pins need to be connected.
ESP32-S2 pin | SD card pin | SPI pin | Notes |
---|---|---|---|
GPIO14 | CLK | SCK | 10k pullup |
GPIO15 | CMD | MOSI | 10k pullup |
GPIO2 | D0 | MISO | 10k pullup |
GPIO13 | D3 | CS | 10k pullup |
N/C | CD | optional, not used in the example | |
N/C | WP | optional, not used in the example |
In SPI mode, pins can be customized. See the initialization of spi_bus_config_t
and sdspi_slot_config_t
structures in the example code.
Note about GPIO2 (ESP32 only)
GPIO2 pin is used as a bootstrapping pin, and should be low to enter UART download mode. One way to do this is to connect GPIO0 and GPIO2 using a jumper, and then the auto-reset circuit on most development boards will pull GPIO2 low along with GPIO0, when entering download mode.
- Some boards have pulldown and/or LED on GPIO2. LED is usually ok, but pulldown will interfere with D0 signals and must be removed. Check the schematic of your development board for anything connected to GPIO2.
Note about GPIO12 (ESP32 only)
GPIO12 is used as a bootstrapping pin to select output voltage of an internal regulator which powers the flash chip (VDD_SDIO). This pin has an internal pulldown so if left unconnected it will read low at reset (selecting default 3.3V operation). When adding a pullup to this pin for SD card operation, consider the following:
- For boards which don't use the internal regulator (VDD_SDIO) to power the flash, GPIO12 can be pulled high.
- For boards which use 1.8V flash chip, GPIO12 needs to be pulled high at reset. This is fully compatible with SD card operation.
- On boards which use the internal regulator and a 3.3V flash chip, GPIO12 must be low at reset. This is incompatible with SD card operation.
- In most cases, external pullup can be omitted and an internal pullup can be enabled using a
gpio_pullup_en(GPIO_NUM_12);
call. Most SD cards work fine when an internal pullup on GPIO12 line is enabled. Note that if ESP32 experiences a power-on reset while the SD card is sending data, high level on GPIO12 can be latched into the bootstrapping register, and ESP32 will enter a boot loop until external reset with correct GPIO12 level is applied. - Another option is to burn the flash voltage selection efuses. This will permanently select 3.3V output voltage for the internal regulator, and GPIO12 will not be used as a bootstrapping pin. Then it is safe to connect a pullup resistor to GPIO12. This option is suggested for production use.
- In most cases, external pullup can be omitted and an internal pullup can be enabled using a
The following command can be used to program flash voltage selection efuses to 3.3V:
This command will burn the XPD_SDIO_TIEH
, XPD_SDIO_FORCE
, and XPD_SDIO_REG
efuses. With all three burned to value 1, the internal VDD_SDIO flash voltage regulator is permanently enabled at 3.3V. See the technical reference manual for more details.
espefuse.py
has a --do-not-confirm
option if running from an automated flashing script.
How to use example
SD card can be used in various modes. See below on choosing the mode to be used.
4-line and 1-line SD modes
By default, example code uses the following initializer for SDMMC slot configuration:
Among other things, this sets slot_config.width = 0
, which means that SD/MMC driver will use the maximum bus width supported by the slot. For slot 1, it will switch to 4-line mode when initializing the card (initial communication always happens in 1-line mode). If some of the card's D1, D2, D3 pins are not connected to the ESP32, set slot_config.width = 1
— then the SD/MMC driver will not attempt to switch to 4-line mode.
Note that even if card's D3 line is not connected to the ESP32, it still has to be pulled up, otherwise the card will go into SPI protocol mode.
SPI mode
By default, the example uses SDMMC Host peripheral to access the card using SD protocol. To use SPI peripheral instead (and SPI protocol), uncomment #define USE_SPI_MODE
line in the example code.
Makerfocus Esp32 Development Board
Build and flash
Esp32 Dev Board Power Consumption
Build the project and flash it to the board, then run monitor tool to view serial output:
(Replace PORT with serial port name.)
(To exit the serial monitor, type Ctrl-]
.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
Esp32 Dev Board Circuit
Example output
Here is an example console output. In this case a 128MB SDSC card was connected, and format_if_mount_failed
parameter was set to true
in the source code. Card was unformatted, so the initial mount has failed. Card was then partitioned, formatted, and mounted again.
Troubleshooting
Failure to upload the example
Disconnect the SD card D0/MISO line from GPIO2 and try uploading again. Read 'Note about GPIO2' above.
Esp32 Dev Board C E
Card fails to initialize with sdmmc_init_sd_scr: send_scr (1) returned 0x107
error
Check connections between the card and the ESP32. For example, if you have disconnected GPIO2 to work around the flashing issue, connect it back and reset the ESP32 (using a button on the development board, or by pressing Ctrl-T Ctrl-R in IDF Monitor).
Card fails to initialize with sdmmc_check_scr: send_scr returned 0xffffffff
error
Connections between the card and the ESP32 are too long for the frequency used. Try using shorter connections, or try reducing the clock speed of SD interface.
Failure to mount filesystem
The example will be able to mount only cards formatted using FAT32 filesystem. If the card is formatted as exFAT or some other filesystem, you have an option to format it in the example code. Modify format_if_mount_failed = false
to format_if_mount_failed = true
in the example code, then build and flash the example.