#363 Which ESP32 pins are safe to use?

Andreas Spiess
29 Nov 202011:52

Summary

TLDRThis video offers an in-depth look at the ESP32 microcontroller, focusing on its pins and their specific functions. It provides a detailed overview of the 40 GPIO pins, highlighting which ones to use or avoid for various projects. The video also covers the importance of consulting the datasheet, handling strapping pins, and using pins for specific interfaces like I2C, SPI, and PWM. Additionally, it discusses advanced features like ADC inputs, DAC outputs, interrupts, and touch sensors. The host shares practical tips for pin selection to optimize project design and performance.

Takeaways

  • 😀 The ESP32 has 40 GPIO (General Purpose Input Output) pins, but not all are truly general purpose.
  • 🔍 GPIO pins 34 through 39 are actually GPI (General Purpose Input) pins and should not be used as output pins.
  • ⚠️ GPIO 34 and 35 are particularly dangerous if used for output without proper precautions.
  • 🔌 GPIO 6 to 11 are connected to an external flash memory chip and should be avoided unless you know what you are doing.
  • 🔄 GPIO 36 and 39 are typically labeled as sensor VP and sensor VN and have special functions.
  • 🚫 Strapping pins like GPIO0 and GPIO2 have functions during boot up and should be handled carefully to prevent boot issues.
  • 🔌 RX/TX pins (GPIO1 and 3) are commonly used for flashing and debugging and should not be altered.
  • 🔄 The ESP32 has two I2C interfaces, typically using GPIO21 and 22, which can be reconfigured to other pins if needed.
  • 🔄 Two SPI interfaces are available, with the third SPI bus used for the flash memory chip.
  • 🔌 GPIO 12 to 15 should be reserved for debugging purposes if using the inline debugger of PlatformIO.
  • 🔋 GPIO 34 through 39 can be used as ADC (Analog to Digital Converter) input pins, though the quality of the ADC results may not be excellent.
  • 🎵 The ESP32 has two 8-bit DAC (Digital to Analog Converter) outputs on GPIO 25 and 26, which are simple to program.

Q & A

  • What is the primary focus of the video script about the ESP32?

    -The primary focus of the video script is to explore the ESP32's pins, create a priority pin list, and provide insights on how to effectively use the ESP32's various pins for projects.

  • How many GPIO pins does the ESP32 have according to the datasheet?

    -According to the datasheet, the ESP32 has 40 GPIO pins numbered from GPIO0 to GPIO39.

  • Why are GPIO 34 through 39 not considered general purpose input output pins?

    -GPIO 34 through 39 should be called GPI pins because they cannot be used as output pins, and using them for output without caution can lead to confusion and wasted troubleshooting time.

  • What special function do GPIO 36 and 39 have in the ESP32?

    -GPIO 36 and 39 are usually labeled as sensor VP and sensor VN, indicating they have a special function, but the exact purpose is not detailed in the script.

  • Why are GPIO 6 to 11 not recommended for general use in ESP32 modules like the Vroom or the Vrover?

    -GPIO 6 to 11 are connected to an external flash memory chip used for data storage, making them 'forbidden' for general use unless the user knows exactly what they are doing.

  • What is the purpose of the strapping pins in the ESP32 during boot up?

    -Strapping pins have a function during boot up, and if wrongly connected, they can prevent the ESP32 from booting properly.

  • Why should GPIO0 and GPIO2 not be used for projects without a specific need?

    -GPIO0 and GPIO2 have hidden functions that are important during the boot process and firmware flashing. Using them without a specific need can lead to complications and difficulty in troubleshooting.

  • What are the standard pins used for the ESP32's I²C interface?

    -The standard pins used for the ESP32's I²C interface are GPIO21 and GPIO22, but they can be changed to most other GPIO pins using specific commands.

  • How many SPI interfaces does the ESP32 have, and which pins are used for them?

    -The ESP32 has two usable SPI interfaces that use different sets of pins. The standard libraries use the VSPI pins as shown in the SPI example sketch.

  • What is the purpose of the ADC pins on the ESP32, and are there any limitations when using them with Wi-Fi?

    -The ADC pins on the ESP32 are used for analog-to-digital conversion. However, all pins starting with ADC2 cannot be used if Wi-Fi is enabled, limiting the available ADC pins for use.

  • How can the ESP32's GPIO pins be used for PWM, and what is unique about its implementation compared to Arduino?

    -The ESP32 can use all GPIOs for PWM to control devices like servos or dim LEDs. Unlike Arduino, which uses 'analogWrite', the ESP32 requires defining the frequency and resolution of a channel before attaching it to a pin and writing to the channel.

  • What is the purpose of interrupts in the ESP32, and how flexible are they in terms of pin usage?

    -Interrupts allow an external signal to interrupt any running sketch, simplifying some projects. The ESP32 is flexible with interrupts, allowing the use of all pins for this purpose, although it is not very fast in handling interrupts.

  • What are the exotic usages of pins discussed in the script, and how many pins can be used for touch sensors?

    -The script discusses touch sensors and hall sensors as exotic usages of pins. Out of the 10 pins that can be used for touch sensors, 8 can be considered after excluding special pins.

