這是練英語寫作的,中文在下面。
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 indexmode
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引腳對應關系Table-1
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 |
【轉載請注明出處:http://blog.csdn.net/leytton/article/details/51646624】
PS:如果此文對您有所幫助,請點個贊讓我知道哦~