#363 Which ESP32 pins are safe to use?
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
😎 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.
🤖 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.
🔍 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
💡GPIO Pins
💡Datasheet
💡Strapping Pins
💡ADC Pins
💡DAC Outputs
💡PWM
💡Interrupts
💡RTC GPIO Pins
💡Touch Sensors
💡Hole Sensor
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
the esp32 is a beast with some secrets
today we will look at its pins and
create a priority pin list which saves
you a lot of time and hassle
crazy youtubers here is the guy with the
swiss accent with a new episode and
fresh ideas around sensors and
microcontrollers
remember if you subscribe you will
always sit in the first row
in this video we will get an overview of
all pins of the esp32
learn which pins have particular
purposes and therefore have to be
treated with care
learn the real universally usable prints
create a strategy on how to use the many
pins for our projects
and do some programming examples
the most important source of wisdom for
parts always is the datasheet if we
consult the esp32 datasheet it looks
like the chip has 40 gpio pins
numbered from
gpio0 to gpio39
gpio by the way
means general purpose input output pins
i copied this overview sheet into excel
like that we can filter and sort it as
we wish
of course you find a link to it in the
description
if we have a close look we see that only
32 pins are labeled gpio
gpio 20 24 28 through 31
37 and 38 do not exist
please don't ask me why
but still 32 is a lot compared with the
esp8266
or the arduino uno
the next surprise
not all those pins are general purpose
as the name implies
gpio 34 through 39 should be called gpi
pins
they cannot be used as output pins
mostly 34 and 35 are dangerous if you do
not pay attention and try to use them
for output
no warning will pop up and after hours
you think you are stupid
gpio 36 and 39 usually are labeled as
sensor vp and sensor vn
we will later see that they have a
special function
so there are 28 true gpio pins left
esp32 modules like the vroom or the
vrover use an external flash memory chip
to store data so gpio 6 to 11 are
connected to this flash chip and are
forbidden for us unless you exactly know
what you do
still 22 potentially true gpio pins are
left
next are the so called strapping pins
they have a function during boot up and
if wrongly connected prevent your esp32
from booting
gpio0 is well known to us
sometimes we have to press a boot button
which tells the chip that we want to
flash a new firmware
definitely not a general purpose pin
we should not use it unless we
absolutely need it
and then make sure it is always high
during boot
gpio2 also has a hidden function if you
pull it high during boot you are not
able to flash new content
also here you will search for the error
for a long time
gpio5
also seems to have a function but i did
not see a disadvantage by pulling it low
or high
other than the mtdo or gpio15
if you pull this pin low
the esp32 does not show the lock anymore
at bootup
if you do not know it you probably will
search for a problem which in reality is
none
gpio0 and gpio2 should not be used for
projects without need
20 pins are left
most development boards use rxtx for
flashing and debugging
these are gpio1 and 3.
we should not touch them too
18 pins left
often we need an i-square-c interface
the esp32 has two such interfaces
because we can attach up to 112 sensors
to one connection
we usually only need one
the standard pins are
gpio2122
and can be changed with this command to
most other gpio pins
for this place for example the fast spi
interface is the right choice
the esp32 has two usable spi interfaces
that use the following pins
the third spi bus is used for the flash
memory chip by the way
standard libraries use the vspi pins as
shown in the spi example sketch
because many sensors offer an isquare-c
interface i usually do not use these two
pins for other purposes
16 pins left
if you plan to debug your sketch using
the inline debugger of platform io you
have to spare gpio 12 to 15 out for your
project
12 pins left this is my priority one
pins list
i always start to use these pins
only on pcb layouts it might be handy to
use other pins
or if you really need a lot of pins
then you can use the flexibility of the
esp32 to change pins for functions like
i square c serial or spi
next we have a look at the secondary
function of pins for example the
datasheet shows us many adc pins
unfortunately all pins starting with adc
2 cannot be used if we use wifi
and who is not using wi-fi with the
esp32
a good thing
gpio 34 through 39 can be used as adc
input pins
my preferred solution to relieve my
priority 1 pin list
just keep in mind the esp32 adc results
are not excellent as shown in video
number 340
but good enough to measure battery
voltage for example you can easily add
two resistors and monitor a 4.2 volts
lighon battery
the esp-32 also has two 8-bit dac
outputs
on gpio 25 and 26
they are very simple to program
just use this command
and the results are ok as we see here
we can also create sine waves for
example with this function
next comes pwm
in this mode pins generate a square wave
signal with a variable on off ratio
such signals are used to control servos
for example or dim leds
fortunately we can use all gpios for pwm
just a curiosity
the esp32 never got the same
implementation as the arduino where
analog write
is used
also not the best choice if you ask me
but the esp32 implementation is even
more adventurous
it seems that somebody wrote a function
to dim leds and then it stayed like that
first we have to define the frequency
and the resolution of a channel
then we have to attach this channel to a
pin
after that we can start to write to this
channel
as we see here the esp32 can create
relatively high frequencies which might
be interesting for some projects
anyway these were the typical usages of
gpio pins in projects with one exception
interrupts
interrupts are a great functionality of
most mcus
we can interrupt any running sketch with
an external signal which can drastically
simplify some sketches
as we saw in video number 328 the esp32
is not very fast in this discipline but
we can use all pins for that purpose
very flexible
if you never used it i strongly suggest
trying interrupts at least once
if we want to use an interrupt pin to
wake the esp32 from deep sleep we have
to use so called rtc gpio pins
here we see like with the adcs that we
can use
gpio34 through 39 to save our priority
one pins
now we definitely come to the exotic
usages of pins
the first being touch sensors
10 pins can be used for that purpose
if we exclude the special pins we still
get 8 pins
so far i had no projects with them i
only played around
maybe you know of cool projects using
these pins
and the last even more exotic function
is a hole sensor
here i have no idea why it is built in
definitely a solution on the search for
a problem because even strong magnets do
not influence the whole sensor over
distance
so i prefer to use such a small hole
sensor chip that can be mounted where
the action is and keep the esp32 away in
a safe case
just in case you want to use this hole
sensor it is connected to gpio36
and 39
you must leave these pins open if you
want to use the sensor
that's it
the last remaining question is
how do i choose the pins
i start with my priority one list
if i expect that they will not be
sufficient i use the gpi pins for analog
input or wake up
i try to stick with the standard i
square c or spi pins as some libraries
do not allow to change pins
especially libraries coming from the
arduino only use wire begin which use
standard pins
only in rare cases i switch standard
pins
for example if i need three serial
connections standard serial one pins are
mapped to pins used by the flash chips
if i design pcbs i sometimes use the
flexibility of changing pins to ease the
design
those are my two synths i'm sure you
have a lot to add in the comments
as always you find all the relevant
links in the description
i hope this video was useful or at least
interesting for you if true please
consider supporting the channel to
secure its future existence thank you
bye
Weitere ähnliche Videos ansehen
5.0 / 5 (0 votes)