Beaglebone Black – LED

In this tutorial, we’ll look at a simple example of how to use the Beaglebone Black’s GPIOS by connecting an LED. In this lesson, we’ll look at an example of a program to switch the LED on.

Here’s the circuit to connect your LED to the Beaglebone Black:

The board has GPIOS which operate at +3.3V. We therefore use a 220 ohm resistor to limit the LED input current.

Here’s the program to turn on a LED:

import Adafruit_BBIO.GPIO as GPIO
import time

led_pin = "P9_12" # Set LED pin
GPIO.setup(led_pin, GPIO.OUT) # Configure pin in output mode

try:
    while True:
        # Turn on LED
        GPIO.output(led_pin, GPIO.HIGH)
        print("LED on")
        time.sleep(1) # Pause for 1 second

        # Turn off LED
        GPIO.output(led_pin, GPIO.LOW)
        print("LED off")
        time.sleep(1) # Pause for 1 second

except KeyboardInterrupt:
    # Keyboard interrupt management (Ctrl+C)
    print("Keyboard interrupt. Program stop.")
    GPIO.cleanup() # Clean GPIO resources