学习NodeMCU的GPIO

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

NodeMCU GPIO与ESP8266的映射

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

NodeMCU的API

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() – pulse1
     print(du)
     pulse1 = tmr.now()
     if level == 1 then gpio.trig(1, "down") else gpio.trig(1, "up") end
    end
    gpio.trig(1, "down",pin1cb)

See also

- gpio.mode()

-gpio.write()

NodeMCU GPIO的驱动能力

https://nurdspace.nl/ESP8266#Power_Management

General PurposeIO

A total of up to 16 GPIO pins. The firmware can assign themdifferent functions. Each GPIO can be configured internal pullup /pulldown resistors available software registers sampled input,triggering edge or level CPU interrupt input, trigger level wake-upinterrupt
input, open-drain or complementary push-pull outputdrivers, software register output source or sigma-delta PWM DAC.These pins are multiplexed with other functions, such as the maininterface, UART, SI, Bluetooth co-existence and so on.

Digital IO pins

Digital IO pad is two-way, three states. It includes a three-statecontrol input and output buffers. In addition, for low-poweroperation, IO can be set to hold state. For example, when we reducethe chip‘s power consumption, all the output enable signal can
be setto maintain a low-power state. Hold function can be selectivelyimplanted IO in need. When the IO help internal and external circuitdriving, hold function can be used to hold last state. Hold functionto pin introduce some positive feedback. Therefore,
the externaldrive pin must be stronger than the positive feedback. However, therequired driving force size is still small, in the 5uA of.


Variables


Symbol


Min


Max


Units


Input Low Voltage


Vil


-0.3


0.25xV10


V


Input High Voltage


Vih


0.75xV10


3.6


V


Input leakage current


IIL


-


50


nA


Output Low Voltage


VOL


-


0.1xV10


V


Output High Voltage


VOH


0.8xV10


-


V


Input pin capacitance


Cpad


-


2


pF


VDDIO


V10


1.7


3.6


V


Current


Imax


-


12


mA


Temperature


Tamb


-20


100


C

All digital IO pins must add an overvoltage protection circuit(snap back circuit) between the pin and ground. Usually bounce (snapback) voltage is about 6V, while maintaining the voltage is 5.8V.This prevents excessive voltage and generating ESD. Diodes
also avoidreverse voltage output devices.

时间: 2024-10-08 19:56:57

学习NodeMCU的GPIO的相关文章

Beaglebone Back学习四(GPIO实验)

GPIO Beaglebone Back开发板引出了92个引脚,其中只有65个GPIO口可通过配置使用,由于引脚具有"复用"的特性,大约每个引脚有8种工作模式(Beagle System Reference Manual),默认情况下,设为Mode7.由于P8扩展部分的引脚功能相对简单,复用不多,故项目功能复杂时,最好选择P8上的GPIO口. 对GPIO口的操作,主要有三个步骤 1 选择GPIO口根据以下两表,确定使用那个GPIO口,该表也可以在BBB_SRM文件中找到. (1)拉电流

学习NodeMCU的低功耗休眠

大多数IOT应用是电池供电的,在电池电量一定的情况下(体积.环境等限制),耗电量决定了产品的寿命,决定了产品是否实用.本文主要目的是学习关于NodeMCU的休眠机制. NodeMCU的API https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en#nodedsleep node.dsleep() Description Enter deep sleep mode, wake up when timed out. Syntax

stm32寄存器版学习笔记01 GPIO口的配置(LED、按键)

STM32的I/O口可以由软件配置成如下8种模式:输入浮空.输入上拉.输入下拉.模拟输入.开漏输出.推挽输出.推挽式复用功能及开漏复用功能.每个I/O口由7个寄存器来控制:配置模式的端口配置寄存器CRL和CRH(模式.速度):数据寄存器IDR和ODR:置位/复位寄存器BSRR:复位寄存器BRR:锁存寄存器LCKR. I/O口模式: GPIO的8种模式 通用输出 推挽输出(Puch-Pull) 可以输出高.低电平,连接数字器件   开漏输出(Open-Drain) 开漏引脚不连接外部的上拉电阻时,

STM32学习2(GPIO EXTI SYSTICK)

GPIO的使用: 打开GPIO时钟根据手册寄存器映射看在哪根总线上,设一个GPIO_InitTypeDef结构体变量,根据实际给改结构体里面各项赋值,GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct),就初始化设置完了. 具体应用读写直接调用 /* GPIO Read and Write functions **********************************************/uint8_t

Duanxx的BeagleBone学习: 安装GPIO的Python库

第一步:upgrade dtc comiler ro enable SPI wget -c https://raw.githubusercontent.com/RobertCNelson/tools/master/pkgs/dtc.sh chmod +x dtc.sh ./dtc.sh 参考网址:https://learn.adafruit.com/introduction-to-the-beaglebone-black-device-tree/compiling-an-overlay 第二步:

野路子学习esp32(八) GPIO 点亮[email protected]宏万

我购买的是下面这个东东,安信可出品 上面有一个LED,电源指示灯,一个重启按钮,还有一个IO0 按钮: 我们要做的就是点亮LED灯: 通过看原理图,可以得知LED是接在 IO2上的: 新建一个LED工程并设置发布方式 工程结构: 原文地址:https://www.cnblogs.com/hongwans/p/9095317.html

stm32寄存器版学习笔记07 ADC

STM32F103RCT有3个ADC,12位主逼近型模拟数字转换器,有18个通道,可测量16个外部和2个内部信号源.各通道的A/D转换可以单次.连续.扫描或间断模式执行. 1.通道选择 stm32把ADC转换分成2个通道组:规则通道组相当于正常运行的程序:注入通道组相当于中断.程序初始化阶段设置好不同的转换组,系统运行中不用变更循环转换的配置,从而达到任务互不干扰和快速切换. 有16个多路通道.可以把转换组织成两组:规则组和注入组.在任意多个通道上以任意顺序进行的一系列转换构成成组转换.例如,可

stm32寄存器版学习笔记05 PWM

STM32除TIM6和TIM7外都可以产生PWM输出.高级定时器TIM1和TIM8可以同时产生7路PWM,通用定时器可以产生4路PWM输出. 1.TIM1 CH1输出PWM配置步骤 ①开启TIM1时钟,配置PA8为复用输出 APB2外设时钟使能寄存器(RCC_APB2ENR) APB1外设复位寄存器 (RCC_APB1RSTR) 置1开启.清0关闭. Eg:RCC->APB2ENR|=1<<11; //使能TIM1时钟 配置I/O口: 参见stm32寄存器版学习笔记01 GPIO口的配置

MQTT学习笔记——树莓派MQTT客户端 使用Mosquitto和paho-python

0 前言 本文说明如何在树莓派上安装Mosquitto.本文通过两个简单的例子说明树莓派中如何使用MQTT协议实现消息订阅,这些例子包括Mosquitto_sub指令实现消息订阅和paho-python扩展库实现GPIO端口的远程控制.本文中使用了两个工具--Mosquitto paho-python,其中Mosquitto是一款实现了 MQTT v3.1 协议的开源消息代理软件,提供轻量级的,支持发布/订阅的的消息推送模式,使设备对设备之间的消息通信简单易用:另外,paho-python是一个