Since | Origin / Contributor | Maintainer | Source |
---|---|---|---|
2016-11-26 | Johny Mattsson | Johny Mattsson | gpio.c |
This module provides access to the GPIO (General Purpose Input/Output) subsystem.
The ESP32 chip features 40 physical GPIO pads. Some GPIO pads cannot be used or do not have the corresponding pin on the chip package (refer to the ESP32 Datasheet).
Configure GPIO mode for one or more pins.
gpio.config({
gpio=x || {x, y, z},
dir=gpio.IN || gpio.OUT || gpio.IN_OUT,
opendrain= 0 || 1 -- only applicable to output modes
pull= gpio.FLOATING || gpio.PULL_UP || gpio.PULL_DOWN || gpio.PULL_UP_DOWN
}, ...)
List of configuration tables:
gpio
one or more (given as list) pins, see GPIO Overviewdir
direction, one of
gpio.IN
gpio.OUT
gpio.IN_OUT
opendrain
1 enables opendrain mode, defaults to 0 if omittedpull
enable pull-up and -down resistors, one of
gpio.FLOATING
disables both pull-up and -downgpio.PULL_UP
enables pull-up and disables pull-downgpio.PULL_DOWN
enables pull-down and disables pull-upgpio.PULL_UP_DOWN
enables both pull-up and -downnil
gpio.config( { gpio={19,21}, dir=gpio.OUT }, { gpio=22, dir=gpio.IN, pull=gpio.PULL_UP })
Read digital GPIO pin value.
gpio.read(pin)
pin
pin to read, see GPIO Overview
0 = low, 1 = high
Establish or clear a callback function to run on interrupt for a GPIO.
gpio.trig(pin, type [, callback])
pin
, see GPIO Overviewtype
trigger type, one of
gpio.INTR_UP
for trigger on rising edgegpio.INTR_DOWN
for trigger on falling edgegpio.INTR_UP_DOWN
for trigger on both edgesgpio.INTR_LOW
for trigger on low levelgpio.INTR_HIGH
for trigger on high levelcallback
optional function to be called when trigger fires, trigger is disabled when omitted. Parameters are:
pin
level
nil
Configuring wake-from-sleep-on-GPIO-level.
gpio.wakeup(pin, level)
pin
, see GPIO Overviewlevel
wake-up level, one of
gpio.INTR_NONE
to disable wake-upgpio.INTR_LOW
for wake-up on low levelgpio.INTR_HIGH
for wake-up on high levelnil
Set digital GPIO pin value.
gpio.write(pin, level)
pin
pin to write, see GPIO Overviewlevel
1 or 0nil