Simple python module to interact with BlackSwift GPIO. Based on articles by BlackSwift developers: on wiki and on habrahabr. This module uses fast "direct gpio register access" method. It means that this library is working with AR9331's registers directly. Use it with care.
- Download .ipk from releases tab or build it yourself (see section below)
- Copy it to your BlackSwift
- Run
opkg install bsb_io
- Download and install OpenWrt SDK from the second article
- Clone this repo to
packages
directory of OpenWrt SDK. - In
make menuconfig
sectionLanguages->
in subsectionPython->
selectbsb_io
- Run
make
if you want to build whole distribution ormake package/bsb_io/install
to build only bsb_io with dependencies. - Locate .ipk in
bin/ar71xx/packages/base/
N.B. This module can be built with Cython 0.11 (Used by current OpenWrt BarrierBreaker Buildroot). If version of Cython in your Buildroot is higher, you would probably need to change setup.py
.
There is only one class Pin
. It's constructor accepts GPIO number.
You can change GPIO direction (input or output) by writing direction
property.
You can read and write GPIO using value
property.
You can modify pin state i.e. both value and direction using state
propery.
This code toggles GPIO1 every 2 seconds:
import time
from bsb_io import *
p1 = Pin(1)
p1.direction = OUTPUT
v = 1
while True:
if v==1:
v = OFF
print "[OFF]\r"
else:
v = ON
print "[ON ]\r"
p1.value = v
time.sleep(2)
- Implement simple, yet configurable soft PWM.
- Implement slow gpio method via SysFs