ESP32 Module Pinout
ESP32 Module Pinout
ESP32 Development Board Pinout
Important to note upfront, it is not recommended to use the following pins when using the ESP32, as they may cause various unsolvable issues in your project.
Pins Not Recommended or Restricted for Use
It is not recommended to use Strapping pins, SPI flash pins, and input-only pins.
Strapping Pins
GPIO 0 GPIO 2 GPIO 4 GPIO 5 (must be high during startup) GPIO 12 (must be low during startup) GPIO 15 (must be high during startup)
Note:
When using external modules, ensure that GPIO12 is not pulled high, as this will cause the ESP32 to fail to start. Additionally, some GPIOs change their state to high or output PWM signals during startup or reset, so take care when using them.
SPI flash pins integrated in ESP-WROOM-32
GPIO 6 to GPIO 11 are exposed on some ESP32 development boards. However, these pins are connected to the integrated SPI flash on the ESP-WROOM-32 chip and are not recommended for other uses. Therefore, do not use these pins in your project:
GPIO 6 (SCK/CLK)
GPIO 7 (SDO/SD0)
GPIO 8 (SDI/SD1)
GPIO 9 (SHD/SD2)
GPIO 10 (SWP/SD3)
GPIO 11 (CSC/CMD)
Input-only pins
GPIO 34 to GPIO 39 are GPIO – input-only pins. These pins do not have internal pull-up or pull-down resistors. They cannot be used as outputs, so they can only be used as inputs:
GPIO 34
GPIO 35
GPIO 36
GPIO 39
These pins are used for the bootloader or for flashing mode/on most built-in USB/Serial development boards, you don’t need to worry about the state of these pins, the development board will set them to the correct state to use flashing or boot mode.
Note:
If you have external modules connected to these pins, you may encounter trouble when trying to upload new code, flash the ESP32 with a new firmware, or reset the board, for example, mysterious errors and failures. It may be because these external modules prevent the ESP32 from entering the correct mode.
So, these pins are not recommended to be used in your project.
Now, let’s start to introduce the pins of ESP32.
ESP32 Peripherals:
- 18 ADC channels
- 4 SPI interfaces
- 3 UART interfaces
- 1 I2C interface
- 16 PWM outputs
- 2 DACs
- 2 I2S interfaces
- 10 capacitive sensing GPIOs
- 16 RTC GPIOs
- 2 built-in Hall sensors in ESP32
18 ADC channels
ESP32 has 18 x 12-bit ADC input channels (while ESP8266 only has 1x 10-bit ADC). These are the GPIOs that can be used as ADC and corresponding channels:
Unlike some digital peripherals (PWM, software SPI, and I2C), ADC pins are fixed, meaning you must use the predefined GPIO pins with ADC functionality and cannot configure them in software. However, you must be aware of some limitations.
Although ESP32 has 18 ADC channels, not all ADC pins are available to users. In the 8 ADC1 channels, only 6 are available (ACD1_CH0 and ACD1_CH3 to ACD1_CH7), while ADC1_CH1 and ADC1_CH2 are not available (even if the pins are not exposed on the ESP32 development board).
When using ADC2, it gets a bit more complex. When you use ESP32’s Wi-Fi, the Wi-Fi Driver uses the ADC2 Peripheral. Therefore, only ADC2 can be used when the Wi-Fi driver is not started.
Even if you are using ADC2 (assuming Wi-Fi is not used), not all pins are always available because some pins related to ADC2 are used for other important purposes (bootstrapping).
ADC Channel | Pin Name | GPIO Pin | Notes |
---|---|---|---|
ACD1_CH0 | A0 | 36 | Available / Built-in Hall sensor |
ACD1_CH1 | \ | 37 | Not available |
ACD1_CH2 | \ | 38 | Not available |
ACD1_CH3 | A3 | 39 | Available / Built-in Hall sensor |
ACD1_CH4 | A4 | 32 | Available |
ACD1_CH5 | A5 | 33 | Available |
ACD1_CH6 | A6 | 34 | Available |
ACD1_CH7 | A7 | 35 | Available |
ACD2_CH0 | A10 | 4 | Not available when starting WIFI |
ACD2_CH1 | A11 | 0 | Not available / Used for BOOT Strapping |
ACD2_CH2 | A12 | 2 | Used for BOOT Strapping |
ACD2_CH3 | A13 | 15 | Used for BOOT Strapping |
ACD2_CH4 | A14 | 13 | Not available when starting WIFI |
ACD2_CH5 | A15 | 12 | Not available when starting WIFI |
ACD2_CH6 | A16 | 14 | Not available when starting WIFI |
ACD2_CH7 | A17 | 27 | Not available when starting WIFI |
ACD2_CH8 | A18 | 25 | Not available when starting WIFI |
ACD2_CH9 | A19 | 26 | Not available when starting WIFI |
ADC input channels have 12-bit resolution. This means you can get analog readings ranging from 0 to 4095, where 0 corresponds to 0V and 4095 corresponds to 3.3V. You can also set the resolution of the channel on the code and ADC range.
ESP32 ADC pins do not have linear behavior. You may not be able to distinguish between 0 and 0.1V, or 3.2 and 3.3V. Keep this in mind when using ADC pins. You will get behavior similar to the one shown in the following figure.
4 SPI interfaces
The default SPI pin mapping that can be used is:
SPI | MOSI | MISO | CLK | CS |
---|---|---|---|---|
VSPI(SPI3) | GPIO 23 | GPIO 19 | GPIO 18 | GPIO 5 |
HSPI(SPI2) | GPIO 13 | GPIO 12 | GPIO 14 | GPIO 15 |
SPI(Serial Peripheral Interface) protocol is a communication protocol proposed by Motorola, which is a high-speed full-duplex communication bus. It is widely used in ADC, LCD, etc. devices and MCUs, and requires high communication rates.
The pins on the chip only occupy four lines. MISO: The main device data output, the slave device data input. MOSI: The main device data input, the slave device data output. SCK: Clock signal, controlled by the main device. NSS (CS): Slave device selection signal, controlled by the main device. When NSS is low, the slave device is selected.
ESP32 integrates 4 SPI
peripherals.
SPI0
andSPI1
are used internally to access the flash connected to ESP32. Two controllers share the same SPI bus signals and have an arbiter to determine which one can access the bus.SPI2
andSPI3
are general SPI controllers, sometimes referred to as HSPI and VSPI. They are open to users. SPI2 and SPI3 have independent bus signals and are named the same. Each bus has 3 CS lines, and can control up to 6 SPI slave devices.
Note:
HSPI and VSPI are not high-speed SPI and Very High-speed SPI as believed by some users. This is just a different name for SPI and HSPI, VSPI is the same as SPI3.
I2C Communication Protocol
ESP32 default I2C pins are:
- GPIO 21 (SDA)
- GPIO 22 (SCL)
In ESP32, any pin can be defined as SDA or SCL, but it is not recommended unless absolutely necessary.
You can use the following statements in the Arduino IDE to configure other pins as SDA or SCL
1 | Wire.begin(SDA, SCL); |
PWM
ESP32 PWM controller is mainly designed for controlling the intensity of LEDs, but it can also be used to generate PWM signals for other purposes. It has 16 channels and can produce independent PWM waveforms.
The ESP32 PWM controller has 8 high-speed channels and 8 low-speed channels, giving us a total of 16 channels. They are divided into two groups based on speed. Each group has 4 timers/8 channels. This means that each pair of channels shares the same timer. Therefore, we cannot independently control the PWM frequency of each pair of channels.
All pins that can be used as output can be used as PWM pins (GPIO 34 to 39 cannot generate PWM).
To set up a PWM signal, you need to define these parameters in your code:
- Signal frequency;
- Duty cycle;
- PWM channel;
- GPIO that outputs the signal.
Digital to Analog Converter (DAC)
ESP32 has 2 x 8-bit DAC channels for converting digital signals to analog voltage signals. These are the DAC channels:
- DAC1 (GPIO25)
- DAC2 (GPIO26)
I2S High-speed Digital Audio Transmission Standard Protocol
On the ESP32 pins, DAC1 and DAC2 are actually marked.
- GPIO 25
- GPIO 26
Capacitive Touch GPIO
ESP32 has 10 internal capacitive touch sensors. They can sense any changes in charged objects, such as human skin. Therefore, they can detect changes caused by touching the GPIO with a finger. These pins can be easily integrated into capacitive pads and replace mechanical buttons. Capacitive touch pins can also be used to wake ESP32 from deep sleep.
These internal touch sensors are connected to these GPIOs:
- T0 (GPIO 4)
- T1 (GPIO 0)
- T2 (GPIO 2)
- T3 (GPIO 15)
- T4 (GPIO 13)
- T5 (GPIO 12)
- T6 (GPIO 14)
- T7 (GPIO 27)
- T8 (GPIO 33)
- T9 (GPIO 32)
RTC GPIO
ESP32 has RTC GPIO support. When ESP32 is in deep sleep, the GPIOs routed to the RTC low-power subsystem can be used. When the ultra-low-power (ULP) co-processor is running, these RTC GPIOs can be used to wake ESP32 from deep sleep. The following GPIOs can be used as external wake-up sources:
- RTC_GPIO0 (GPIO36)
- RTC_GPIO3 (GPIO39)
- RTC_GPIO4 (GPIO34)
- RTC_GPIO5 (GPIO35)
- RTC_GPIO6 (GPIO25)
- RTC_GPIO7 (GPIO26)
- RTC_GPIO8 (GPIO33)
- RTC_GPIO9 (GPIO32)
- RTC_GPIO10 (GPIO4)
- RTC_GPIO11 (GPIO0)
- RTC_GPIO12 (GPIO2)
- RTC_GPIO13 (GPIO15)
- RTC_GPIO14 (GPIO13)
- RTC_GPIO15 (GPIO12)
- RTC_GPIO16 (GPIO14)
- RTC_GPIO17 (GPIO27)
Interrupt
All GPIOs can be configured as interrupts.
Enable (EN)
EN is the enable pin for the 3.3V regulator. It is pulled high, so grounding it disables the 3.3V regulator. For example, this means you can use this pin connected to a button to reset ESP32.
GPIO Current Consumption
According to the “Recommended Operating Conditions” section in the ESP32 datasheet, the absolute maximum current consumption per GPIO is 40mA.
ESP32 Built-in Hall Effect Sensor
ESP32 also has a built-in Hall effect sensor that can detect changes in the surrounding magnetic field.
- GPIO 36
- GPIO 39
References for this article:
https://randomnerdtutorials.com/esp32-pinout-reference-gpios/
https://deepbluembedded.com/esp32-pwm-tutorial-examples-analogwrite-arduino/