Contact Us
Blog >> Blog Details Page

ESP32 Pinout: The Ultimate Guide

Posted:11:27 AM January 19, 2024 writer: Roland Pelayo

 

Introduction

The ESP32, developed by Espressif Systems, is a versatile microcontroller that has gained widespread popularity for its advanced features and extensive connectivity options. One of the critical aspects of harnessing the full potential of the ESP32 is understanding its pinout configuration. This article will delve into the intricacies of the ESP32 pinout, exploring various functionalities and applications.

ESP32 Main Features

Before diving into the pinout details, let's briefly highlight some key features of the ESP32:

  • Dual-core microcontroller with Wi-Fi and Bluetooth capabilities.
  • Low-power modes for energy-efficient operation.
  • Rich set of peripherals and interfaces.
  • Robust support for various communication protocols.

The ESP32 supports a variety of programming languages. The primary programming language for ESP32 development is C/C++, and it is typically programmed using the Arduino IDE or the ESP-IDF (Espressif IoT Development Framework), which is Espressif's official development framework for the ESP32.

Apart from C/C++, you can also use MicroPython and JavaScript (via Espruino) to program the ESP32. Here's a brief overview:

C/C++ with Arduino IDE or ESP-IDF - The Arduino IDE provides a user-friendly environment for programming the ESP32 using C/C++. Alternatively, you can use the ESP-IDF, which offers more advanced features and low-level control.

MicroPython - is a lightweight implementation of Python 3 for microcontrollers. It allows you to write Python code directly on the ESP32, providing a higher-level language for development.

Espruino -  is a JavaScript interpreter for microcontrollers, and it supports the ESP32. You can use the Espruino IDE or a text editor to write JavaScript code for your ESP32.

These programming languages offer flexibility, allowing developers to choose the one that best suits their preferences and project requirements. Remember that C/C++ is the most commonly used language for ESP32 development due to its efficiency and close integration with the hardware.

Free Components Worldwide Shipping

ESP32 Pinout

The ESP32 comes with a myriad of pins, each serving a specific purpose. The pinout is crucial for effective hardware design and interfacing with external devices.

ESP32 Pin Configuration Details

Digital Input GPIO Pins

The ESP32 offers a range of General-Purpose Input/Output (GPIO) pins, allowing digital signals to be read or output. These pins are crucial for interfacing with sensors, actuators, and other digital devices.

The ESP32 has 34 GPIO pins in total numbered GPIO0 to GPIO39. Some GPIO pins are not accessible to users because they serve a special function. Examples of these are GPIO20 and GPIO28 to GPIO31. Moreover, GPIO37 and GPIO38 are not accessible on the development board. Also, take note that, GPIOs 34, 35, 36, and 39 are input-only pins.

Interrupt Pins

Interrupt pins are essential for handling external events promptly. The ESP32 provides specific pins that can be configured to trigger interrupts, enabling efficient event-driven programming.

Except for GPIO6 to GPIO11, all GPIO pins of the ESP32 can be used as an external interrupt. This means any change of state in any of these pins can trigger an interrupt provided that the attachInterrupt() function in Arduino has been enabled.

Strapping GPIO Pins

Strapping pins play a vital role during the device's boot process. They help set various configuration options, such as boot mode and flash voltage. Proper utilization of strapping pins is crucial for configuring the ESP32 at startup.

The pins GPIO12, GPIO0, GPIO2, GPIO4, GPIO15 and GPIO5 are all strapping pins. Being such, users cannot make them HIGH or LOW normally through code. If you are using a development board, there is no need to worry about these pins as they have been automatically controlled via the USB-TTL chip.

Analog to Digital Converter or Analog GPIO Pins

Analog pins allow the ESP32 to read analog signals, making it suitable for applications requiring accurate analog measurements, such as sensor interfacing.

Unlike the Arduino UNO where analog pins are limited to 6, the ESP32 has 18 channels. You can view all the analog pins in the ESP32 pinout diagram above.

Digital to Analog Converter Pins

Digital to Analog Converter (DAC) pins enable the generation of analog output signals. This feature is valuable in applications like audio synthesis and precision control systems. The ESP32 has two DAC pins which are GPIO25 and GPIO26. 

ESP32 UART Pins

The UART pins facilitate serial communication, supporting data exchange between the ESP32 and other devices. This is particularly useful for communication with sensors, displays, and other peripherals.

The ESP32 development board contains three UART interfaces. The transmit and receive pins for UART0 are GPI01 and GPIO3 respectively. For  UART2, those pins are GPIO17 and GPIO16. The third interface, UART1 is reserved for USB-serial communication and is inaccessible to users.

Touch Sensor Pins of Devkit

