gpio
Platypush documentation
gpio
- class platypush.plugins.gpio.GpioPlugin(pins: Optional[Dict[str, int]] = None, monitored_pins: Optional[Collection[Union[str, int]]] = None, mode: str = 'board', **kwargs)[source]
Bases:
RunnablePlugin
This plugin can be used to interact with custom electronic devices connected to a Raspberry Pi (or compatible device) over GPIO pins.
Requires:
RPi.GPIO (
pip install RPi.GPIO
)
Triggers:
platypush.message.event.gpio.GPIOEvent
when the value of amonitored PIN changes.
- __init__(pins: Optional[Dict[str, int]] = None, monitored_pins: Optional[Collection[Union[str, int]]] = None, mode: str = 'board', **kwargs)[source]
- Parameters:
mode – Specify
board
if you want to use the board PIN numbers,bcm
for Broadcom PIN numbers (default:board
)pins – Custom GPIO name -> PIN number mapping. This can be useful if you want to reference your GPIO ports by name instead of PIN number.
Example:
pins: LED_1: 14, LED_2: 15, MOTOR: 16, SENSOR_1: 17 SENSOR_2: 18
- Parameters:
monitored_pins – List of PINs to monitor. If a new value is detected on these pins then a
platypush.message.event.gpio.GPIOEvent
event will be triggered. GPIO PINS can be referenced either by number or name, if a name is specified on the pins argument.
- read(pin: Union[int, str], name: Optional[str] = None) Dict[str, Any] [source]
Reads a value from a PIN.
- Parameters:
pin – PIN number or configured name.
name – Optional name for the read value (e.g. “temperature” or “humidity”)
Response:
output = { "name": <pin number or pin/metric name>, "pin": <pin>, "value": <value>, "method": "read" }
- read_all()[source]
Reads the values from all the configured PINs and returns them as a list. It will raise a RuntimeError if no PIN mappings were configured.
- write(pin: Union[int, str], value: Union[int, bool], name: Optional[str] = None) Dict[str, Any] [source]
Write a byte value to a pin.
- Parameters:
pin – PIN number or configured name
name – Optional name for the written value (e.g. “temperature” or “humidity”)
value – Value to write
Response:
output = { "name": <pin or metric name>, "pin": <pin>, "value": <value>, "method": "write" }