Outlines

00:00

😎 Exploring ESP32's Pin Secrets and Prioritization

This paragraph introduces the ESP32 microcontroller, highlighting its extensive pin capabilities. The video aims to provide an overview of all ESP32 pins, focusing on their specific purposes and the importance of careful handling. The speaker emphasizes the need to consult the datasheet for accurate pin information and shares a strategy for utilizing the numerous pins in projects. The discussion includes the limitations of certain pins, such as GPIO 34-39, which are not suitable for output functions. Additionally, the paragraph touches on the use of strapping pins during boot-up and their potential to prevent the device from booting if connected incorrectly. The speaker also mentions the external flash memory chip connected to GPIO 6-11 and the need to avoid using these pins unless absolutely necessary.

05:01

🤖 Prioritizing ESP32 Pins for Project Use

This paragraph delves deeper into the prioritization of ESP32 pins for various project requirements. The speaker discusses the standard SPI and I2C interfaces, emphasizing the importance of reserving certain pins for these functions to avoid conflicts. The paragraph also addresses the need to reserve GPIO 12-15 for debugging purposes when using the inline debugger of PlatformIO. The speaker then explores the secondary functions of pins, such as ADC inputs, and suggests using GPIO 34-39 for these purposes while noting the limitations when using Wi-Fi. The paragraph further covers the use of GPIO 25 and 26 for 8-bit DAC outputs and the flexibility of using all GPIOs for PWM functions. The speaker also highlights the versatility of the ESP32 in handling interrupts and the use of RTC GPIO pins for waking the device from deep sleep. Finally, the paragraph touches on the exotic uses of pins, such as touch sensors and a hall sensor, and provides guidance on how to choose pins based on project needs.

10:02

🔍 Choosing Pins for ESP32 Projects

In this final paragraph, the speaker provides a summary of how to choose pins for ESP32 projects. The focus is on starting with a priority one list of pins and considering the use of GPIO 34-39 for analog input or wake-up functions if more pins are needed. The speaker advises sticking to standard I2C or SPI pins due to library constraints, especially from Arduino, which may not allow pin changes. The paragraph also mentions the flexibility of changing pins in PCB designs to ease the layout process. The speaker encourages viewers to share their insights and experiences in the comments and reminds them of the importance of supporting the channel for its continued existence.

Mindmap

Keywords

💡ESP32

ESP32 is a microcontroller with Wi-Fi and Bluetooth capabilities, known for its versatility and power. In the video, it's referred to as a 'beast' with 'secrets,' highlighting its complex features and capabilities. The script discusses the various pins and functionalities of the ESP32, emphasizing its extensive GPIO (General Purpose Input Output) pins.

💡GPIO Pins

GPIO stands for General Purpose Input Output, which are pins on a microcontroller used for various input and output functions. The video script discusses the ESP32's 40 GPIO pins, numbered from GPIO0 to GPIO39, and how not all of them are truly general purpose, with some having specific functions or restrictions.

💡Datasheet

A datasheet is a document that provides detailed information about a component, such as pin functions, electrical characteristics, and operating conditions. The script mentions consulting the ESP32 datasheet as the primary source of wisdom for understanding the chip's capabilities and pin functions.

💡Strapping Pins

Strapping pins are used during the boot-up process of a microcontroller and can affect its operation if not connected correctly. In the script, GPIO0 and GPIO2 are identified as strapping pins with specific boot functions, and the video advises caution when using them to avoid boot issues.

💡ADC Pins

