Skip to main content

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.

  • Documentation: Coming soon
  • Github

Installation

  • pip
pip install pi_common_sensors
  • source
git clone git@github.com:mohas95/pi_common_sensors.git
cd pi_common_sensors
pip install -r pip.txt

Example Usage

Control Scripts

Controlling relays

import time
from pi_common_sensors import controls

relay_config = {
        "relay1":{'pin':26, 'state':False, 'config':'no'},
        "relay2":{'pin':20, 'state':False, 'config':'no'},
        "relay3":{'pin':21, 'state':False, 'config':'no'},
}

relay_group1 = controls.relay_engine( relay_config=relay_config,
                             label='test_relays', 
                             api_dir='./api/', 
                             log_dir='./log/',
                             refresh_rate=1)

relay_group1.start()


######### You can put any code because this function is non-blocking
try:
    while True:
        time.sleep(5)
        relay_group1.set_relay_state('relay1',True)
        time.sleep(5)
        relay_group1.set_relay_state('relay2',True)
        time.sleep(5)
        relay_group1.set_relay_state('relay3',True)
        time.sleep(5)
        relay_group1.set_relay_state('relay1',False)
        time.sleep(5)
        relay_group1.set_relay_state('relay2',False)
        time.sleep(5)
        relay_group1.set_relay_state('relay3',False)
except:
    relay_group1.stop()

USB Mass Storage Script

import time, os
from pi_common_sensors 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 pi_common_sensors.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 scripts

K30 CO2 Sensor (Serial)

from pi_common_sensors import monitors

co2_sensor = monitors.K30_CO2(serial_device = "/dev/ttyS0", baudrate=9600, label='k30_CO2', api_dir='./api/', log_dir='./log/', refresh_rate=1)
co2_sensor.start()

try:
    while True:
        time.sleep(5)
except:
    co2_sensor.stop()

BME680 Sensor

from pi_common_sensors import monitors


env_sensor = monitors.BME680()
env_sensor.start()
time.sleep(60)
env_sensor.stop()

Hardware and drivers

List of Compatible Raspberry Pi boards

List of Compatible Sensors

  • BM680 (DFRobot flavor)
  • any Ultrasonic sensor
  • K30 CO2 Sensor

Feedback

All kinds of feedback and contributions are welcome.

Contributors

Change Log

0.3.0

0.2.3

  • Move relay controlling to controls module and simplify code
  • K30 CO2 Sensor compatability
  • add status indicators to api files

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


Download files

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

Source Distribution

pi_common_sensors-0.3.0.tar.gz (43.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pi_common_sensors-0.3.0-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

Details for the file pi_common_sensors-0.3.0.tar.gz.

File metadata

  • Download URL: pi_common_sensors-0.3.0.tar.gz
  • Upload date:
  • Size: 43.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for pi_common_sensors-0.3.0.tar.gz
Algorithm Hash digest
SHA256 45512eccb2ad28431cfb93f49c34f15351a5a16700dfd508a33fee3b176bcfbd
MD5 7808a9138d0f906ae99ab79bb0d1a9ca
BLAKE2b-256 708a7c76b6eacc74fb6ba7d74213387b571f6e2964826a0f7671a0eb1a13e498

See more details on using hashes here.

File details

Details for the file pi_common_sensors-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pi_common_sensors-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 93f1ede7cca65c49b64a3f0606bfbaa21fd6b1098785163839713d7b913383f9
MD5 a10fe633c41dc6bd901742d67014e259
BLAKE2b-256 2d0fca464d42d2463f6ec9b4edf618be021be0da16d8ab0b0bac02e4b6699bc5

See more details on using hashes here.

Supported by

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