Hello readers! I hope you're all doing well. Today, we are going to start a new tutorial series on the ESP32 Microcontroller board. In this programming series, I will try to explain everything related to ESP32. We will start from basic concepts and will gradually move towards complex projects. Because today's our first tutorial in this series, so I will give you a detailed introduction to the ESP32 family of devices. Before creating your first code, you should be familiar with the esp32 module's basic capabilities and components. Let's get started:
What is ESP32?
ESP32 is a complete standalone system, designed for mobile, wearable electronics, and Internet-of-Things (IoT) applications. The ESP32 is a family of system-on-chip microcontrollers that come in a range of low-cost modules. Espressif Systems created the ESP32.
Major components integrated with ESP32 are:
- Integrated WiFi
- Tensilica Xtensa LX6 Microprocessor (Dual Core Processor)
The ESP32 is a more feature-rich version of the ESP8266. Variations, through-chip modules, and a development board are all available.
ESP32 vs ESP8266
- Both the ESP32 and ESP8266 are inexpensive WiFi modules with low power consumption.
- Both modules are desirable for DIY projects in the areas of IoT (Internet of Things) and automation.
- The ESP32 is a dual-core 160Mhz 240Mhz CPU, while the ESP8266 has an 80Mhz single-core processor. Therefore, if your primary concern is processor speed, you should prioritize the ESP32 over the ESP8266.
- The ESP32 offers more GPIO than the ESP8266.
- ESP32 supports Bluetooth 4.2 and BLE. NS. Bluetooth Low Energy.
- The ESP32 offers a 12-bit ADC, while the ESP8266 offers only a 10-bit ADC.
- Besides the cost, the ESP32 has more features than ESP8266.
- 520 KB SRAM, 448 KB ROM, and 16 KB RTCS RAM.
- Supports 802.11b / g / n Wi-Fi connections at speeds up to 150Mbps.
- Supports both classic Bluetooth v4.2 and BLE specifications.
- 4 SPI channels.
- Two I2C interfaces.
- Two I2S interfaces (for digital audio).
- Up to 18 12-bit ADCs (analog-to-digital converters).
- Two 8-bit DACs (digital-to-analog converters).
- 10 capacitive touch switch sensors.
- Integrated Hall effect sensor.
- Ethernet MAC
- for physical LAN communication • Analog preamplifier with very low power consumption.
- Internal low dropout regulator.
- Three UARTs (Universal Asynchronous Receiver & Transmitter) for communication.
- Up to 8 IR remote control channels.
- Secure boot and flash encryption.
- Up to 16 channels of LED
- pulse width modulation (PWM).
Types of ESP32 modules
ESP32 modules are available for experimentation and application on the market. The most popular and widely available boards are the ESP32 DEVKIT and ESP32 Node MCU boards. The majority of accessible esp32 modules feature a built-in micro USB connector for programming, although some modules do not. In this situation, programming must be done with an external FTDI adaptor.
- ESP32 WROOM is the chip that most boards are based on.
Another popular module in the ESP32 family is the ESP32-CAM. An integrated miniature camcorder, a micro SD card slot, and an esp32 module make up the ESP 32 CAM. The programming of this module necessitates the use of an FTDI adaptor.
ESP32 DEVKIT V1
This is one of the most widely used esp32 modules. The esp32 board is made up of the following components:
- 30 GPIO Pins on the ESP-WROOM-32 Module
- AMS1117 Regulator IC (3.3V)
- Boot Button • Enable Button (Reset) (for flashing)
- LEDs with high output (Red)
- LED light for the user (Blue, which is connected to GPIO2)
- Micro USB Connector • CP2012 USB (UART Bridge IC) (for power and programming)
Let's have a look at this ESP32 Pinout in detail:
GPIO Pins in ESP32
GPIO (general purpose input/output) is the most frequent peripheral for esp32. Each of the 36 GPIO pins on the ESP32 performs numerous duties (only one function is active at a time). The ESP32 Dev Kit V1 includes 30 GPIO pins, though. Some esp32 modules have different numbers of GPIO pins. GPIOs, ADCs, and UARTs can all be assigned to each GPIO pin dynamically.
PWM Pins in ESP32
The ESP32's PWM controller has 16 independent PWM waveform channels with configurable frequency and duty cycles. PWM waveforms can be used to drive motors and LEDs. You can configure the frequency, channel, GPIO pin, and duty cycle of the PWM signal.
SPI Pins in ESP32
The ESP32 Wi-Fi chip has three SPI blocks i.e., SPI, HSPI, and VSPI in both master and slave modes. SPI is used as an interface to flash memory. Therefore, there are two SPI interfaces.
I2C Pins in ESP32
The ESP32 has two I2C interfaces for complete pinout flexibility. NS. The SCL and SDA pins of both I2C interfaces can be assigned by a user in the program. If you are using the Arduino IDE, the default I2C pins are:
ADC in ESP32
The ESP32 is equipped with two 12-bit SAR analog-to-digital converter modules, each with eight and ten channels. The 12-bit ADCs in the ADC1 and ADC2 blocks have a total of 18 channels. The digital output value ranges from 0 to 4093 at 12-bit resolution. The ADC (analog to digital) and DAC (digital to analog) pins are preset and must be utilized in accordance with the manufacturer's instructions. PWM, SPI, UART, and I2C are just some of the other functions that can be dynamically assigned to any GPIO pin.
The ESP32 microcontroller features two distinct 8-bit digital-to-analog converter channels for translating digital values to analog voltage signals. The DAC function is connected to the two GPIO pins below.
The DAC employs a power supply as an input reference voltage and features an internal resistance network.
GPIO pins with a capacitive touch
Ten capacitive sensing GPIOs on the ESP32 SoC become electrostatically charged when a finger or pen meets or approaches the GPIO pin. Without any additional hardware, these touch GPIOs can be utilized to make capacitive touchpads. Variations in capacitance are evident.
The RTC Low Power subsystem on the ESP32 contains 16 RTC GPIOs. As an external wake-up source, these pins can be utilized to wake up the ESP32 from a deep sleep.
Note: Most of the ESP32 pins have different functions, so not all pins can be used at the same time.
In order to program esp32 modules different programming environments are available like:
- Arduino IDE
- Espressif IDE
Code for programming ESP32 can be written either in C++ or Micropython. In our upcoming projects, we will be using Arduino IDE.
Programming ESP32 in Arduino IDE
To use the ESP32 with the Arduino IDE, you need to add the ESP32 board manager to the Arduino IDE. All we have to do is add the JSON file link. JSON is a format of text files that allow structured information to be shared between computers.
Installation of ESP32 Library in Arduino IDE
Steps to follow to install ESP32 Board Manager on Arduino IDE:
- Open Arduino IDE. Go for version 1.8 or above.
- Go to the ‘File’ menu on the top menu bar.
- Click on ‘Preferences’, this will open a preferences dialog box.
- Look for the textbox ‘Additional boards manager URL’ and add the following link in the box: https://dl.espressif.com/dl/package_esp32_index.json
- If there is already a link then add a comma (,) and then add the URL for the ESP32 board.
- Click "OK".
Now, the next step will be to Install the ESP32 board manager and the steps for that are:
- Click on the ‘Tool’ menu.
- Scroll down for the ‘Board’ option in the menu.
- A submenu will open when you highlight the ‘Board’.
- At the top of the submenu click on ‘Board Manager’.
- Search for ESP32 and install the board manager.
- You should see the entry "ESP32 by Espressif Systems".
- Close the board manager window once the installation is done.
- Once again go to the ‘Tool’ menu and highlight the ‘Board’ option and in the submenu, you will see a list of ESP32 boards.
- Look for the board which matches the board you have purchased.
- Here we will select ‘ESP32 DEV KIT V1’ as we are using the one.
Now finally, your Arduino IDE is ready to ‘Verify’ & ‘Upload’ a code into the ESP32 board.
Verify & Upload
Now that the Arduino IDE is ready to handle the ESP32 Dev Kit module, you can write the code for the ESP32 module. To verify and upload a code in the esp32 module:
- Write a code in the Arduino IDE.
- Click the ‘Verify’ option on the top menu bar to confirm the code.
- After checking for errors, if you find any errors, try red-bugging your code.
- Once the code has been validated without any error, continue with uploading the code.
- Click the Upload option on the top menu bar.
- Press the "BOOT" button on the ESP32 module.
That concludes today's discussion. We hope you found this post informative. We'll talk about developing a program with the esp32 and some peripheral interface in the following tutorial. If you have any questions, please ask in the comments.