ADC stands for Analog to Digital Converter, which is used to convert analog signals into digital values that a microcontroller can process. The video script explains that the ESP32 has several ADC pins, but not all can be used simultaneously with Wi-Fi, which is a common function of the ESP32.

💡DAC Outputs

DAC stands for Digital to Analog Converter, which converts digital signals into analog form. The script mentions that the ESP32 has two 8-bit DAC outputs on GPIO 25 and 26, which can be used to generate analog signals, such as for creating sine waves.

💡PWM

PWM stands for Pulse Width Modulation, a technique used to encode a message into a pulse signal whose duty cycle varies. In the context of the video, PWM is used to control devices like servos or dim LEDs by generating a square wave signal with a variable on/off ratio.

💡Interrupts

Interrupts are a feature of microcontrollers that allow external signals to temporarily halt the normal execution of the program. The video script discusses how all pins of the ESP32 can be used for interrupts, which can simplify programming by allowing for immediate responses to external events.

💡RTC GPIO Pins

RTC stands for Real-Time Clock, and RTC GPIO pins are used for waking up the microcontroller from deep sleep. The script mentions that GPIO34 through 39 can be used as RTC GPIO pins, which is a way to save the more versatile priority one pins for other uses.

💡Touch Sensors

The ESP32 has the capability to use certain pins as touch sensors, allowing for touch input without the need for external components. The script notes that 10 pins can be used for touch sensors, but after excluding special pins, 8 remain for this purpose.

💡Hole Sensor

The hole sensor is a less common feature of the ESP32, which can detect the presence of a magnet or metal. The video script describes it as an 'exotic' function, suggesting it may not be commonly used but is an interesting capability of the microcontroller.

Highlights

Overview of ESP32 pins and creation of a priority pin list for efficiency.

Introduction to the unique functions of specific ESP32 pins.

Explanation of general-purpose input-output (GPIO) pins and their numbering.

Discussion on non-existent GPIO pins and their impact on usage.

Distinction between true GPIO pins and those with restricted functions.

Identification of pins connected to external flash memory and their restrictions.

Introduction to strapping pins and their role during boot-up.

Highlighting the hidden functions of GPIO0, GPIO2, GPIO5, and GPIO15.

Insight on development board pins used for flashing and debugging.

Explanation of I2C interfaces and their standard pins.

Overview of SPI interfaces and their standard pins.

Details on pins used for debugging sketches in PlatformIO.

Discussion on secondary functions of pins, such as ADC inputs and DAC outputs.

Introduction to PWM and its usage across all GPIO pins.

Explanation of interrupts and their application on ESP32 pins.

Introduction to RTC GPIO pins for waking the ESP32 from deep sleep.

Overview of exotic functions like touch sensors and the hall sensor.

Recommendations on choosing pins for various project requirements.

Emphasis on using standard I2C and SPI pins for compatibility with libraries.

Encouragement to experiment with interrupts to simplify sketches.

Transcripts

play00:00

the esp32 is a beast with some secrets

play00:04

today we will look at its pins and

play00:07

create a priority pin list which saves

play00:10

you a lot of time and hassle

play00:12

crazy youtubers here is the guy with the

play00:15

swiss accent with a new episode and

play00:18

fresh ideas around sensors and

play00:20

microcontrollers

play00:21

remember if you subscribe you will

play00:24

always sit in the first row

play00:27

in this video we will get an overview of

play00:30

all pins of the esp32

play00:33

learn which pins have particular

play00:35

purposes and therefore have to be

play00:38

treated with care

play00:40

learn the real universally usable prints

play00:43

create a strategy on how to use the many

play00:46

pins for our projects

play00:48

and do some programming examples

play00:51

the most important source of wisdom for

play00:54

parts always is the datasheet if we

play00:57

consult the esp32 datasheet it looks

play01:01

like the chip has 40 gpio pins

play01:04

numbered from

play01:06

gpio0 to gpio39

play01:10

gpio by the way

play01:12

means general purpose input output pins

play01:16

i copied this overview sheet into excel

play01:20

like that we can filter and sort it as

play01:23

we wish

play01:24

of course you find a link to it in the

play01:27

description

play01:28

if we have a close look we see that only

play01:31

32 pins are labeled gpio

play01:35

gpio 20 24 28 through 31

play01:40

37 and 38 do not exist

play01:44

please don't ask me why

play01:46

but still 32 is a lot compared with the

