Led blinking In Beaglebone Blank
Let’s start with the explanation of various peripheral interfaces with Beaglebone black. I will begin with a simple external LED blinking with BBB for better understanding of the configuration and usage of GPIO pin. I have chosen the python scripting language for programming but you can write it in any another language also. I have used adafruit python BBB library to make application.
- Beaglebone Black
- 330 Ω Resistor
- Female to Female connectors
Setup of Software environment
Install the latest python version in BBB as explained in tutorial How to make first python program with Beaglebone Black. Install the adafruit python-GPIO library named adafruit_BBIO.
It is a simple learning tutorial of Beaglebone black. Here I connected two LEDs with GPIO pin of Beaglebone black. When script is running, both the LEDs are switched ON and OFF for one second. After executing it for five times, the pin status and configuration are clear.
Let’s first prepare the circuit connection. Take a breadboard and provide VCC and ground from BBB to breadboard line. Connect Supply 3.3 V from pin number 3 of header P9 and ground from pin number 2 of header P8. Connect the negative and positive terminals of both LEDs with the ground and 330 OHM resistor respectively. Connect another end of both resistors with pin number 8 and 9 of header P8. Provide the supply to Beaglebone black by connecting it with PC through USB cable. Now your circuit is prepared.
Open the command terminal and take an access of Beaglebone black through SSH as explained in getting started with Beaglebone black. Create a new file using touch command with .py extension. Open the file with any text editor (i.e. nano, vim etc.) and write a code in python language.
Configuration of GPIO pin
Import the GPIO library from adafruit Beaglebone black library by calling following line in program:
import Adafruit_BBIO.GPIO as GPIO
You can define the pin number with underscore followed by its number. (i.e. P8_8). Give it an appropriate name.
i.e. LED1 = “P8_8”
Here, I have assigned the name LED1 to pin number 8th oh header P8.
Next, configure the pin as input or output as following function:
GPIO.setup (Pin number, output/input)
For example, I have declared LED1 (pin number 8th oh header P8) as an output by following line:
If you want to declare as an input, you can declare as following:
Note: here I have declared LED as an output. (led is output device)
You can make pin high and low by following function:
GPIO.output (Pin number, High or Low)
For example, I have made led1 (pin number 8th oh header P8) as High and low by following line:
HIGH : GPIO.output (LED1, GPIO.HIGH)
LOW : GPIO.output (LED1, GPIO.LOW)
Filed Under: Tutorials