Book Image

Learning Beaglebone Python Programming

Book Image

Learning Beaglebone Python Programming

Overview of this book

Table of Contents (19 chapters)

The PyBBIO library


The PyBBIO library was developed with Arduino users in mind. It emulates the structure of an Arduino (http://arduino.cc) program, as well as the Arduino API where appropriate. If you've never seen an Arduino program, it consists of a setup() function, which is called once when the program starts, and a loop() function, which is called repeatedly until the end of time (or until you turn off the Arduino). PyBBIO accomplishes a similar structure by defining a run() function that is passed two callable objects, one that is called once when the program starts, and another that is called repeatedly until the program stops. So the basic PyBBIO template looks like this:

from bbio import *

def setup():
  pinMode(GPIO1_16, OUTPUT)

def loop():
  digitalWrite(GPIO1_16, HIGH)
  delay(500)
  digitalWrite(GPIO1_16, LOW)
  delay(500)

run(setup, loop)

The first line imports everything from the PyBBIO library (the Python package is installed with the name bbio). Then, two functions are...