How To: Pick the right pins on the NodeMCU ESP8266 and ESP32

July 25, 2018

Picking your pins on the ESP8266 and ESP32

Today on the hookup we’re going to explore some of the quirks of the different pins on both the ESP8266 and ESP32 based nodeMCUs.

Straight to the point! If you’re using an ESP8266 based nodeMCU here are the best pins to use for your general purpose input output needs.  If you’re using the ESP32 based nodeMCU these pins are the best pins for general purpose input output.  Diagrams of each of the boards with important details about each pin can be found in the video description.  To see how I determined which pins are the best keep watching.

First of all, I have to admit, I’m mostly making this video for myself.  I can’t tell you how many times during a project I’ve troubleshooted my code searching for my mistake only to find the issue was due to some undocumented, or poorly documented quirk of the nodeMCU.  In this video we’re going to talk about the different quirks of each of the pins on ESP8266 and ESP32 based NodeMCUs and help you pick the best pins for your specific application.

While we’re talking about pins, it’s important to know that the raw pin order on the nodemcu doesn’t match up with the descriptions written on the board.  For instance D1 on the ESP8266 based nodemcu is actually GPIO 5, so if you were to type pinMode(1, OUTPUT), you wouldn’t be assigning pin D1.  In order to use D1 you need to type pinMode(5, OUTPUT) or pinMode(D1, OUTPUT), assuming that you have the definition file for the nodeMCU’s pins installed in Arduino.  On my diagrams the raw pin orders are listed, so you’ll use the numbers listed in the bubbles, not on the board.

The most common source of irritation in my projects is that the nodeMCU can be prevented from booting if certain pins are grounded (which we call pulling them low) or exposed to voltage (which we call pulling them high) during the boot process.  To explore which pins have this characteristic, I loaded up a simple sketch with a serial monitor, wifi, mqtt, and a single output pin. I then hooked a female to female jumper wire to and tested each channel while watching the serial monitor for boot progress.  I then repeated the same process connecting each pin to the 3.3v pin instead of ground.  Using this method I was able to determine the specific boot requirements of each GPIO pin.

The second problem that I used to constantly troubleshoot has to do with pins that go high (which means they output 3.3V) during the booting process.  When using these pins as outputs connected to relays, transistors, or optoisolators this will cause them to fire for a short period of time.  This was especially jarring when the relay was connected to our alarm siren which would chirp for about half a second any time the nodeMCU rebooted due to an MQTT reconnection.  To test this I hooked up a 3.3V relay and wrote a sketch that reboots after setting itself up correctly.  I then tested every pin and noted which ones triggered the relay.  A few of the pins on the ESP32 output about 1V for a short period of time during the boot process,  But it wasn’t enough voltage to trigger my relay so I didn’t include it on the chart.  If you were using a transistor with a low threshold voltage it could still cause issues, so be aware of that.

I’m going to keep this video short and focused solely on choosing the right GPIO pins, or more specifically avoiding picking the wrong ones.  I hope the diagrams I have provided will be useful when you are making your next project using a NodeMCU.  If you enjoyed this video please consider subscribing, and as always, thanks for watching the hookup.

Video Description

ESP8266 NodeMCU Pin Diagram: https://github.com/thehookup/Wireless_MQTT_Doorbell/blob/master/GPIO_Limitations_ESP8266_NodeMCU.jpg

ESP32 NodeMCU Pin Diagram: https://github.com/thehookup/ESP32_Ceiling_Light/blob/master/GPIO_Limitations_ESP32_NodeMCU.jpg

The ESP32 Pins Outputting a PWM signal at startup that had duty cycles low enough that they didn’t trigger the relay were: P14, P5, P0, P15, P8, P7, and P6.

Buy an ESP8266 NodeMCU: https://amzn.to/2K0hgjS
Buy an ESP32 NodeMCU: https://amzn.to/2JVgEvx

Follow me on Twitter: @TheHookUp1
Support my channel:
Patreon: https://www.patreon.com/thehookup

Music by www.BenSound.com

Related Posts