{"id":320,"date":"2018-07-25T11:48:35","date_gmt":"2018-07-25T15:48:35","guid":{"rendered":"http:\/\/www.thesmarthomehookup.com\/test_install\/?p=320"},"modified":"2023-02-08T17:09:09","modified_gmt":"2023-02-08T22:09:09","slug":"post-320","status":"publish","type":"post","link":"http:\/\/www.thesmarthomehookup.com\/test_install\/post-320\/","title":{"rendered":"How To: Pick the right pins on the NodeMCU ESP8266 and ESP32"},"content":{"rendered":"<p><iframe width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/7h2bE2vNoaY\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen=\"\"><\/iframe><\/p>\n<p><strong>Picking your pins on the ESP8266 and ESP32<\/strong><\/p>\n<p>Today on the hookup we\u2019re going to explore some of the quirks of the different pins on both the ESP8266 and ESP32 based nodeMCUs.<\/p>\n<p>Straight to the point! If you\u2019re using an ESP8266 based nodeMCU here are the best pins to use for your general purpose input output needs.&nbsp; If you\u2019re using the ESP32 based nodeMCU these pins are the best pins for general purpose input output.&nbsp; Diagrams of each of the boards with important details about each pin can be found in the video description.&nbsp; To see how I determined which pins are the best keep watching.<\/p>\n<p>First of all, I have to admit, I\u2019m mostly making this video for myself.&nbsp; I can\u2019t tell you how many times during a project I\u2019ve troubleshooted my code searching for my mistake only to find the issue was due to some undocumented, or poorly documented quirk of the nodeMCU.&nbsp; In this video we\u2019re 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.<\/p>\n<p>While we\u2019re talking about pins, it\u2019s important to know that the raw pin order on the nodemcu doesn\u2019t match up with the descriptions written on the board.&nbsp; For instance D1 on the ESP8266 based nodemcu is actually GPIO 5, so if you were to type pinMode(1, OUTPUT), you wouldn\u2019t be assigning pin D1.&nbsp; 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\u2019s pins installed in Arduino.&nbsp; On my diagrams the raw pin orders are listed, so you\u2019ll use the numbers listed in the bubbles, not on the board.<\/p>\n<p>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.&nbsp; 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.&nbsp; I then repeated the same process connecting each pin to the 3.3v pin instead of ground.&nbsp; Using this method I was able to determine the specific boot requirements of each GPIO pin.<\/p>\n<p>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.&nbsp; When using these pins as outputs connected to relays, transistors, or optoisolators this will cause them to fire for a short period of time.&nbsp; 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.&nbsp; To test this I hooked up a 3.3V relay and wrote a sketch that reboots after setting itself up correctly.&nbsp; I then tested every pin and noted which ones triggered the relay.&nbsp; A few of the pins on the ESP32 output about 1V for a short period of time during the boot process,&nbsp; But it wasn\u2019t enough voltage to trigger my relay so I didn\u2019t include it on the chart.&nbsp; If you were using a transistor with a low threshold voltage it could still cause issues, so be aware of that.<\/p>\n<p>I\u2019m going to keep this video short and focused solely on choosing the right GPIO pins, or more specifically avoiding picking the wrong ones.&nbsp; I hope the diagrams I have provided will be useful when you are making your next project using a NodeMCU.&nbsp; If you enjoyed this video please consider subscribing, and as always, thanks for watching the hookup.<iframe title=\"How To: Pick the right pins on the NodeMCU ESP8266 and ESP32\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/7h2bE2vNoaY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p><strong>Video Description<\/strong><\/p>\n<p>ESP8266 NodeMCU Pin Diagram: <a href=\"https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/GPIO_Limitations_ESP8266_NodeMCU.jpg\">https:\/\/github.com\/thehookup\/Wireless_MQTT_Doorbell\/blob\/master\/GPIO_Limitations_ESP8266_NodeMCU.jpg<\/a><\/p>\n<p>ESP32 NodeMCU Pin Diagram: <a href=\"https:\/\/github.com\/thehookup\/ESP32_Ceiling_Light\/blob\/master\/GPIO_Limitations_ESP32_NodeMCU.jpg\">https:\/\/github.com\/thehookup\/ESP32_Ceiling_Light\/blob\/master\/GPIO_Limitations_ESP32_NodeMCU.jpg<\/a><\/p>\n<p>The ESP32 Pins Outputting a PWM signal at startup that had duty cycles low enough that they didn&#8217;t trigger the relay were: P14, P5, P0, P15, P8, P7, and P6.<\/p>\n<p>Buy an ESP8266 NodeMCU: <a href=\"https:\/\/amzn.to\/2K0hgjS\">https:\/\/amzn.to\/2K0hgjS<\/a><br \/>\nBuy an ESP32 NodeMCU: <a href=\"https:\/\/amzn.to\/2JVgEvx\">https:\/\/amzn.to\/2JVgEvx<\/a><\/p>\n<p>Follow me on Twitter: @TheHookUp1<br \/>\nSupport my channel:<br \/>\nPatreon:&nbsp;<a href=\"https:\/\/www.patreon.com\/thehookup\">https:\/\/www.patreon.com\/thehookup<\/a><\/p>\n<p>Music by www.BenSound.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Picking your pins on the ESP8266 and ESP32 Today on the hookup we\u2019re 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\u2019re using an ESP8266 based nodeMCU here are the best pins to use for your general purpose input [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":2602,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-320","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"acf":[],"mb":[],"mfb_rest_fields":["title","gutenberg_elementor_mode"],"_links":{"self":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts\/320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/comments?post=320"}],"version-history":[{"count":5,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts\/320\/revisions"}],"predecessor-version":[{"id":2357,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/posts\/320\/revisions\/2357"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/media\/2602"}],"wp:attachment":[{"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/media?parent=320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/categories?post=320"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.thesmarthomehookup.com\/test_install\/wp-json\/wp\/v2\/tags?post=320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}