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.
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.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
- Raspberrypi 3B+
- OS: Rasbian Buster +
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.
- Create an issue
- Create a pull request
- Reach out to @moha7108
Contributors
Change Log
0.1.2
- fix minor error in test and example code
0.1.1
- Change host to github for better community issue tracking and documentation, functionally the same as previous version
- gitlab will be used as a mirror
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
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
Hashes for RPI_control_center-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aee17f4c8dae084438997d17850ea13595133258437fa60b9178ea4c07d7993a |
|
MD5 | bce9ee7dceb9f8aaab25df96edba9a16 |
|
BLAKE2b-256 | b7b4c203487b9508822d596680ca2fe2962715946c01a3a6d2c9ef607e61bd0e |