本文研究NodeMCU的GPIO的用法,主要是IO的电压范围和电流范围
https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en
IO index |
ESP8266 pin |
IO index |
ESP8266 pin |
---|---|---|---|
0 [*] |
GPIO16 |
7 |
GPIO13 |
1 |
GPIO4 |
8 |
GPIO15 |
2 |
GPIO5 |
9 |
GPIO3 |
3 |
GPIO0 |
10 |
GPIO1 |
4 |
GPIO2 |
11 |
GPIO9 |
5 |
GPIO14 |
12 |
GPIO10 |
6 |
GPIO12 |
** D0(GPIO16) can only be used asgpio read/write. no interrupt supported. no pwm/i2c/ow supported. *
NodeMCU的API
https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en
gpio.OUTPUT, gpio.INPUT, gpio.INT, gpio.HIGH, gpio.LOW
initialize pin to GPIO mode, set the pin in/out mode, internalpullup.
gpio.mode(pin, mode, pullup)
pin: 0~12, IO index
mode: gpio.OUTPUT or gpio.INPUT, orgpio.INT(interrupt mode) pullup: gpio.PULLUP or gpio.FLOAT, default:gpio.FLOAT.
nil
- gpio.read()
- Backto Index
read pin value.
gpio.read(pin)
pin: 0~12, IO index
number:0 - low, 1 - high
- gpio.mode()
set pin value.
gpio.write(pin)
pin: 0~12, IO index
level: gpio.HIGH or gpio.LOW
nil
- gpio.mode()
-gpio.read()
set the interrupt callback function for pin.
gpio.trig(pin, type, function(level))
pin: 1~12, IO index, pin D0 does not supportInterrupt.
type: "up", "down", "both","low", "high", which represent rising edge,falling edge, both edge, low level, high level trig modeseparately.
function(level): callback function when triggered. Thegpio level is the param. Use previous callback function if undefinedhere.
nil