Blink

Now that we have our transistor driving the LED at its full current from GPIO0_30 (P9.11), let's use Adafruit_BBIO to write a program that blinks it at a fixed interval. The first step is to load the universal-io Device Tree overlay as described previously:

# echo cape-universaln > /sys/devices/bone_capemgr.*/slots

Next you'll need to use the config-pin command to manually configure the pin as a digital output:

# config-pin P9_11 in

Now that the pin is configured properly, open a new file in Cloud9 called blink.py with the following code:

from Adafruit_BBIO import GPIO
import time

LED_PIN = "GPIO0_30"
GPIO.setup(LED_PIN, GPIO.OUT)

while True:
  GPIO.output(LED_PIN, GPIO.HIGH)
  time.sleep(0.5)
  GPIO.output(LED_PIN, GPIO.LOW)
  time.sleep(0.5)

Press ...

Get Learning BeagleBone Python Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.