gpio4
Control gpio in python on Linux.
Improved version based on Sysfs, features same as RPi.GPIO and gpio3
Support RaspberryPi / OrangePi / BananaPi...
Installation
Install from PyPI is suggested.
pip install gpio4
Or install from source.
git clone git@github.com:hankso/gpio4.git
cd gpio4
python setup.py build && sudo python setup.py install
Usage
Want something like RPi.GPIO?
>>> import gpio4.GPIO as GPIO
>>> GPIO.setmode(GPIO.BCM)
>>> GPIO.setup([12, 13], GPIO.IN)
>>> GPIO.input([12, 13])
[0, 0]
>>> p = GPIO.PWN(12) # Pin 12 will be set to output first
>>> p.start(30) # duty cycle is 30%
...
>>> from gpio4.constants import BOARD_NANO_PI as BOARD
>>> GPIO.setmode(BOARD)
>>> GPIO.setup([6, 7, 9], GPIO.OUTPUT)
>>> GPIO.output([6, 7, 9], [GPIO.HIGH, GPIO.LOW, GPIO.HIGH])
>>> GPIO.add_event_detect(8, GPIO.RAISING, bouncetime=300)
or call functions as you are using Arduino?
>>> from gpio4.arduino import *
>>> pinMode(13, OUTPUT)
>>> pinMode(12, INPUT_PULLUP)
>>> digitalWrite(13, HIGH)
>>> digitalWrite(13, digitalRead(12))
>>> shiftIn(dataPin=12, clockPin=13, bitOrder=MSBFIRST)
170
Try the most basic but fastest Sysfs class
>>> import select
>>> from gpio4 import SysfsGPIO
>>> from gpio4.constants import BOARD_ORANGE_PI_PC
>>> pin_name = 6
>>> pin_num = BOARD_ORANGE_PI_PC[pin_name]
>>> pin = SysfsGPIO(pin_num) # default path: /sys/class/gpio/gpio#n
>>> pin.export = True # register pin through sysfs
>>> pin.direction = 'out' # set Input/Output like `pinMode`
>>> pin.value = 1 # set High/Low like `digitalWrite`
>>> pin.active_low = 1 # High means 0V, Low means 5V (TTL)
>>> print(pin.value) # get current gpio level
>>> pin.export = False # unregister from sysfs
We also add support for SysfsLED since v0.1.0
>>> from gpio4 import SysfsLED
>>> led = SysfsLED('act') # default path: /sys/class/leds/act
>>> led.brightness = led.max_brightness # turn on LED
>>> led.brightness = 0 # turn off LED
>>> led.brightness = 0x80 # only works with PWM LED etc.
>>> led.trigger = 'timer' # now led should blink
>>> led.delay_on = 1000 # you can change blink speed in ms
>>> led.delay_off = 1000
And SysfsPWM since v0.1.3
>>> from gpio4 import SysfsPWM
>>> pwm = SysfsPWM(0) # default path: /sys/class/pwm/pwmchip0/pwm0
>>> pwm.frequency = 1250 # set period to 1 / 1.25kHz = 800000 ns
>>> pwm.percentage = 10 # set duty cycle to 10% = 80000 ns
>>> pwm.polarity = 'inversed' # change polarity only when not enabled
>>> pwm.enable = True # turn on/off pwm output
If you have any question on usage, it is strongly recommended to directly read well commented source codes.
Also check kernel doc of SysfsGPIO and kernel doc of SysfsPWM.
Metadata
Release files for gpio4 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gpio4-0.1.6.linux-x86_64.tar.gz | 21.4 kB | Without provenance | Details for gpio4-0.1.6.linux-x86_64.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gpio4-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for gpio4-0.1.6-py3-none-any.whl |
Total release size: 34.0 kB
Release files / gpio4-0.1.6.linux-x86_64.tar.gz
| Download URL | gpio4-0.1.6.linux-x86_64.tar.gz |
|---|---|
| Size | 21.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b55417825e762f9b18ceb13334dbfcfe65e558278fab2059fbd080678e6974e7
|
|
BLAKE2b-256 checksum How to use checksums |
0c5908b0c5e095b71263933e1460f77d727da2e63f5592b7d5c5bd40572e2fe7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.2
|
Release files / gpio4-0.1.6-py3-none-any.whl
| Download URL | gpio4-0.1.6-py3-none-any.whl |
|---|---|
| Size | 12.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
54d0a0fb6d29ef4060948dae312f421409c773943badeb4a5d0209f478e0056d
|
|
BLAKE2b-256 checksum How to use checksums |
14f7d76463c7c4c6b69aa62922deb2c12edc519d344e323476ab582179112178
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.2
|
Security for gpio4 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.