This package provides additional suite of python based rpi abstraction for handling rpi hardware control.
Project description
This package provides additional suite of python based rpi abstraction for handling rpi hardware and data control. The package currently includes 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. The package also includes a module for handling usb mass storage device mounting, data dumping, and unmounting,and other data handling. Finally the Package also includes a module for common sensors.
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
GPIO Control Script
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"
}
USB Mass Storage Script
import time, os
from rpi_control_center import rpi_usb
storage_devices = rpi_usb.get_devices(True)
print(storage_devices)
for dev in storage_devices:
dev('test.txt')
time.sleep(5)
os.system(f'sudo ls {dev.mnt}')
dev.umnt_usb()
os.system(f'sudo ls /mnt')
CSV Handling Script
from rpi_control_center.data import csv_handler
test_data = {'hello': 13, 'poop':'34013'}
test_csv = csv_handler(filename='test_data')
test_csv(test_data)
print(test_csv.data_files)
print(test_csv.writing_to)
print(test_csv.total_size)
Sensor Monitoring
from rpi_sensor_monitors import monitors
env_sensor = monitors.BME680()
env_sensor.start()
time.sleep(60)
env_sensor.stop()
Hardware and drivers
List of Compatible Sensors
- BEM680
- any Ultrasonic sensor
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.2.2
- add ultrasonic sensor monitor
- get sensor reading from object directly
- add am2420 sensor class
- add dual camera (VERY SPECIFIC USECASE)
- change package architecture to include control module
- add pwm to control module
0.2.1
- add data module with csv handler class to the rpi_control_center package
0.2.0
- addition of rpi_monitors module for sensor interfacing (currently only DFRobot_BME680)
- add dependancies (smbus, spidev)
0.1.3
- add rpi_usb module for usb mass storage handling
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
Packaging Notes
- source venv/bin/activate
- python setup.py sdist bdist_wheel
- twine upload dist/* or twine upload --repository-url https://test.pypi.org/legacy/ dist/*
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.2.1.27.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13429a40d536f2d29aeb1779962e7d5123e96dcbfa508d81ba45b7b834d7d0ef |
|
MD5 | 961eba762246bcdb6002f49bc1f50f02 |
|
BLAKE2b-256 | f8a8c9e627c412511803a1f505de6a76b17b7bac8464f5bdfe87cea823d89ac9 |
Hashes for RPI_control_center-0.2.1.27-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81e95e3be8cc30e0f13712d9f43db1d078630c51739911d3f9ce392b4d4a1ea7 |
|
MD5 | 8da4a7f19a45be6812340c991b1ee0a4 |
|
BLAKE2b-256 | b8fba38ccfef4fd090d4f864e2a176046abba9bb1d0c75911089a1d3b850d3ae |