#363 Which ESP32 pins are safe to use?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
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
Info
Channel: Andreas Spiess
Views: 65,813
Rating: 4.9851823 out of 5
Keywords: ESP32, hobby, diy, eevblog, greatscott, andreas spiess, project, how to, nodemcu, ttgo, wemos, internet, iot, internet of things, sensors, github, arduino, arduino project, esp32 project, esp8266 project, beginners, tutorial, esp8266, esp8266 datasheet, esp8266 tutorial, FET, FET tutorial, Field Effect Transistor, guide, hack, lora, lorawan, n-channel, npn, p-channel, pnp, simple, smart home, wifi, Raspberry Pi, Zoom, Microsoft, Teams, Home Assistant, Docker, ESP32 pins, esp32 deep sleep
Id: LY-1DHTxRAk
Channel Id: undefined
Length: 11min 52sec (712 seconds)
Published: Sun Nov 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.