GPIO
Generic GPIO module for transparently handling physical pins and pins controlled by port expanders.
The gpio
module defined the following constants:
PE_ADS7128 = 1
PE_ADS1015 = 2
PE_PCAL6524 = 3
PE_SX1503 = 4
used as names for the Port Expander supported chips.
function set
set(pin, value)
Sets the pin
gpio to logic value value
.
pin
can be either the pin number or the symbolic name defined into board
module from bsp
value
can be 0
or 1
.
function get
get(pin)
Returns the value read on pin
gpio.
function latch
latch(pin)
Return the latch register value for the pin
gpio.
function toggle
toggle(pin)
Invert the output value of the pin
gpio.
function mode
mode(pin, mode)
Configures the pin
gpio with mode
mode.
function high
high(pin)
Set the pin
gipo to logic 1
.
function low
low(pin)
Set the pin
gipo to logic 0
.
function on_rise
on_rise(pin, fn, debounce=0, pull=INPUT_PULLNONE)
Registers the fn
function as callback on the rising edge on the pin
gpio. De-bouncing with a delay of debounce
milliseconds and setting a pull
pull-up or pull-down resistor. By default pull is none, since setting a pull-up or pull-down without knowing the hardware used can cause failures.
The signature of fn
is fn(pin, value)
where pin
is the interrupted pin and value
is 0 or 1 depending on the level of the pin.
function on_fall
on_fall(pin, fn, debounce=0, pull=INPUT_PULLNONE)
Registers the fn
function as callback on the falling edge on the pin
gpio. De-bouncing with a delay of debounce
milliseconds and setting a pull
pull-up or pull-down resistor. By default pull is none, since setting a pull-up or pull-down without knowing the hardware used can cause failures.
The signature of fn
is fn(pin, value)
where pin
is the interrupted pin and value
is 0 or 1 depending on the level of the pin.
function on_rise_and_fall
on_rise_and_fall(pin, fn, debounce=0, pull=INPUT_PULLNONE)
Registers the fn
function as callback either on the rising and falling edges on the pin
gpio. De-bouncing with a delay of debounce
milliseconds and setting a pull
pull-up or pull-down resistor. By default pull is none, since setting a pull-up or pull-down without knowing the hardware used can cause failures.
*** note ***: This function might not work properly with pin that are not native of the zm1 module.
The signature of fn
is fn(pin, value)
where pin
is the interrupted pin and value
is 0 or 1 depending on the level of the pin.
function disable_interrupt
disable_interrupt(pin)
Disable the interrupt triggered by configured edge(s) for the pin
gpio. By disabling the interrupt triggering, the callbacks registered on the pin
will not be called.
class LED
LED(rled, gled, bled, active=0)
Return a LED
item controlled by the three pins passed.
*** note *** native leds on Zerynth boards are already initialized and can be controlled using board.led()
-
rled
is the red led pin. -
gled
is the green led pin. -
bled
is the blue led pin. -
active
is the logic state of the pins to turn led on. Default is0
.
method led
led(color)
Set the color of the led.
color
is the color to set. Possible colors are.BLACK
,WHITE
,RED
,GREEN
,BLUE
,YELLOW
,CYAN
andMAGENTA
.
function add_expander
add_expander(petype, startpin, npins, alertpin, address, i2c=I2C0)
Configures a Port Expander of petype
(see the PE constants defined in this module), starting at board pin number startpin
, with a total of npins
pins. alertpin
is the pin used for the interrupts generated by the PE being configured. address
is the I2C bus address of the port expander on right-aligned 7bits. i2c
is the system bus number.
Examples
The module can be used without configuration like this:
import gpio
gpio.mode(D10, OUTPUT) # Set mode for D10
gpio.mode(D11, OUTPUT) # Set mode for D11
gpio.high(D10) # Set D10 high
gpio.low(D11) # Set D11 low