The ESP32 Devkit includes touch-sensitive pins, enabling the implementation of touch interfaces. These pins are sensitive to touch and can be employed for various interactive applications. There are 10 GPIO pins for the touch sensor: GPIO4, GPIO0, GPIO2, GPIO15, GPIO13, GPIO12, GPIO14, GPIO27, GPIO33, and GPIO32. 

Memory Card Interfacing Pins

For storage expansion, the ESP32 supports memory card interfacing through specific pins, making it suitable for projects that require additional data storage. Memory card pins are those labeled with VSPI in the pinout diagram above.

PWM GPIO Pins

Pulse Width Modulation (PWM) pins are crucial for motor control and LED brightness modulation applications. The ESP32 offers a range of PWM pins for such purposes. The ESP32 has 16 PWM-capable pins. All of them are those that have wiggly lines in the pinout diagram above.

PWM Motor Control Feature 

The ESP32's PWM motor control feature allows precise control of motors, making it ideal for robotics and other motor-driven projects.

Here is an example code in C/C++ that controls a motor, connected to GPIO5 of the ESP32, via PWM.

const int motorPin = 5; // Example GPIO pin for motor control

void setup() {
  pinMode(motorPin, OUTPUT);
}

void loop() {
  // Vary the motor speed using PWM
  for (int dutyCycle = 0; dutyCycle <= 255; dutyCycle += 5) {
    analogWrite(motorPin, dutyCycle);
    delay(500); // Adjust the delay as needed
  }

  delay(1000); // Wait for a second

  for (int dutyCycle = 255; dutyCycle >= 0; dutyCycle -= 5) {
    analogWrite(motorPin, dutyCycle);
    delay(500); // Adjust the delay as needed
  }

  delay(1000); // Wait for a second
}

In this code, the motor speed gradually increases and decreases in a loop. You may need to adjust the GPIO pin number and the delays based on your specific motor and project requirements.

Here is another example PWM code using microPython for ESP32:

from machine import Pin, PWM
from time import sleep

motor_pin = 5  # Example GPIO pin for motor control

motor_pwm = PWM(Pin(motor_pin), freq=1000, duty=0)

def set_motor_speed(speed):
    motor_pwm.duty(speed)