play01:50

esp8266

play01:52

or the arduino uno

play01:54

the next surprise

play01:56

not all those pins are general purpose

play01:59

as the name implies

play02:01

gpio 34 through 39 should be called gpi

play02:06

pins

play02:07

they cannot be used as output pins

play02:10

mostly 34 and 35 are dangerous if you do

play02:14

not pay attention and try to use them

play02:17

for output

play02:18

no warning will pop up and after hours

play02:21

you think you are stupid

play02:24

gpio 36 and 39 usually are labeled as

play02:28

sensor vp and sensor vn

play02:32

we will later see that they have a

play02:34

special function

play02:36

so there are 28 true gpio pins left

play02:41

esp32 modules like the vroom or the

play02:45

vrover use an external flash memory chip

play02:48

to store data so gpio 6 to 11 are

play02:53

connected to this flash chip and are

play02:55

forbidden for us unless you exactly know

play02:58

what you do

play02:59

still 22 potentially true gpio pins are

play03:04

left

play03:05

next are the so called strapping pins

play03:08

they have a function during boot up and

play03:11

if wrongly connected prevent your esp32

play03:14

from booting

play03:16

gpio0 is well known to us

play03:19

sometimes we have to press a boot button

play03:22

which tells the chip that we want to

play03:24

flash a new firmware

play03:26

definitely not a general purpose pin

play03:30

we should not use it unless we

play03:32

absolutely need it

play03:33

and then make sure it is always high

play03:36

during boot

play03:37

gpio2 also has a hidden function if you

play03:41

pull it high during boot you are not

play03:44

able to flash new content

play03:46

also here you will search for the error

play03:49

for a long time

play03:51

gpio5

play03:52

also seems to have a function but i did

play03:55

not see a disadvantage by pulling it low

play03:58

or high

play03:59

other than the mtdo or gpio15

play04:04

if you pull this pin low

play04:06

the esp32 does not show the lock anymore

play04:10

at bootup

play04:11

if you do not know it you probably will

play04:14

search for a problem which in reality is

play04:17

none

play04:18

gpio0 and gpio2 should not be used for

play04:22

projects without need

play04:24

20 pins are left

play04:27

most development boards use rxtx for

play04:30

flashing and debugging

play04:32

these are gpio1 and 3.

play04:35

we should not touch them too

play04:38

18 pins left

play04:39

often we need an i-square-c interface

play04:43

the esp32 has two such interfaces

play04:46

because we can attach up to 112 sensors

play04:49

to one connection

play04:51

we usually only need one

play04:53

the standard pins are

play04:56

gpio2122

play04:58

and can be changed with this command to

play05:01

most other gpio pins

play05:03

for this place for example the fast spi

play05:06

interface is the right choice

play05:09

the esp32 has two usable spi interfaces

play05:13

that use the following pins

play05:16

the third spi bus is used for the flash

play05:19

memory chip by the way

play05:21

standard libraries use the vspi pins as

play05:25

shown in the spi example sketch

play05:28

because many sensors offer an isquare-c

play05:31

interface i usually do not use these two

play05:34

pins for other purposes

play05:37

16 pins left

play05:39

if you plan to debug your sketch using

play05:42

the inline debugger of platform io you

play05:44

have to spare gpio 12 to 15 out for your

play05:49

project

play05:50

12 pins left this is my priority one

play05:54

pins list

play05:55

i always start to use these pins

play05:58

only on pcb layouts it might be handy to

play06:01

use other pins

play06:03

or if you really need a lot of pins

play06:06

then you can use the flexibility of the

play06:08

esp32 to change pins for functions like

play06:12

i square c serial or spi

play06:15

next we have a look at the secondary

play06:18

function of pins for example the

play06:21

datasheet shows us many adc pins

play06:25

unfortunately all pins starting with adc

play06:28

2 cannot be used if we use wifi

play06:32

and who is not using wi-fi with the

play06:35

esp32

play06:36

a good thing

play06:38

gpio 34 through 39 can be used as adc

play06:42

input pins

play06:44

my preferred solution to relieve my

play06:46

priority 1 pin list

play06:49

just keep in mind the esp32 adc results

play06:53

are not excellent as shown in video

play06:56

number 340

play06:58

but good enough to measure battery

play07:00

voltage for example you can easily add

play07:03

two resistors and monitor a 4.2 volts

