Sysfs GPIO utility
Project description
sysfsgpio
Python GPIO library, using Linux sysfs interface. This is a fork of trimarlib-sysfsgpio
project, originally hosted here.
Getting started
These instructions will get you a copy of the project on your local machine for development and testing purposes. See Deployment for notes on how to deploy the project on a live system.
Prerequisites
The build process requires some basic development tools:
make- GNU Make program, either for *nix or Windows system, used to execute build and test targetsgit- used not only to clone the repository, but also in auto-versioning (see Versioning)python3
Two standard Python packages are used for build and installation steps:
setuptoolswheel
Testing depends on nose package - this dependency is defined in setup.py and should be satisfied automatically.
The library itself has no dependencies on any third-party packages.
Building and releasing
Invoking make all (default target) executes test-suite and prepares archives for distribution.
It is done in two steps:
- query Git repository for tags (
git describecommand) to determine current version and generateversion.pyfile, - invoke Python interpreter passing
setup.pyscript to prepare source and wheel distributions.
The Python interpreter invoked by the Makefile defaults to python when running on Windows machine and
python3 otherwise. In both cases it is possible to override it passing a PYTHON variable to the command,
e.g. make all PYTHON=python3.
The release process is automated and based on GitLab CI/CD environment, see configuration file.
Testing
Test source files are located in sysfsgpio/tests directory. Testing is based on unittest Python
built-in package, nose is used as the test runner.
The Makefile defines test target which runs the test suite.
Testing is divided into two steps:
- utility functions testing - performs unit tests of all ancillary features. Those tests are platform independent (i.e. shall pass on either a *nix or a Windows machine);
Pintesting - performs unit tests ofPinclass. Those tests depend on thesysfsLinux filesystem and are skipped when running on Windows machine.
Deployment
The library is not intended to be used in a standalone configuration - the primary purpose is to be used
by higher-level applications, which should define it as a dependency. However it is perfectly correct
to install it manually using pip.
Please keep in mind that there are some platform dependent steps needed to be taken before the
pins are accessible without super-user privileges. The package designates 3 entry points (accessible
as command-line tools) to ease-up the set-up process (the scripts are developed and confirmed to be
working on Orange Pi platform running Armbian distribution). These entry points are:
sysfsgpio-install-service- this command installs and enablessystemdgpio-exporterservice, which exports all free pins available on the Orange Pi SBC at system boot;sysfsgpio-install-rules- this command installudevrules file which ensures that each exported pin hasrwmode available tostaffgroup;sysfsgpio-install- this one invokes the above to reduce number of commands needed to set-up system.
Each of the commands may be invoked with --force switch to overwrite existing files - without that
switch commands fail printing proper message.
NOTE: The user needs to become member of the
staffgroup to use the pins without super-user rights.
Versioning
The project is versioned using a simple pattern based on repository tagging feature. See Makefile for implementation details, for versions available see tags on this repository.
Usage
See docstrings for API documentation.
- Example of using pin PA21 as input:
from sysfsgpio import Pin
def callback(sender, value):
print('pin={}, value={}'.format(sender, value))
pin = Pin('PA21')
pin.direction = 'in'
pin.register_callback(callback)
pin.enabled = True
- Example of using pin PA20 as output:
from sysfsgpio import Pin
import time
pin = Pin('PA20')
pin.direction = 'out'
for i in range(10):
time.sleep(.1)
pin.value = pin.value ^ 1
- Example of using pin PA7 as inverted output to generate timed pulses:
from sysfsgpio import Pin
pin = Pin('PA20')
pin.direction = 'out'
pin.configuration = dict(ontime=3.33, offtime=6.67, repeat=3)
pin.enable()
License
This software is licensed under the MIT License - see LICENSE.
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 Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sysfsgpio-0.3.0-py3-none-any.whl.
File metadata
- Download URL: sysfsgpio-0.3.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
270d56a90b31213ea69b98397e13d6fe107bb7fbf3e50209ceae04c72215e3e5
|
|
| MD5 |
dd20b6677f312735aaba906fac979ee9
|
|
| BLAKE2b-256 |
f9792d13e67e5efb6c00e54d23f815ca26e2f16058d94129efcf6f58af280b19
|