def motor_demo():
    # Vary the motor speed using PWM
    for duty_cycle in range(0, 256, 5):
        set_motor_speed(duty_cycle)
        sleep(0.5# Adjust the delay as needed

    sleep(1# Wait for a second

    for duty_cycle in range(255, -1, -5):
        set_motor_speed(duty_cycle)
        sleep(0.5# Adjust the delay as needed

    sleep(1# Wait for a second

motor_demo()

I2C Communication Pins

Inter-Integrated Circuit (I2C) pins facilitate easy communication between the ESP32 and other I2C-compatible devices, enabling a seamless connection to sensors, displays, and more.

The default hardware I2C pins for the ESP32 are GPIO22 (SCL) and GPIO21 (SDA). If using software I2C, any digital I/O pin can be used. You just need to specify which pin during the initialization of the Wire object.

Wire.begin(SDA, SCL); //specify SDA and SCL pins here

For microPython, the syntax for SoftSPI is:

from machine import Pin, SoftI2C

i2c = SoftI2C(scl=Pin(5), sda=Pin(4), freq=100000)

Here, the assigned SCL pin is GPIO5 and the SDA pin is GPIO4.

SPI Pins

Serial Peripheral Interface (SPI) pins are vital for high-speed communication with devices like displays, flash memory, and other peripherals.

There are 4 SPI channels on the ESP32. Out of the four, only two are user accessible. These channels, referred to as HSPI and VSPI are mapped to I/O pins. The HSPI pins are GPIO13 (MOSI), GPIO12 (MISO), GPIO14 (SCLK), and GPIO15 (CS). For the VSPI, the pins are GPIO23 (MOSI), GPIO19 (MISO), GPIO18 (SCLK), and GPIO5 (CS).

In Arduino, the default SPI pins are those of VSPI. This means if you only do this,

SPI.begin(14, 12, 13, 15);

The pins are already mapped to GPIO23, GPIO19, GPIO18, and GPIO5. If you want to use the other SPI, then do

SPI.begin(14, 12, 13, 15);

You can also use the SPIClass to call whichever SPI channel you want. Here’s an example of using both SPI channels using SPIClass in the same code.

#include

SPIClass *vspi = NULL;
SPIClass *hspi = NULL;

void setup() {
  // Initialize two instances of the SPIClass attached to VSPI and HSPI respectively
  vspi = new SPIClass(VSPI);
  hspi = new SPIClass(HSPI);

  // Initialize the SPI bus using the default hardware SPI pins
  SPI.begin();

  // Your setup code here
}

void loop() {
  // Use vspi for VSPI communication
  vspi->begin();

  // Your VSPI code here

  vspi->end(); // End VSPI communication

  // Use hspi for HSPI communication
  hspi->begin();

  // Your HSPI code here

  hspi->end(); // End HSPI communication

  // Your main code here
}

 

Get Free PCB Assembly

RTC Pins of ESP32 Devkit

Real-Time Clock (RTC) pins are used for timekeeping functions. The ESP32 has dedicated pins to interface with an external RTC module. In the pinout diagram above, you can see which pins support RTC.

Hall Sensor Pin

The ESP32 features a Hall sensor, making it suitable for applications requiring proximity or magnetic field detection. The hall sensor is hidden behind the metal lif of the ESP32. The hall sensor pin, however, is inaccessible as it is internally wired. You can read the hall sensor value using the following code:

int val = 0;

void setup() {
  Serial.begin(9600);
}

// put your main code here, to run repeatedly
void loop() {
  // read hall effect sensor value
  val = hallRead();
  // print the results to the serial monitor
  Serial.println(val);
  delay(1000);
}

I2S (Inter-IC Sound)

I2S pins support high-quality audio communication, making the ESP32 suitable for audio applications like music playback and voice recognition.

As I2S output requires an analog signal, the DAC pins for the ESP32 can be used as I2S pins. If an external DAC is used, any available GPIO (digital) may be used for I2S applications.

Pulse Counter Module (PCNT)

The Pulse Counter Module allows counting pulses on specific pins, expanding the ESP32's capability for applications like event counting and speed measurement. All digital I/O pins can be assigned to a pulse counter module. 

Remote Control Module

The ESP32's remote control module enables Infrared (IR) communication, making it compatible with various remote control devices. Similar to PCNT, all digital I/O pins can be assigned to a remote control module.

Enable Pin

The enable pin is crucial for controlling the power supply to peripherals, allowing efficient power management.

The enable pin is the one labeled EN on the ESP32 development board. An EN button is also found near the microUSB port. Remember that when EN is pulled LOW, the ESP32 is disabled. When the EN pin is high or left as is, the ESP32 is enabled.

Automatically Resetting ESP32

Certain pins can be utilized to enable automatic resetting of the ESP32, providing a convenient way to restart the device. One pin is the previously discussed EN pin which when pulled LOW disables the ESP32. Another pin is GPIO0, one of the strapping pins. If IO0 is held low during power-up or reset, the ESP32 goes into bootloader mode, which is useful for flashing new firmware.

Here’s an example Arduino code that resets the ESP32 every 5 seconds:

void setup() {
  // Your setup code here
}

void loop() {
  // Trigger a reset
  resetESP32();
  delay(5000);  // Wait for 5 seconds before triggering another reset
}

void resetESP32() {
  // Set EN (RST) pin low to disable the ESP32
  digitalWrite(EN_PIN, LOW);
 
  // Optional delay to ensure stable low state
  delay(50);
 
  // Toggle IO0 to trigger a reset
  digitalWrite(IO0_PIN, HIGH);
  delay(50);
  digitalWrite(IO0_PIN, LOW);
 
  // Set EN (RST) pin high to enable the ESP32 again
  digitalWrite(EN_PIN, HIGH);
}

 

Get Instant PCB Online Quote

Conclusion

The ESP32's pinout is a roadmap to its vast capabilities. Effectively leveraging the diverse functionalities of its pins opens up a world of possibilities for embedded systems, IoT applications, and beyond. As you embark on your ESP32 projects, a solid understanding of the pinout configuration will be your guiding light, empowering you to unlock the full potential of this remarkable microcontroller.

You may also be interested in...

ESP32 BLE(Bluetooth Low Energy) Control in Arduino IDE

ESP32 as a Webserver

Free Worldwide Shipping on Over 600,000 Electronics Components with HQ Online

Free PCB Assembly Offer is Now Live: Experience Reliable PCB Assembly from HQ NextPCB

HQ NextPCB Introduces New PCB Gerber Viewer: HQDFM Online Lite Edition

  • PCB
    Prototype
  • PCB
    Assembly
  • SMD
    Stencil

Dimensions: (mm)

×

Quantity: (pcs)

5
5
10
15
20
25
30
40
50
75
100
120
150
200
250
300
350
400
450
500
600
700
800
900
1000
1500
2000
2500
3000
3500
4000
4500
5000
5500
6000
6500
7000
7500
8000
9000
10000

Other Quantities:(quantity*length*width is greater than 10㎡)

OK

Layers:

Thickness:

Quote now