中国最全IT社区平台 联系我们 | 收藏本站
阿里云优惠2阿里云优惠1
您当前位置:首页 > php开源 > 综合技术 > 学习NodeMCU的GPIO

学习NodeMCU的GPIO

来源:程序员人生   发布时间:2015-05-12 08:50:25 阅读次数:15617次

本文研究NodeMCU的GPIO的用法,主要是IO的电压范围和电流范围

NodeMCU GPIOESP8266的映照

https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en

GPIONEW TABLE ( Build 20141219 and later)

new_gpio_map

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. *



NodeMCUAPI

https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en


GPIO module

CONSTANT

gpio.OUTPUT, gpio.INPUT, gpio.INT, gpio.HIGH, gpio.LOW

gpio.mode()

Description

initialize pin to GPIO mode, set the pin in/out mode, internalpullup.

Syntax

gpio.mode(pin, mode, pullup)

Parameters

pin: 0~12, IO index
mode: gpio.OUTPUT or gpio.INPUT, orgpio.INT(interrupt mode) pullup: gpio.PULLUP or gpio.FLOAT, default:gpio.FLOAT.

Returns

nil

Example

-- set gpio 0 as output. gpio.mode(0, gpio.OUTPUT)

See also

- gpio.read()

- Backto Index

gpio.read()

Description

read pin value.

Syntax

gpio.read(pin)

Parameters

pin: 0~12, IO index

Returns

number:0 - low, 1 - high

Example

-- read value of gpio 0. gpio.read(0)

See also

- gpio.mode()


gpio.write()

Description

set pin value.

Syntax

gpio.write(pin)

Parameters

pin: 0~12, IO index
level: gpio.HIGH or gpio.LOW

Returns

nil

Example

-- set pin index 1 to GPIO mode, and set the pin to high. pin=1 gpio.mode(pin, gpio.OUTPUT) gpio.write(pin, gpio.HIGH)

See also

- gpio.mode()
-gpio.read()


gpio.trig()

Description

set the interrupt callback function for pin.

Syntax

gpio.trig(pin, type, function(level))

Parameters

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.

Returns

nil

Example

-- use pin 0 as the input pulse width counter pulse1 = 0 du = 0 gpio.mode(1,gpio.INT) function pin1cb(level) du = tmr.now()
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------