A module to control BeagleBone IO channels
Project description
**PLEASE NOTE: This library may have breaking changes as development continues. Please read the changelog anytime you update the library!**
**The PWM Duty Cycle range was reversed in 0.0.15 from 100(off)-0(on) to 0(off)-100(on). Please update your code accordingly.**
**Adafruit's BeagleBone IO Python Library**
This is a set of Python tools to allow GPIO, PWM, and ADC access on the BeagleBone using the Linux 3.8 Kernel and above (latest releases).
It has been tested on the 5-20 and 6-6 Angstrom image on the BeagleBone Black.
**Note: BBIO has been renamed to Adafruit_BBIO.**
**Installation on Angstrom**
Easiest::
/usr/bin/ntpdate -b -s -u pool.ntp.org
opkg update && opkg install python-pip python-setuptools
pip install Adafruit_BBIO
Manual::
git clone git://github.com/adafruit/adafruit-beaglebone-io-python.git
#set the date and time
/usr/bin/ntpdate -b -s -u pool.ntp.org
#install dependency
opkg update && opkg install python-distutils
cd adafruit-beaglebone-io-python
python setup.py install
**Installation on Ubuntu/Debian**
Easiest::
sudo ntpdate pool.ntp.org
sudo apt-get update
sudo apt-get install build-essential python-dev python-pip -y
#easy_install -U distribute //debian only
sudo pip install Adafruit_BBIO
Manual::
sudo ntpdate pool.ntp.org
sudo apt-get update
sudo apt-get install build-essential python-dev python-pip -y
git clone git://github.com/adafruit/adafruit-beaglebone-io-python.git
cd adafruit-beaglebone-io-python
sudo python setup.py install
cd ..
sudo rm -rf adafruit-beaglebone-io-python
**Usage**
Using the library is very similar to the excellent RPi.GPIO library used on the Raspberry Pi. Below are some examples.
**GPIO Setup**
Import the library, and setup as GPIO.OUT or GPIO.IN::
import Adafruit_BBIO.GPIO as GPIO
GPIO.setup("P8_14", GPIO.OUT)
You can also refer to the pin names::
GPIO.setup("GPIO0_26", GPIO.OUT)
**GPIO Output**
Setup the pin for output, and write GPIO.HIGH or GPIO.LOW. Or you can use 1 or 0.::
import Adafruit_BBIO.GPIO as GPIO
GPIO.setup("P8_14", GPIO.OUT) GPIO.output("P8_14", GPIO.HIGH)
**On-Board LEDs**
On-board LEDs (USR0-USR3) are handled by LED class driver rather than the GPIO pin driver.
They have a different path in the /sys/ filesystem.
Setup the pin for output and write GPIO.HIGH or GPIO.LOW::
import Adafruit_BBIO.GPIO as GPIO
import time
for i in range(4):
GPIO.setup("USR%d" % i, GPIO.OUT)
while True:
for i in range(4):
GPIO.output("USR%d" % i, GPIO.HIGH)
time.sleep(1)
for i in range(4):
GPIO.output("USR%d" % i, GPIO.LOW)
time.sleep(1)
**GPIO Input**
Inputs work similarly to outputs.::
import Adafruit_BBIO.GPIO as GPIO
GPIO.setup("P8_14", GPIO.IN)
Polling inputs::
if GPIO.input("P8_14"):
print("HIGH")
else:
print("LOW")
Waiting for an edge (GPIO.RISING, GPIO.FALLING, or GPIO.BOTH::
GPIO.wait_for_edge(channel, GPIO.RISING)
or
GPIO.wait_for_edge(channel, GPIO.RISING, timeout)
Detecting events::
GPIO.add_event_detect("P9_12", GPIO.FALLING)
#your amazing code here
#detect wherever:
if GPIO.event_detected("P9_12"):
print "event detected!"
**PWM**::
import Adafruit_BBIO.PWM as PWM
#PWM.start(channel, duty, freq=2000, polarity=0)
#duty values are valid 0 (off) to 100 (on)
PWM.start("P9_14", 50)
PWM.set_duty_cycle("P9_14", 25.5)
PWM.set_frequency("P9_14", 10)
PWM.stop("P9_14")
PWM.cleanup()
#set polarity to 1 on start:
PWM.start("P9_14", 50, 2000, 1)
**ADC**::
import Adafruit_BBIO.ADC as ADC
ADC.setup()
#read returns values 0-1.0
value = ADC.read("P9_40")
#read_raw returns non-normalized value
value = ADC.read_raw("P9_40")
**Running tests**
Install py.test to run the tests. You'll also need the python compiler package for py.test.::
opkg update && opkg install python-compiler
#Either pip or easy_install
pip install -U pytest
easy_install -U pytest
Execute the following in the root of the project::
py.test
**Credits**
The BeagleBone IO Python library was originally forked from the excellent MIT Licensed [RPi.GPIO](https://code.google.com/p/raspberry-gpio-python) library written by Ben Croston.
**License**
Written by Justin Cooper, Adafruit Industries. BeagleBone IO Python library is released under the MIT License.
1.0.1
----
* Merge pull request #124 from jpbarraca/master [cf9771a]
* Timeout support for wait_for_edge (replaces PR #62)
* Merge pull request #123 from bubbapizza/master [8b4f7f2]
* Added a delay parameter for GPIO.setup() for udev permissions
* Merge pull request #121 from dengber/master [50e8883]
* ADC.read() returns wrong value
* Merge pull request #64 from olegantonyan/master [d1e8dc1]
* Wait until GPIO file appears on the /sys filesystem (issue #36)
* Merge pull request #106 from cocasema/master [12b79d7]
* Treat warnings as errors
* Merge pull request #119 from JesseMcL/pr [e7e987a]
* Add GPIO pullup configurations and fix PWM Segfault on kernel 4.1+
* Merge pull request #116 from kozga/master [1b04cdf]
* Fix SPI: IOError: [Errno 22] Invalid argument in xfer and xfer2 funct…
1.0.0
----
* Merge pull request #108 from MatthewWest for PWM support in Linux kernel 4.1+
* Merge pull request #96 from PeteLawler for ADC support in Linux kernel 4.1+
* Finally publish new version to PyPi
* Bump major version number to signify long duration since last release
0.0.30
-----
* Merge Python 3 compatibility fixes from Github user westphahl.
* Moved old Angstrom build fix for missing py_compile from setup.py to separate file.
0.0.20
----
* Fix for SPI not loading spidevX.X correctly based on load order
* Initialize ctrl_dir in unload_device_tree #63
* Clean up unused/dead code
0.0.19
----
* Fix for SPI.xfer crashes python after 3 calls
* Added a retry to reading for the analog inputs to avoid a bug where reading back and forth between two analog inputs would cause the resource to be unavailable every 16 scans (zthorson)
* Updated the build_path to be more selective over what paths it chooses (zthorson)
* Update Debian installation instructions in README (justinledwards)
* Increase the size of the buffer used for storing device tree names (SaintGimp)
0.0.18
----
* UART - Include UART overlays, and compile upon installation
* UART - Rename UART overlays
* Adafruit_I2C - Remove readU16Rev and readS16Rev
* Adafruit_I2C - Updated readU16/readS16 for correct 16-bit reads
0.0.17
----
* Fix SPI memory leaks
* Clean up of PWM code (bit-hacker, jwcooper)
* Remove UART debug statements
0.0.16
----
* Add polarity as optional fourth parameter to PWM.start(). Valid values are 0 and 1. Default is still 0.
* Fix for actually setting the polarity in start.
* Add new unit tests to check that the polarity is being set properly, and valid values passed in.
0.0.15
----
* Fix PWM duty cycle so 0 is off and 100 is on. Set polarity to 0 by default.
* Give extra buffer space in export, and unexport functions for gpio that are more than 2 digits (Chris Desjardins)
* Add new test case for 3 digit gpio (Chris Desjardins)
* Fix for test_direction_readback. gpio_get_direction wasn't properly null terminating the direction string (Chris Desjardins)
0.0.14
----
* Fix GPIO.gpio_function to work with the IO name (zthorson)
* Fix IOErrors not getting raised when fopen fails while loading overlays into device tree (bradfordboyle, jwcooper)
* Add new UART tests
0.0.13
----
* Remove the gpio parameter from callbacks (cdesjardins)
0.0.12
----
* Bump version due to pypi issues
0.0.11
----
* New UART module to export UART overlays
* Alpha support for SPI
* Add small delay after loading any device tree overlays
0.0.10
____
* Fix direction for event detection code
* Fix for segmentation faults on add_event_detect
0.0.9
____
* Fix for ADC Segmentation Faults
0.0.8
____
* Temp remove overlay compilation. Ubuntu failures.
0.0.7
____
* Refactor and clean up adc and pwm
* Fix tests for Adafruit_BBIO rename
0.0.6
____
* Include Adafruit_I2C.py as top-level module
0.0.5
----
* Rename from BBIO to Adafruit_BBIO to reduce library conflicts and confusion.
0.0.4
----
* Support for pip and easy_install
0.0.3
____
* ADC enabled
0.0.2
____
* PWM enabled
0.0.1
____
* Initial Commit
* GPIO mostly working
* Initial GPIO unit tests
* PWM in progress
**The PWM Duty Cycle range was reversed in 0.0.15 from 100(off)-0(on) to 0(off)-100(on). Please update your code accordingly.**
**Adafruit's BeagleBone IO Python Library**
This is a set of Python tools to allow GPIO, PWM, and ADC access on the BeagleBone using the Linux 3.8 Kernel and above (latest releases).
It has been tested on the 5-20 and 6-6 Angstrom image on the BeagleBone Black.
**Note: BBIO has been renamed to Adafruit_BBIO.**
**Installation on Angstrom**
Easiest::
/usr/bin/ntpdate -b -s -u pool.ntp.org
opkg update && opkg install python-pip python-setuptools
pip install Adafruit_BBIO
Manual::
git clone git://github.com/adafruit/adafruit-beaglebone-io-python.git
#set the date and time
/usr/bin/ntpdate -b -s -u pool.ntp.org
#install dependency
opkg update && opkg install python-distutils
cd adafruit-beaglebone-io-python
python setup.py install
**Installation on Ubuntu/Debian**
Easiest::
sudo ntpdate pool.ntp.org
sudo apt-get update
sudo apt-get install build-essential python-dev python-pip -y
#easy_install -U distribute //debian only
sudo pip install Adafruit_BBIO
Manual::
sudo ntpdate pool.ntp.org
sudo apt-get update
sudo apt-get install build-essential python-dev python-pip -y
git clone git://github.com/adafruit/adafruit-beaglebone-io-python.git
cd adafruit-beaglebone-io-python
sudo python setup.py install
cd ..
sudo rm -rf adafruit-beaglebone-io-python
**Usage**
Using the library is very similar to the excellent RPi.GPIO library used on the Raspberry Pi. Below are some examples.
**GPIO Setup**
Import the library, and setup as GPIO.OUT or GPIO.IN::
import Adafruit_BBIO.GPIO as GPIO
GPIO.setup("P8_14", GPIO.OUT)
You can also refer to the pin names::
GPIO.setup("GPIO0_26", GPIO.OUT)
**GPIO Output**
Setup the pin for output, and write GPIO.HIGH or GPIO.LOW. Or you can use 1 or 0.::
import Adafruit_BBIO.GPIO as GPIO
GPIO.setup("P8_14", GPIO.OUT) GPIO.output("P8_14", GPIO.HIGH)
**On-Board LEDs**
On-board LEDs (USR0-USR3) are handled by LED class driver rather than the GPIO pin driver.
They have a different path in the /sys/ filesystem.
Setup the pin for output and write GPIO.HIGH or GPIO.LOW::
import Adafruit_BBIO.GPIO as GPIO
import time
for i in range(4):
GPIO.setup("USR%d" % i, GPIO.OUT)
while True:
for i in range(4):
GPIO.output("USR%d" % i, GPIO.HIGH)
time.sleep(1)
for i in range(4):
GPIO.output("USR%d" % i, GPIO.LOW)
time.sleep(1)
**GPIO Input**
Inputs work similarly to outputs.::
import Adafruit_BBIO.GPIO as GPIO
GPIO.setup("P8_14", GPIO.IN)
Polling inputs::
if GPIO.input("P8_14"):
print("HIGH")
else:
print("LOW")
Waiting for an edge (GPIO.RISING, GPIO.FALLING, or GPIO.BOTH::
GPIO.wait_for_edge(channel, GPIO.RISING)
or
GPIO.wait_for_edge(channel, GPIO.RISING, timeout)
Detecting events::
GPIO.add_event_detect("P9_12", GPIO.FALLING)
#your amazing code here
#detect wherever:
if GPIO.event_detected("P9_12"):
print "event detected!"
**PWM**::
import Adafruit_BBIO.PWM as PWM
#PWM.start(channel, duty, freq=2000, polarity=0)
#duty values are valid 0 (off) to 100 (on)
PWM.start("P9_14", 50)
PWM.set_duty_cycle("P9_14", 25.5)
PWM.set_frequency("P9_14", 10)
PWM.stop("P9_14")
PWM.cleanup()
#set polarity to 1 on start:
PWM.start("P9_14", 50, 2000, 1)
**ADC**::
import Adafruit_BBIO.ADC as ADC
ADC.setup()
#read returns values 0-1.0
value = ADC.read("P9_40")
#read_raw returns non-normalized value
value = ADC.read_raw("P9_40")
**Running tests**
Install py.test to run the tests. You'll also need the python compiler package for py.test.::
opkg update && opkg install python-compiler
#Either pip or easy_install
pip install -U pytest
easy_install -U pytest
Execute the following in the root of the project::
py.test
**Credits**
The BeagleBone IO Python library was originally forked from the excellent MIT Licensed [RPi.GPIO](https://code.google.com/p/raspberry-gpio-python) library written by Ben Croston.
**License**
Written by Justin Cooper, Adafruit Industries. BeagleBone IO Python library is released under the MIT License.
1.0.1
----
* Merge pull request #124 from jpbarraca/master [cf9771a]
* Timeout support for wait_for_edge (replaces PR #62)
* Merge pull request #123 from bubbapizza/master [8b4f7f2]
* Added a delay parameter for GPIO.setup() for udev permissions
* Merge pull request #121 from dengber/master [50e8883]
* ADC.read() returns wrong value
* Merge pull request #64 from olegantonyan/master [d1e8dc1]
* Wait until GPIO file appears on the /sys filesystem (issue #36)
* Merge pull request #106 from cocasema/master [12b79d7]
* Treat warnings as errors
* Merge pull request #119 from JesseMcL/pr [e7e987a]
* Add GPIO pullup configurations and fix PWM Segfault on kernel 4.1+
* Merge pull request #116 from kozga/master [1b04cdf]
* Fix SPI: IOError: [Errno 22] Invalid argument in xfer and xfer2 funct…
1.0.0
----
* Merge pull request #108 from MatthewWest for PWM support in Linux kernel 4.1+
* Merge pull request #96 from PeteLawler for ADC support in Linux kernel 4.1+
* Finally publish new version to PyPi
* Bump major version number to signify long duration since last release
0.0.30
-----
* Merge Python 3 compatibility fixes from Github user westphahl.
* Moved old Angstrom build fix for missing py_compile from setup.py to separate file.
0.0.20
----
* Fix for SPI not loading spidevX.X correctly based on load order
* Initialize ctrl_dir in unload_device_tree #63
* Clean up unused/dead code
0.0.19
----
* Fix for SPI.xfer crashes python after 3 calls
* Added a retry to reading for the analog inputs to avoid a bug where reading back and forth between two analog inputs would cause the resource to be unavailable every 16 scans (zthorson)
* Updated the build_path to be more selective over what paths it chooses (zthorson)
* Update Debian installation instructions in README (justinledwards)
* Increase the size of the buffer used for storing device tree names (SaintGimp)
0.0.18
----
* UART - Include UART overlays, and compile upon installation
* UART - Rename UART overlays
* Adafruit_I2C - Remove readU16Rev and readS16Rev
* Adafruit_I2C - Updated readU16/readS16 for correct 16-bit reads
0.0.17
----
* Fix SPI memory leaks
* Clean up of PWM code (bit-hacker, jwcooper)
* Remove UART debug statements
0.0.16
----
* Add polarity as optional fourth parameter to PWM.start(). Valid values are 0 and 1. Default is still 0.
* Fix for actually setting the polarity in start.
* Add new unit tests to check that the polarity is being set properly, and valid values passed in.
0.0.15
----
* Fix PWM duty cycle so 0 is off and 100 is on. Set polarity to 0 by default.
* Give extra buffer space in export, and unexport functions for gpio that are more than 2 digits (Chris Desjardins)
* Add new test case for 3 digit gpio (Chris Desjardins)
* Fix for test_direction_readback. gpio_get_direction wasn't properly null terminating the direction string (Chris Desjardins)
0.0.14
----
* Fix GPIO.gpio_function to work with the IO name (zthorson)
* Fix IOErrors not getting raised when fopen fails while loading overlays into device tree (bradfordboyle, jwcooper)
* Add new UART tests
0.0.13
----
* Remove the gpio parameter from callbacks (cdesjardins)
0.0.12
----
* Bump version due to pypi issues
0.0.11
----
* New UART module to export UART overlays
* Alpha support for SPI
* Add small delay after loading any device tree overlays
0.0.10
____
* Fix direction for event detection code
* Fix for segmentation faults on add_event_detect
0.0.9
____
* Fix for ADC Segmentation Faults
0.0.8
____
* Temp remove overlay compilation. Ubuntu failures.
0.0.7
____
* Refactor and clean up adc and pwm
* Fix tests for Adafruit_BBIO rename
0.0.6
____
* Include Adafruit_I2C.py as top-level module
0.0.5
----
* Rename from BBIO to Adafruit_BBIO to reduce library conflicts and confusion.
0.0.4
----
* Support for pip and easy_install
0.0.3
____
* ADC enabled
0.0.2
____
* PWM enabled
0.0.1
____
* Initial Commit
* GPIO mostly working
* Initial GPIO unit tests
* PWM in progress
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 Distribution
Adafruit_BBIO-1.0.1.tar.gz
(45.9 kB
view details)
File details
Details for the file Adafruit_BBIO-1.0.1.tar.gz
.
File metadata
- Download URL: Adafruit_BBIO-1.0.1.tar.gz
- Upload date:
- Size: 45.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a354d8c4d7b07cf1efb90a1bc3db5672f6b73eae68be108ca3b9aff04d7d190 |
|
MD5 | c91021bef570261b26a967113c858c5e |
|
BLAKE2b-256 | c411aa490e029b7c3283cb7bf77113a8f6f31b1250dcb5fa91474493293770c2 |