No description
Find a file
Drew Fustini f64382b8db
create release 1.0.9
Features:
  * Issue #194: Encoder position cannot be set
  * PR #205: Encoder: add support for reading/writing sysfs attributes

Fixes:
  * Issue #198: use https for DEFAULT_URL in distribute_setup.py
  * Issue #197: Fix leak of pwm enable file descriptor
  * Issue #189: Fix seg fault of PWM in Python 3.6
  * Issue #180: Clarify there is no 0 prefix for pin lables
  * PR #201: Encoder: do kernel check, PEP8 cleanup
  * PR #202: Encoder: corrected kernel check logic
  * PR #207: Encoder: improved usage adocumentation
  * PR #210: Encoder: fix sysfs import, make code Python 3 compatible
  * PR #212: Encoder: fix Python 3 compatibility
  * PR #213: Encoder: fix frequency calculation from period

shortlog:

* David Planella (18):
  * Encoder: initialize only the given channel
  * Sync from master
  * Encoder: do kernel check, PEP8 cleanup
  * Encoder: added sysfs module
  * Encoder: use sysfs to write QEP attributes
  * Encoder: corrected kernel check logic
  * Merge pull request #2 from adafruit/master
  * Encoder: convert get/set methods to properties, update apidoc strings
  * Encoder: updated README
  * Encoder: add README apt install clarification
  * Encoder: copyright assignment note, updated comments
  * Encoder: added usage notes
  * Encoder: improved usage documentation
  * Encoder: minor fix to usage example
  * Encoder: added a note about permissions
  * Encoder: switched sysfs to be a relative import compatible with Python 2 and 3
  * Encoder: use items() instead of iteritems() to be Python 3 compatible
  * Encoder: fix frequency getter

