Skip to main content

This package provides an abstraction layer and API engine for the RPi.GPIO package for python, which allows for multi-process and non-blocking control of GPIO pins.

Project description

This package provides an abstraction layer and API engine for the RPi.GPIO package for python, which allows for multi-process and non-blocking control of GPIO pins. With this package you can start the GPIO Engine, and control the output pins for relay control/ actuation using a json configuration files, while your code performs other operations. This allows for relative real time control* of the GPIO pins(~<1s scale). This package also provides real-time api of the status for external logging or communication.Using the JSON protocol for the api we can allow for user control and information logging. For now this package only handles GPIO output but will feature input control in the near future.

*Note: While this package provides multi-process control of the GPIO pins for near real-time control, jitter can vary considerably due to the nature of Linux OS and python's garbage collection. For now refresh rate is by default set to 1 second to mitigate issue of jitter to a known scale, but we cannot guarantee performance if refresh rate is set to 0.

  • Documentation: Coming soon
  • GitLab

Installation

  • pip
pip install rpi_control_center
  • source
git clone https://gitlab.com/moha7108/rpi-control-center.git
cd rpi-control-center
pip install -r requirements.txt

Example Usage

import time
from rpi_control_center import GPIO_engine

## please note configuration must be in this format incase of missing file, file corruption, and other errors
default_relay_config = {
        "1":{'name':'name1', 'pin':26, 'state':False},
        "2":{'name':'name2', 'pin':20, 'state':False},
        "3":{'name':'name3', 'pin':21, 'state':False},
}

control_box = GPIO_engine()
control_box = BulkUpdater(
                            config_file = './relay_config.json',
                            api_dir = './api',
                            default_config = default_relay_config,
                            refresh_rate = 1
                          )
control_box.start()
######### You can put any code because this function is non-blocking
try:
    while True:
        time.sleep(5)
except:
    control_box.stop()

Configuration/ API Files

  • pin configuration file (ie. relay_config.json, this example is a 3 GPIO pin configuration, once instantiated the state can be changed in the file and the change will be reflected in the gpio pin)
{
    "1": {
        "name": "name1",
        "pin": 26,
        "state": false
    },
    "2": {
        "name": "name2",
        "pin": 20,
        "state": false
    },
    "3": {
        "name": "name3",
        "pin": 21,
        "state": false
    }
}
  • API file (json file that is constantly updated with the status of a certain pin)
{
    "id": "1",
    "name": "name1",
    "pin": 26,
    "status": false,
    "last updated": "2021/08/16 17:03:49"
}

Hardware and drivers

Hardware

System Libraries

cd
sudo apt update
sudo apt list --upgradeable
sudo apt ugrade
sudo apt autoremove

sudo apt-get install wiringpi
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v
sudo apt-get install libopenjp2-7 -y
sudo apt-get install libatlas-base-dev -y
sudo apt install libtiff -y
sudo apt install libtiff5 -y
sudo apt-get install -y i2c-tools

Feedback

All kinds of feedback and contributions are welcome.

Contributors

Change Log

0.1.0

  • Logging via logzero, ability to suppress debug level logs when debug_mode is off
  • create log and api folders when they do not exist
  • all previous versions are pre release, this is the first working release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

RPI-control-center-0.1.0.tar.gz (19.9 kB view hashes)

Uploaded Source

Built Distribution

RPI_control_center-0.1.0-py3-none-any.whl (20.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page