play07:06

lighon battery

play07:08

the esp-32 also has two 8-bit dac

play07:12

outputs

play07:13

on gpio 25 and 26

play07:17

they are very simple to program

play07:19

just use this command

play07:22

and the results are ok as we see here

play07:27

we can also create sine waves for

play07:29

example with this function

play07:31

next comes pwm

play07:33

in this mode pins generate a square wave

play07:36

signal with a variable on off ratio

play07:40

such signals are used to control servos

play07:42

for example or dim leds

play07:46

fortunately we can use all gpios for pwm

play07:51

just a curiosity

play07:53

the esp32 never got the same

play07:56

implementation as the arduino where

play07:58

analog write

play08:00

is used

play08:01

also not the best choice if you ask me

play08:04

but the esp32 implementation is even

play08:08

more adventurous

play08:09

it seems that somebody wrote a function

play08:12

to dim leds and then it stayed like that

play08:16

first we have to define the frequency

play08:18

and the resolution of a channel

play08:21

then we have to attach this channel to a

play08:23

pin

play08:24

after that we can start to write to this

play08:28

channel

play08:29

as we see here the esp32 can create

play08:32

relatively high frequencies which might

play08:34

be interesting for some projects

play08:37

anyway these were the typical usages of

play08:40

gpio pins in projects with one exception

play08:44

interrupts

play08:45

interrupts are a great functionality of

play08:48

most mcus

play08:50

we can interrupt any running sketch with

play08:52

an external signal which can drastically

play08:55

simplify some sketches

play08:57

as we saw in video number 328 the esp32

play09:01

is not very fast in this discipline but

play09:04

we can use all pins for that purpose

play09:07

very flexible

play09:09

if you never used it i strongly suggest

play09:11

trying interrupts at least once

play09:14

if we want to use an interrupt pin to

play09:16

wake the esp32 from deep sleep we have

play09:19

to use so called rtc gpio pins

play09:24

here we see like with the adcs that we

play09:27

can use

play09:28

gpio34 through 39 to save our priority

play09:32

one pins

play09:34

now we definitely come to the exotic

play09:36

usages of pins

play09:38

the first being touch sensors

play09:40

10 pins can be used for that purpose

play09:43

if we exclude the special pins we still

play09:46

get 8 pins

play09:48

so far i had no projects with them i

play09:51

only played around

play09:53

maybe you know of cool projects using

play09:55

these pins

play09:57

and the last even more exotic function

play10:00

is a hole sensor

play10:02

here i have no idea why it is built in

play10:06

definitely a solution on the search for

play10:08

a problem because even strong magnets do

play10:11

not influence the whole sensor over

play10:13

distance

play10:15

so i prefer to use such a small hole

play10:17

sensor chip that can be mounted where

play10:20

the action is and keep the esp32 away in

play10:24

a safe case

play10:25

just in case you want to use this hole

play10:28

sensor it is connected to gpio36

play10:31

and 39

play10:33

you must leave these pins open if you

play10:35

want to use the sensor

play10:37

that's it

play10:38

the last remaining question is

play10:41

how do i choose the pins

play10:44

i start with my priority one list

play10:47

if i expect that they will not be

play10:49

sufficient i use the gpi pins for analog

play10:53

input or wake up

play10:55

i try to stick with the standard i

play10:57

square c or spi pins as some libraries

play11:01

do not allow to change pins

play11:03

especially libraries coming from the

play11:05

arduino only use wire begin which use

play11:09

standard pins

play11:11

only in rare cases i switch standard

play11:13

pins

play11:14

for example if i need three serial

play11:17

connections standard serial one pins are

play11:20

mapped to pins used by the flash chips

play11:23

if i design pcbs i sometimes use the

play11:26

flexibility of changing pins to ease the

play11:29

design

play11:30

those are my two synths i'm sure you

play11:33

have a lot to add in the comments

play11:36

as always you find all the relevant

play11:38

links in the description

play11:40

i hope this video was useful or at least

play11:43

interesting for you if true please

play11:45

consider supporting the channel to

play11:47

secure its future existence thank you

play11:50

bye

Rate This

5.0 / 5 (0 votes)

関連タグ
ESP32MicrocontrollersGPIO PinsProgrammingSensorsEmbedded SystemsElectronicsDIY ProjectsTech TipsYouTube
英語で要約が必要ですか?