Hardware Reference
In-Depth Information
Solution
So far, we've focused on using JavaScript and the BoneScript API for interfacing
BeagleBone Black to the physical world. BoneScript provides an easy way to interface the
Bone to the world, but there are other programming languages out there. This recipe
provides the steps needed to work with Python, and Recipe 5.21 does the same for C.
Adafruit has produced an excellent library for the Bone , and it's already installed. Ensure
that the BBIO library is up-to-date:
bone# pip install Adafruit_BBIO
Requirement already satisfied (use --upgrade to upgrade):
Adafruit-BBIO in /usr/local/lib/python2.7/dist-packages
Cleaning up...
Now that you're ready to go, add the code in Example 5-3 to a file called blinkLED.py .
Example 5-3. Use Python to blink an LED (blinkLED.py)
#!/usr/bin/env python
import Adafruit_BBIO.GPIO as GPIO
import time
pin = "P9_14"
GPIO . setup ( pin , GPIO . OUT )
while True :
GPIO . output ( pin , GPIO . HIGH )
time . sleep ( 0.5 )
GPIO . output ( pin , GPIO . LOW )
time . sleep ( 0.5 )
Wire your LED as shown in Recipe 3.2 and run it with the following command:
bone# chmod +x blinkLED.py .
bone# ./blinkLED.py .
Adafruit's Setting up IO Python Library on BeagleBone Black does a nice job showing
how to use the BBIO library.
Search WWH ::




Custom Search