GPIO

The gpio extension controls and monitors GPIO pins connected to a linux sbc board such as a Raspberry Pi. Provided are a set of interfaces through the support of adafruit-blinka. There are a large variety of supported linux boards that you can use.

This extension does not take an extension level config and is focused on interfaces.


Sensor Interface

Provides a sensor that returns a GPIO pin reading.

OptionTypeRequiredDescription
key[String]YesUnique slug id for the component
pin[String]YesGPIO pin to use on board i.e. D12 or A1.
name[String]NoFriendly display name of component. Useful for UI.
classifier[String]NoChoose a specific sensor classifier to change formatting on frontend. Default: general

Config

Here is a config of a complete gpio sensor.

"sensor": [{
    "key": "gpio_sensor_D12",
    "interface": "gpio",
    "pin": "D12",
    "classifier": "general"
}]

Control Interface

Attach a control to a linux board GPIO such as a button, switch or potentiometer.

OptionTypeRequiredDescription
key[String]YesUnique slug id for the component
pin[String]YesGPIO pin to use on board i.e. D12 or A1.
name[String]NoFriendly display name of component. Useful for UI.
type[String]NoType of control behavior. Options: button control or potentiometer. Default: button
resistor[String]NoSet internal resistor to pull up or pull down. Default None
edge_detection[String]NoSet edge detection on gpio for more responsive feedback. Options rose, fellor both.
debounce[Float]NoTime in seconds to wait for gpio to settle before firing. Prevents multiple fires from one press. Default 0. A good starting value is 0.05.

Config

Here is a config of a complete gpio control.

"control": [{
    "key": "gpio_button_D12",
    "interface": "gpio",
    "name": "Button Pin D12",
    "type": "button",
    "resistor": "down",
    "edge_detection": "both",
    "debounce": 0.05
}]

Note: Be mindful of how edge_detection works. If you listen to just the fell or rose events technically you would never know when the state is the opposite. To help, MudPi still checks for the actual pin state and uses this for what is stored. It is suggested to use the both option for edge_detection.

Additional events are exposed to interact with these edge detection changes. ControlPressed is emitted when a rose edge is detected and ControlReleased when a fell detected. These events are reveresed if invert_state is true.


Toggle Interface

Provides a toggle that can turn a GPIO pin on or off.

OptionTypeRequiredDescription
key[String]YesUnique slug id for the component
pin[String]YesGPIO pin to use on board i.e. D12 or A1.
name[String]NoFriendly display name of component. Useful for UI.
max_duration[Integer]NoFailsafe duration (in seconds) to turn off toggle after. 0 means off. Default 0
invert_state[Boolean]NoSet to True if toggle is off when pin is in HIGH state. Default False

Config

Here is a config of a complete gpio toggle.

"toggle": [{
    "key": "gpio_toggle_D12",
    "interface": "gpio",
    "name": "Light - Pin D12"
    "pin": "D12",
    "max_duration": 360,
    "invert_state": false
}]