Package: serialize-gpio
Serialize GpioSerialize 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 forgpiozero, 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, visitgpiozero's documentation.InstallationDependenciesSerialize 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:~$sudoaptupdate
pi@raspberrypi:~$sudoaptinstallpython3-gpiozeroorpi@raspberrypi:~$sudopip3installgpiozeroIf 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:~$sudopip3installrpi.gpioDisclaimerWhile gpiozero supports Python 2, Serialize Gpio only supports Python 3.Installing Serialize GpioSerialize Gpio is available in the Python Package index, so you can install it using pip:pi@raspberrypi:~$sudopip3installserialize_gpioAlternatively; you can download it from thereleases pageand install it from that file or clone this repository and use it from source.UsageSerialize 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.fromserialize_gpio.controllerimportGPIOControllerfromserialize_gpio.messageManipulatorsimportJsonMessageManipulator#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)DocumentationYou can find the project's documentation it thewiki.