Using Command Terminal
Probably the most basic example you could do but its a great start for using digital output on your device. Before I attempted this in Python, I turned and LED on simply through the command terminal. This begins with defining the pin you are going to use. This creates a directory by executing the following command
cd /sys/class/gpio
echo ## export
The ## being which pin you will be using as the digital pin on the BBB
This will create the directory for the pin you have specified. Next is to define it as an INPUT or an OUTPUT pin.
This pin will be an "out" as we are turning off and on and LED controlled by the device.
echo out > direction
Using Python
The same concepts are utilized when executing the commands in python. Rather than using "echo" to write values to the pin files, you use python to write the commands to the files on the BeagleBone.
The link to the code is located at Blink.py
I will explain it in segments,
1. The first setup is to define which pin will be used, just as we did before.
2. The second setup is to define whether it is an INPUT or an OUTPUT, as we did before
3. We then open the value file so we can write to it. Because this is a digital output we will write a "1" for on and a "0" for off.
We then just create a loop that turns the LED off and on in 1 second intervals.
The except is for when we want to end the program. You have to unexport the pin that was being used so you execute the command
/sys/class/gpio/unexport
This will occur when the user uses Ctrl+C in the terminal window to end the python program.
This is a great start to understanding how to use digital input and output on the BeagleBone Black. From here you can use this to turn on much more than just and LED.