Digital package provides drivers for GPIO expanders.

GPIOPort

Summary

GPIOPort interface provides functions to use digital I/O.

Supported devices

Methods list

digitalCount()

Returns the digital channel count.

REST API : GET /devices/name/count

digitalRead(channel)

Returns the value of the given digital channel.

REST API : GET /devices/name/channel/value

digitalReadAll()

Returns a list containing all digital channels value.

REST API : GET /devices/name/*/value

digitalWrite(channel, digit)

Write the value of the given digital channel.

REST API : POST /devices/name/channel/value/digit

portRead()

Returns an integer composed of all digital bits.

REST API : POST /devices/name/*/integer

portWrite(value)

Write on all digital channels with an integer composed of all bits.

REST API : POST /devices/name/*/integer/value

getFunction(channel)

Returns the current fonction of the given digital channel.

REST API : Use getFunctionString instead.

getFunctionString(channel)

Returns the current fonction of the given digital channel.

REST API : GET /devices/name/channel/function

setFunction(channel, func)

Setup the given digital channel with the given function

REST API : Use setFunctionString instead.

setFunctionString(channel, func)

Setup the given digital channel.

REST API : GET /devices/name/channel/function/func

wildcard()

Returns a list containing the current value and function of all digital channels.

REST API : GET /devices/name/*

Python example

form webiopi.devices.digital import MCP23008
mcp = MCP23008(...)             # setup a MCP23008 I2C GPIO expander
# or
from webiopi import deviceInstance
mcp = deviceInstance("mcp")     # retrieve device named "mcp" in configuration file

mcp.getFunction(0)              # get current MCP digital channel 0 setup

mcp.setFunction(0, GPIO.OUT)    # setup MCP digital channel 0 as output
mcp.setFunction(1, GPIO.OUT)    # setup MCP digital channel 1 as output
mcp.setFunction(2, GPIO.OUT)    # setup MCP digital channel 2 as output
mcp.setFunction(3, GPIO.OUT)    # setup MCP digital channel 3 as output

mcp.digitalRead(4)              # read MCP digital channel 0

mcp.digitalWrite(4, GPIO.HIGH)  # write MCP digital channel 4 as HIGH

mcp.portWrite(0x0F)             # write channels 0-3 as HIGH

mcp.portRead()                  # read all MCP digital channels in a single integer

REST example


HTTP GET  /devices/mcp/0/function      # retrieve "mcp" channel 0 setup
HTTP GET  /devices/mcp/0/value         # retrieve "mcp" channel 0 digital value

HTTP POST /devices/mcp/0/function/out  # set "mcp" channel 0 as output
HTTP POST /devices/mcp/0/value/1       # set "mcp" channel 0 as digital HIGH