Python library for controlling Raspberry Pi® GPIO Pins through a serializable message protocol.
Project description
Serialize Gpio
Serialize Gpio is a Python library that provides tools for manipulating Raspberry Pi® GPIO pins using a serializable message protocol. These messages are modelled with Python dictionaries, but can also be encoded into either JSON or XML format. Using one of these two formats allows you to easily interact with the pins remotely or from an application which doesn't have access to a library for doing so.
At it's core; Serialize Gpio is a wrapper for gpiozero, which provides a simple interface for managing the GPIO pins. That library abstracts away lower level concerns using device classes, which go from simple ones like 'LED' or 'Button' to more complex ones like 'Robot' (a representation of a generic dual motor robot). Of course, it also supports more general classes such as 'DigitalOutputDevice'.
You can interact with these device objects through:
- Their methods ( such as LED.on() )
- Their properties, each falling into one of two categories:
- Properties which take functions which will be executed when certain event happens (such as Button.when_pressed)
- Properties which take literal values (such as Button.hold_time)
For more information on the available device classes and their corresponding attributes, visit gpiozero's documentation.
Installation
Dependencies
Serialize Gpio directly depends on gpiozero, which comes already installed by default in the Raspbian image. If you are using Raspbian Lite, you can install it with:
pi@raspberrypi:~$ sudo apt update
pi@raspberrypi:~$ sudo apt install python3-gpiozero
or
pi@raspberrypi:~$ sudo pip3 install gpiozero
If you are using a different operating system, you might need to use the pip version.
Also, it's recommended that you install RPi.GPIO if you don't have it installed already. Gpiozero can use multiple libraries for controlling the pins or a custom implementation if none are availabe. Nonetheless, the prefered implementation is RPi.GPIO. You can install it with:
pi@raspberrypi:~$ sudo pip3 install rpi.gpio
Disclaimer
While gpiozero supports Python 2, Serialize Gpio only supports Python 3.
Installing Serialize Gpio
Serialize Gpio is available in the Python Package index, so you can install it using pip:
pi@raspberrypi:~$ sudo pip3 install serialize_gpio
Alternatively; you can download it from the releases page and install it from that file or clone this repository and use it from source.
Usage
Serialize Gpio provides the GPIOController object to interface with the GPIO pins. Through the method 'handle_message', it receives a message and execute the action it describes.
Message manipulators are used for building, encoding and decoding messages. Use BasicMessageManipulator for messages in dictionary format, JsonMessageManipulator for JSON and XMLMessageManipulator for XML.
from serialize_gpio.controller import GPIOController
from serialize_gpio.messageManipulators import JsonMessageManipulator
#The GPIOController constructor takes desired message format as a parameter.
controller = GPIOController('json')
messageBuilder = JsonMessageManipulator()
# The build_create_device_message method takes the name of device class, the name you want
# to assign to device and the keyword arguments for the classes' __init__ method.
create_led_message = messageBuilder.build_create_device_message('LED', 'blinkingLED', pin=4)
controller.handle_message(create_led_message)
# Make the led blink
# build_execute_device_method_message takes the device's name, the name of the method and
# keyword arguments for any method arguments.
execute_blink_message = messageBuilder.build_execute_device_method_message('blinkingLED', 'blink', on_time=0.5)
controller.handle_message(execute_blink_message)
Documentation
You can find the project's documentation it the wiki.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file serialize_gpio-0.1.0.tar.gz
.
File metadata
- Download URL: serialize_gpio-0.1.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.4.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b6cf05c648bbe74804f777eb45b4810b0956a0bc8e0dfbbd98bad54bf99614d |
|
MD5 | 037cb60ed112a8fa5eba4ed5e767dacf |
|
BLAKE2b-256 | 2399c4d74037339bb644572ce41cd5733da836a464333a0242bc5e7626c8967a |
File details
Details for the file serialize_gpio-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: serialize_gpio-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.4.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 415efac784114d03ec76e4a337975e211f65dee0cbc644080c50cdfaafc8e12d |
|
MD5 | 97e591fe6a74102b70d86f8846634c3a |
|
BLAKE2b-256 | ba66446dabe736da8b8dc6040c5d6672332ab45a63d22f7ffc4290594fcc3931 |