Giter VIP home page Giter VIP logo

adafruit-beaglebone-io-python's Introduction

Adafruit's BeagleBone IO Python Library

This is a set of Python tools to allow GPIO, PWM, and ADC (coming soon) 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.

Installation

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

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 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 BBIO.GPIO as GPIO

GPIO.setup("P8_14", GPIO.OUT)
GPIO.output("P8_14", GPIO.HIGH)

GPIO Input

Inputs work similarly to outputs.

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

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 BBIO.PWM as PWM
#PWM.start(channel, duty, freq=2000)
#duty values are valid 0-100
PWM.start("P9_14", 50)

PWM.set_duty_cycle("P9_14", 25.5)
PWM.set_frequency("P9_14", 10)

PWM.disable("P9_14")
PWM.cleanup()

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 library written by Ben Croston.

License

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

adafruit-beaglebone-io-python's People

Contributors

jwcooper avatar blsmit5728 avatar ladyada avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.