I have an embarrassingly simple question.

My experience to date has been limited to Arduino Uno + Wifi101. I bought an ESP8266 and noticed that the GPIO pins don't match the printed numbers on the board.

When programming and defining pins, does #define <pin name> 16 call the pin with the printed designation D0?

I can't find a straight answer to this anywhere.

Image credit: http://crufti.com/content/images/2015/11/nodemcudevkit_v1-0_io.jpg

NodeMCU ESP8266

  • When you use it with what libraries? – Ignacio Vazquez-Abrams Jun 14 '16 at 2:19
  • The Arduino IDE: ESP8266WiFi.h, SPI.h – acpilot Jun 14 '16 at 2:25

Looks like you're using https://github.com/esp8266/Arduino, in which case - yes, 16 is GPIO16, which on the NodeMCU board you have is labeled D0.
I am not entirely sure why the NodeMCU guys had to do this "pin remapping", but the end result is inconvenience when using the module with anything but their Lua.

| improve this answer | |

It looks like they are using a similar system to the Arduino pin mappings, for example:

Arduino Uno pin mappings

(Image credit: https://www.arduino.cc/en/Hacking/PinMapping168)

There, for example, pin 2 on the chip, is D0 (digital pin 0) on the board.

Their board will use their own mappings, but the concept is the same.

does #define 16 call the pin with the printed designation D0?

That doesn't "call" anything. It would depend on the code. If the code in question addresses the actual chip pins, then it is chip pin 16. If it goes through a library and the library maps the chip pins to the board pins, that it will refer to board pin 16. I notice BTW that the board doesn't have a pin 16.

| improve this answer | |
  • Pardon my ignorance. By pin 16 I meant GPIO 16. – acpilot Jun 14 '16 at 23:22
  • I know what you meant. I'm just saying that a line #define foo 16 can only be read when you see what is done with foo. On its own it could mean anything. – Nick Gammon Jun 14 '16 at 23:42

Well based on my experience with NodeMcu and Arduino, in Arduino you use the GPIO by reffering its pin number (like 0-13), whereas in NodeMcu you will have to use D0-D8.

It's better to use D0 to use GPIO 16.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.