Coder Social home page Coder Social logo

pidevices's Introduction

pidevices

Overview

Pidevices is a python3 library whose main goal is the easy deployment of peripheral devices for the raspberry pi. A peripheral device could be anything that get’s connected to the pi. Pidevices organize the devices in two categories; sensors, which are devices that acquire information from the environment and actuators that affect the environment.

To make things easier for the maker/developer, pidevices use a common interface consisting of three functions start(), stop() and restart(). The differentiation between sensors and actuators is a read() function that belongs to sensors and a write() function that belongs only to actuatos.

With that in mind, a developer can contribute a new sensor or effector by just implementing these four functions and then any user could use it without having to know the specific implementation.

In order to accomplish that pidevices abstracts all hardware interfaces by a common api that has 4 main functions initialize(), read(), write() and close(). So when the development of a new driver is concerned, the programmer can focus on the device protocol and not get distracted by the underling protocol library.

This abstraction is done using inheritance of abstract protocol classes. For example the SPI class defines the attributes and the abstract functions of the SPI interface in general and then an SPI_Implementation class inherits it and fills the functions and the setters/getters of the parent class using a specific protocol library e.x. spidev2. Basically the implementations are wrappers of the specific library but they follow a common interface so the programmer doesn’t have to know how to use the specific protocol libraries.

Hardware Interfaces Support

The library supports GPIO, I2C, SPI and HPWM(hardware pwm) hardware interfaces. Also in the future it will support UART.

For those interfaces the following wrappers have been implemented for existing libraries:

Also for the GPIO interface a wrapper using the mcp23017 chip has been implemented .

Drivers Implementation

Pidevices support multiple implementations of device drivers using different underlying libraries and hardware interfaces. For example there is an implementation for a single button using RPi.GPIO library and one using the custom mcp23017 gpio expander. These two implementations go by the names ButtonRpiGPIO and ButtonMcp23017.

Installation

First type

sudo apt install python3-numpy
sudo apt install python3-scipy

then install pygame module which is a prerequisite for the touch screen driver

pip install pygame

and then from the project's top level directory type

pip install .

Configuration

For using some of the device drivers additional configuration steps should be done.

HPWMPeriphery interface

  • Enable kernel support for hardware PWM. For kernel 4.9 edit file /boot/config.txt and add

    dtoverlay=pwm-2chan
    

    For earlier kernels more information here.

  • Add udev rule for adding /sys/class/pwm folder and it's files in the gpio group. Append the following lines in the /etc/udev/rules.d/99-com.rules file or make a new one with custom udev rules.

    SUBSYSTEM=="pwm*", PROGRAM="/bin/sh -c '\
         chown -R root:gpio /sys/class/pwm && chmod -R 770 /sys/class/pwm;\
         chown -R root:gpio /sys/devices/platform/soc/*.pwm/pwm/pwmchip* && chmod -R 770 /sys/devices/platform/soc/*.pwm/pwm/pwmchip*\
    '"
    

    An example of that file can be found in the conf_files folder with the name 97-pwm.rules.

Speaker and Microphone

The speaker and microphone drivers need the pyalsaaudio module to work. Also because the module uses the underlying alsa interface, a consistent name should be given to the devices. For the currently implemented devices the following two extra steps need to be performed.

  • Give the name "Speaker" to the speaker device in the asoundrc configuration file. Or use the example file from the config_files folder with the following command.
    cp conf_files/asoundrc ~/.asoundrc
  • Make a udev rule for consistent naming of the same devices across different boots. Or copy the example from the config_file folder.
    cp conf_files/98-alsa.rules /etc/udev/rules.d/

Also a folder wav_sounds should be created inside the project.

Attension This udev rule work only for this microphone and this speaker. The library doesn't support other devices for now.

Touch Screen

The touch screen driver is written on top of pygame module. The only screen that is currently supported is this.

In order to properly work, the instructions from the above link have to be followed for configuring the raspberry to support the hardware.

Usage

Example:

from pidevices import ButtonRPiGPIO

Example use cases of almost any driver can be found in tests folder.

Docs

The pidevices api documentation can be found here.

License

MIT

pidevices's People

Contributors

iparaskev avatar klpanagi avatar etsardou avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.