Contents
ESP8266 NodeMCU Devkit GPIO Pin Map
IO index | ESP8266 pin | IO index | ESP8266 pin |
---|---|---|---|
0 [*] | GPIO16 | 7 | GPIO13 |
1 | GPIO5 | 8 | GPIO15 |
2 | GPIO4 | 9 | GPIO3 |
3 | GPIO0 | 10 | GPIO1 |
4 | GPIO2 | 11 | GPIO9 |
5 | GPIO14 | 12 | GPIO10 |
6 | GPIO12 |
ESP8266 NodeMCU Module GPIO Functions
gpio.mode() | Initialize pin to GPIO mode, set the pin in/out direction, and optional internal weak pull-up. |
gpio.read() | Read digital GPIO pin value. |
gpio.serout() | Serialize output based on a sequence of delay-times in µs. |
gpio.trig() | Establish or clear a callback function to run on interrupt for a pin. |
gpio.write() | Set digital GPIO pin value. |
gpio.pulse | This covers a set of APIs that allow generation of pulse trains with accurate timing on multiple pins. |
gpio.pulse.build | This builds the gpio. |
gpio.pulse:start | This starts the output operations. |
gpio.pulse:getstate | This returns the current state. |
gpio.pulse:stop | This stops the output operation at some future time. |
gpio.pulse:cancel | This stops the output operation immediately. |
gpio.pulse:adjust | This adds (or subtracts) time that will get used in the min / max delay case. |
gpio.pulse:update | This can change the contents of a particular step in the output program. |
Note : [*] D0(GPIO16) can only be used as gpio read/write. No support for open-drain/interrupt/pwm/i2c/ow.
Pr-Request
- ESP8266 NodeMCU Build firmware
- ESP8266 NodeMCU Flash firmware
- ESp8266 NodeMCU IDE
- ESP8266 NodeMCU Hello World example
GPIO pin set as input
- if you have questions like How set GPIO pin as input in ESP8266? then refer the below contents
Required
- ESP8266 Any module or NodeMCU Development Kit(Any Version)
- ESPlorer
- Wires (Optional)
Note : if your using ESP8266 module only you need to know basic connection diagram of ESP8266
Code
-- set pin index 1 to GPIO mode, and set the pin to high. pin=3 --gpio-0 gpio.mode(pin, gpio.INPUT) while true do print("GPIO Read PIN Status : "..gpio.read(pin)) end
GPIO pin set as output
- Set GPIO pin as output using gpio.mode() function.
- Example : gpio.mode(pin, gpio.INPUT)
Code
pin = 3 gpio.mode(pin, gpio.OUTPUT) gpio.write(pin,HIGH) --gpio.write(pin, LOW)
Result
GPIO pin status monitor
- GPIO pin monitor status is very useful, because if you wanna monitor the pin status based on do the some process can easily.
- Example : continuously monitor the gpio input button pin and based on button pin low/high level trun on/off the led.
Required
- ESP8266 Any module or NodeMCU Development Kit(Any Version)
- ESPlorer
- Wires (Optional)
Note : if your using ESP8266 module only you need to know basic connection diagram of ESP8266.
Basic connection Diagram
Note : this below diagram for flash nodeMCU Firmware to ESP8266. We use the same circuit. But GPIO-0 Should be High or float Mode
Code
- Source Code GitHub
--www.aruneworld.com/embedded/esp8266/esp8266-nodecmu button_pin=3 --GPIO-0 gpio.mode(button_pin, gpio.INPUT) while true do print("GPIO Read PIN Status : "..gpio.read(button_pin)) tmr.delay(1000000) end