Pin setup

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
atux_null
Posts: 20
Joined: Tue Jul 10, 2018 2:16 pm

Pin setup

Post by atux_null » Fri Aug 03, 2018 10:08 pm

Kinda confused and i need your confirmation on pins please. I need to connect some devices in pins 4 and 12 as well. So these are the D2 for gpio 4 and read from micropython as pin 4? Also for pin 12 is D6 for gpio12 and micropython reads it as pin12?
Please advice

cyberlab
Posts: 56
Joined: Sat Apr 21, 2018 5:02 am

Re: Pin setup

Post by cyberlab » Sat Aug 04, 2018 3:29 am

Hello good day, apparently you are talking about nodemcu, you are correct, when you connect something in D2 you have to refer to it as pin 4 in micropython and D6 as pin 12.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Pin setup

Post by kevinkk525 » Sat Aug 04, 2018 9:02 am

You can use this dict I'm using to get the pin number with nodemcu:

Code: Select all

from micropython import const
pins = {"D0": const(16), "D1": const(5), "D2": const(4), "D3": const(0), "D4": const(2),
            "D5": const(14), "D6": const(12), "D7": const(13), "D8": const(15), "D9": const(3),
            "D10": const(1)}
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: Pin setup

Post by SpotlightKid » Sun Aug 05, 2018 12:30 pm

Or shorter:

Code: Select all

pins = {"D%i" % p: v for p, v in enumerate((16, 5, 4, 0, 2, 14, 12, 13, 15, 3, 1))}
I'm not sure whether const makes sense for dict entries.

Post Reply