您的位置:首页 > Web前端 > Node.js

NodeMCU教程 GPIO操作与引脚映射

2016-06-12 16:41 429 查看

1、Simple Demo

We can operate the GPIO of NodeMCU like Arduino,Code block-1 is a simple demo gave by the official website.

For more you can see http://nodemcu.readthedocs.io/en/master/en/modules/gpio/

pin = 1--Define the number of GPIO which to operate

gpio.mode(pin,gpio.OUTPUT)--Define the mode of GPIO to output

gpio.write(pin,gpio.HIGH)--Output a high level

gpio.mode(pin,gpio.INPUT)--Define the mode of GPIO to input

print(gpio.read(pin))--Read the input signal,return a number, 0 = low, 1 = high

The syntax of GPIO mode definition is as follows:

gpio.mode(pin,mode[,pullup])

Parameters

pin
pin
to configure, IO index
mode
one
of gpio.OUTPUT, gpio.OPENDRAIN, gpio.INPUT, or gpio.INT (interrupt mode)
pullup
gpio.PULLUP
enables the weak pull-up resistor; default is gpio.FLOAT

2、Pin Map

The Figure-1 (NODEMCU_DEVKIT_V1.0_PINMAP.png) is the GPIO map between NodeMCU and ESP8266.

3、GPIO Index

The Table-1 is the map
between pin index and ESP8266 GPIO. Combined with Figure-1
and Table-1,we can get the pin-index corresponding the hardware GPIO.

—————————————————————————————————————————

上面是练英语写作的,欢迎吐槽

。中文如下:

1、简单例程

我们可以像Arduino一样只需要几行代码就能方便地操作NodeMCU的GPIO。下面是官方的示例代码,更多请查看

http://nodemcu.readthedocs.io/en/master/en/modules/gpio/

示例代码code block-1

参考http://nodemcu.com/index_cn.html

pin = 1
gpio.mode(pin,gpio.OUTPUT)
gpio.write(pin,gpio.HIGH)
gpio.mode(pin,gpio.INPUT)
print(gpio.read(pin))
pin = 1--定义IO口序号
gpio.mode(pin,gpio.OUTPUT)--输出模式

gpio.write(pin,gpio.HIGH)--输出高电平

gpio.mode(pin,gpio.INPUT)--输入模式

print(gpio.read(pin))--读取输入信号,返回0或1

GPIO模式定义语法如下:

gpio.mode(pin,mode[,pullup])

参数

pin
IO
口序号
mode
可以是gpio.OUTPUT,
gpio.OPENDRAIN, gpio.INPUT, 或者 gpio.INT (中断模式)
pullup
支持gpio.PULLUP上拉模式;默认为
gpio.FLOAT浮空模式

2、引脚映射

NodeMCU与ESP8266端口对应关系Figure-1



3、GPIO序号

GPIO序号与ESP8266引脚对应关系

IO indexESP8266 pinIO indexESP8266 pin
0 [*]GPIO167GPIO13
1GPIO58GPIO15
2GPIO49GPIO3
3GPIO010GPIO1
4GPIO211GPIO9
5GPIO1412GPIO10
6GPIO12
结合Figure-1与Table-1,我们就能得到NodeMCU硬件引脚对应的IO序号。

【转载请注明出处:/article/11899277.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: