Book Image

Learning Beaglebone Python Programming

Book Image

Learning Beaglebone Python Programming

Overview of this book

Table of Contents (19 chapters)

The Adafruit_BBIO library

The Adafruit_BBIO library is structured differently than PyBBIO. While PyBBIO is structured such that, essentially, the entire API is accessed directly from the first level of the bbio package; Adafruit_BBIO instead has the package tree broken up by a peripheral subsystem. For instance, to use the GPIO API you have to import the GPIO package:

from Adafruit_BBIO import GPIO

Otherwise, to use the PWM API you would import the PWM package:

from Adafruit_BBIO import PWM

This structure follows a more standard Python library model, and can also save some space in your program's memory because you're only importing the parts you need (the difference is pretty minimal, but it is worth thinking about).

The same program shown above using PyBBIO could be rewritten to use Adafruit_BBIO:

from Adafruit_BBIO import GPIO
import time

GPIO.setup("GPIO1_16", GPIO.OUT)
  while True:
    GPIO.output("GPIO1_16", GPIO.HIGH)
    GPIO.output("GPIO1_16", GPIO.LOW)