Since | Origin / Contributor | Maintainer | Source |
---|---|---|---|
2015-03-02 | AllAboutEE | AllAboutEE | mcp23008.lua |
This Lua module provides access to MCP23008 I²C I/O Expander.
!!! note
This module requires `i2c` C module built into firmware.
mcp32008 = require("mcp32008")
mcp32008 = nil
package.loaded["mcp32008"] = nil
Sets the MCP23008 device address’s last three bits.
!!! note
The address is defined as binary `0100[A2][A1][A0]` where `A2`, `A1`, and `A0` are defined by the connection of the pins, e.g. if the pins are connected all to GND then the parameter address will need to be `0x0`.
mcp23008.begin(address, pinSDA, pinSCL, speed)
address
: The 3 least significant bits (LSB) of the addresspinSDA
: The pin to use for SDApinSCL
: The pin to use for SCLspeed
: The speed of the I2C signalnil
Writes a byte of data to the GPIO register.
mcp23008.writeGPIO(dataByte)
dataByte
: The byte of data to writenil
Reads a byte of data from the GPIO register
mcp23008.readGPIO()
None
One byte of data
Writes one byte of data to the IODIR register.
mcp23008.writeIODIR(dataByte)
dataByte
: The byte of data to writenil
Reads a byte from the IODIR register
mcp23008.readIODIR()
None
The byte of data in IODIR
Writes a byte of data to the GPPU (Pull-UP resistors register)
mcp23008.writeIODIR(dataByte)
dataByte
: the value to write to the GPPU register. Each bit in this byte is assigned to an individual GPIO pinnil
Reads the GPPU (Pull-UP resistors register) byte
mcp23008.readGPPU()
None
The GPPU byte i.e. state of all internal pull-up resistors
Other examples of using this module can be found in mcp23008_buttons.lua and mcp23008_leds.lua files.