Skip to content
alexanderhiam edited this page Apr 16, 2012 · 41 revisions

PyBBIO is a Python library for hardware IO support on the TI Beaglebone.

It is designed to mimic the Arduino API to create a friendly and familiar development environment.

##Installing Installation is quite simple. It is assumed that your Beaglebone is already set up and configured on your network, and that you have already SSHed onto it.

Note that these instructions assume you want PyBBIO/ to live in your home directory. This is not a requirement and can changed as desired.

The first step is to install the dependencies:

# opkg update && opkg install python-mmap python-pyserial

Then you'll need to get the code:

# cd ~
# git clone git://github.com/alexanderhiam/PyBBIO.git

The next step is to run the install script:

# cd PyBBIO
# sh install.sh -i

PyBBIO should now be installed correctly. Run the blink example to make sure all is well:

# cd examples
# python blink.py

And confirm that the LEDs next to the Ethernet jack labelled USR2 and USR3 are blinking back and forth.

##Updating I am working as fast as I can to add support for many of the features that the Beablebone's AM3359 processor has to offer, so you'll want to make sure your version is up to date. Thanks to git this is a very simple process:

# cd ~/PyBBIO
# git pull
# sh install -i

##Uninstalling If you need to uninstall PyBBIO you can use the install.sh script:

# cd ~/PyBBIO
# sh install.sh -u

##Usage If you've worked with the Arduino and know some Python, you should hopefully have no trouble getting used to PyBBIO. Here's the basic structure of a PyBBIO program:

from bbio import *
    
def setup():
  """ This will be called once before the main loop. """

def loop():
  """ This is the main loop of your program. It will be called repeatedly
      until ctrl-c is pressed, or stop() is called from within. """

# We then pass the two functions to run() to start the program:
run(setup, main) 

You'll want to have the Beaglebone schematics on hand. The last page shows the pin names for the expansion headers; these names are the same for PyBBIO. If you run examples/available_pins.py you'll see all the pins that are currently supported. I'll keep this up to date as new features are added. Notice, in the GPIO pins list, USR0-USR3. These are the on-board LEDs next to the Ethernet jack.

Let's walk through a simple example of blinking a single led:

First, refer to the schematic to find a digital pin. we'll use GPIO1_16, which is pin 15 on the header labelled P9. We'll then connect the anode of an LED to this pin, the cathode to one end of a 330 ohm resistor, and the other end of the resistor to ground, which is pin 1 on the P9 header.

There's only a few lines of code we need to add to the above template to get the LED blinking. First, to keep things straightforward, it's nice to set a variable for the LED instead of passing around GPIO1_16, e.g.:

LED = GPIO1_16

Then we'll want to set the LED pin as an output in our setup routine. This is done with the pinMode() function:

pinMode(LED, OUTPUT)

To set the state of the LED we could use the digitalWrite() function, but since all we're doing is toggling the state of the pin, we can just use the toggle() function:

toggle(LED)

And we'll also want to add a bit of a time delay into the loop using the delay() function so we can actually see the LED blinking; it takes a delay in milliseconds as an argument.

When we put it all together:

from bbio import *

LED = USR3

def setup():
  pinMode(LED, OUTPUT)

def loop():
  toggle(LED)
  delay(500)

run(setup, loop)

Then save and run it; you should see your LED blinking.

Be sure to look through the examples in PyBBIO/examples/.

In order for PyBBIO to allow access to certain features, there are some initialization and clean-up requirements. This is easily handled by the run() function when executing a PyBBIO program, but it makes it more tricky to use the library interactively. I'm working on a solution, but for the time being interactive mode is not supported.

For full API documentation see: API documentation

##Libraries PyBBIO includes its own libraries, which are stored in PyBBIO/libraries/. Documentation for these libraries:

##Troubleshooting Something not working? Chances are I don't know about it yet, so open an issue or send me an email at ahiam@marlboro.edu with all the details and I'll do my best to fix it.