* Drew Fustini (18):
  * use https for DEFAULT_URL in distribute_setup.py (#198)
  * fix except syntax for Python 3
  * use dict.items() instead of dict.iteritems() for Python 3
  * fix error in set_brightness()
  * close enable_fd when stopping PWM output (#197)
  * Merge pull request #199 from dplanella/patch-1
  * Fix leak of pwm enable file descriptor (#197)
  * Merge pull request #201 from dplanella/encoder-cleanup
  * remove test_rotary.py as not valid for pytest
  * Fix seg fault of PWM in Python 3.6 (#189)
  * Merge pull request #202 from dplanella/patch-2
  * Clarify there is no 0 prefix for pin lables (#180)
  * Merge pull request #205 from dplanella/encoder-sysfs
  * assign copyright for new file to Adafruit Industries
  * Add bash scripts to help install and test
  * Merge pull request #212 from dplanella/patch-4
  * Merge pull request #207 from dplanella/patch-3
  * Merge pull request #213 from dplanella/fix-encoder-frequency

Signed-off-by: Drew Fustini <drew@pdp7.com>
2017-11-30 20:31:39 -06:00
.github Add GitHub pull request template 2016-05-27 13:23:46 -07:00
Adafruit_BBIO Merge pull request #213 from dplanella/fix-encoder-frequency 2017-11-30 19:34:57 -06:00
doc Update rotary-encoder-eqep-test.md 2017-08-31 21:58:42 -05:00
m4 Add PWM c++ tests 2017-03-31 02:17:00 -07:00
overlays Add -Wno-unit_address_vs_reg to avoid dtc warning 2017-09-01 04:36:55 +00:00
source Fix seg fault of PWM in Python 3.6 (#189) 2017-11-25 05:24:44 -06:00
test remove test_rotary.py as not valid for pytest 2017-11-25 05:04:55 -06:00
udev add udev rules and script for non-root access to gpio 2017-04-04 04:27:04 +00:00
.gitignore Add 2 versions of library with c++98 and c++11 abi 2017-03-31 02:17:00 -07:00
.travis.yml Testing: Create Tox and Travis CI config 2015-05-13 10:52:29 +02:00
Adafruit_I2C.py Add support for Python 3 2015-05-06 08:29:00 +02:00
CHANGELOG.md create release 1.0.9 2017-11-30 20:31:39 -06:00
configure.ac Instruct users to open GitHub issue instead email 2017-04-02 07:23:41 -05:00
distribute_setup.py use https for DEFAULT_URL in distribute_setup.py (#198) 2017-11-22 01:16:08 -06:00
fix_py_compile.py Add support for Python 3 2015-05-06 08:29:00 +02:00
install_all_python_versions.sh Add bash scripts to help install and test 2017-11-30 02:20:52 -06:00
Makefile Removed --force to speed things up 2017-07-28 15:36:09 -04:00
Makefile.am Add libadafruit-bbio with C++ wrappers for PWM/GPIO 2017-03-31 02:17:00 -07:00
MANIFEST.in update new names of README and CHANGELOG 2017-11-02 19:06:29 +00:00
pytest_all_versions.sh Add bash scripts to help install and test 2017-11-30 02:20:52 -06:00
README.md Clarify there is no 0 prefix for pin lables (#180) 2017-11-27 22:52:23 -06:00
setup.py create release 1.0.9 2017-11-30 20:31:39 -06:00
tox.ini Update tox to notify pytest must be run on beagle 2017-01-10 08:59:02 +00:00

Adafruit BeagleBone I/O Python Library (Adafruit_BBIO)

Installation on Debian

Easiest:

sudo ntpdate pool.ntp.org
sudo apt-get update
sudo apt-get install build-essential python-dev python-pip -y
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

Upgrade Adafruit_BBIO to latest version on PyPI:

sudo pip install --upgrade Adafruit_BBIO

Usage

Using the library is very similar to the excellent RPi.GPIO library used on the Raspberry Pi. Below are some examples.

Pin Numbers

Please note that there is no '0' prefix for the pin numbers. For example, pin 7 on header P8 is P8_7.

Correct:

GPIO.setup("P8_7", OUT )

INCORRECT:

GPIO.setup("P8_07", OUT )

Refer to pins_t table[] in common.c all the pin labels.

config-pin

config-pin is now used on the official BeagleBoard.org Debian Jessie and Stretch images to control pin mode (e.g. pin mux).

debian@beaglebone:~$ config-pin -q P9_14
P9_14 Mode: pwm

debian@beaglebone:~$ config-pin -l P9_14
default gpio gpio_pu gpio_pd pwm

debian@beaglebone:~$ config-pin P9_14 gpio

debian@beaglebone:~$ config-pin -q P9_14
P9_14 Mode: gpio Direction: in Value: 0

debian@beaglebone:~$ config-pin P9_14 pwm

debian@beaglebone:~$ config-pin -q P9_14
P9_14 Mode: pwm

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

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.

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")

UART

config-pin P9.21 uart  # UART2_TXD
config-pin P9.22 uart  # UART2_RXD
config-pin P9.24 uart  # UART1_TXD
config-pin P9.26 uart  # UART1_RXD
sudo pip install pyserial
import Adafruit_BBIO.UART as UART
import serial

UART.setup("UART1")

ser = serial.Serial(port = "/dev/ttyO1", baudrate=9600)
ser.close()
ser.open()
if ser.isOpen():
	print "Serial is open!"
    ser.write("Hello World!")
ser.close()

Running tests

Install py.test to run the tests. You'll also need the python compiler package for pytest:

sudo pip install pytest

Execute the following in the root of the project:

sudo pytest

NOTE: sudo should not be required when running Debian 9.2 "Stretch" iot (2017-10-29) with Linux kernel 4.14.x as udev configures group ownership and permission for GPIO and PWM

Credits

The BeagleBone IO Python library was originally forked from the excellent MIT Licensed RPi.GPIO library written by Ben Croston.

License

Written by Justin Cooper, Adafruit Industries. BeagleBone IO Python library is released under the MIT License.