# Blinking an LED with BeagleBone Black

## Overview

In this tutorial, you will learn how to control an external LED using a BeagleBone Black (BBB) from Python.

![](https://cdn-learn.adafruit.com/assets/assets/000/009/102/medium800/beaglebone_overview.jpg?1396883186)

Because the BBB runs Linux, there are many ways in which it can be programmed. In this tutorial we show how to control an output pin and hence LED using Python.

# Blinking an LED with BeagleBone Black

## You Will Need

Info: 

# Blinking an LED with BeagleBone Black

## Installing the Python Library

This tutorial uses Ångström Linux, the operating system that comes pre-installed on the BBB.  
Follow the instructions here, to install the Python IO library. [http://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black](http://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black)

# Blinking an LED with BeagleBone Black

## Wiring

Wire up the solderless breadboard using the header leads as shown below.

![](https://cdn-learn.adafruit.com/assets/assets/000/009/108/medium800/beaglebone_fritzing.png?1396883299)

Push the LED leads into the breadboard, with the longer (positive) lead towards the top of the breadboard. It does not matter which way around the resistor goes.  
  
The top two connections on the BBB expansion header we are using (P8) are both GND. The other lead is connected to pin 10, which is the right-hand connector on the fifth row down. The pins are numbered left to right, 1, 2 then on the next row down 3,4 etc. You can find out about all the pins available on the P8 and P9 connecters down each side of the BBB here: [http://stuffwemade.net/hwio/beaglebone-pin-reference/](http://stuffwemade.net/hwio/beaglebone-pin-reference/ "Link: http://stuffwemade.net/hwio/beaglebone-pin-reference/")

# Blinking an LED with BeagleBone Black

## The Python Console

Before writing a Python program to control an LED, you can try some experiments from the Python console to control the LED.  
  
To launch the Python Console type:

```auto
# python
Python 2.7.3 (default, Apr  3 2013, 21:37:23) 
[GCC 4.7.3 20130205 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
```

First, we need to import the library, so enter the command:

```auto
>>> import Adafruit_BBIO.GPIO as GPIO
```

By default, all the IO pins are set to be inputs. This is no good for our LED, we need the pin it is connected to to be an output, so type the command:

```auto
>>> GPIO.setup("P8_10", GPIO.OUT)
```

At this point, the LED should still be off. To turn it on, type:

```auto
>>> GPIO.output("P8_10", GPIO.HIGH)
```

Turn it off again by typing:

```auto
>>> GPIO.output("P8_10", GPIO.LOW)
```

# Blinking an LED with BeagleBone Black

## Writing a Program

To make the LED flash, we are going to write a short Python program, so exit the Python Console by typing:

```auto
>>> exit()
```

This should take you back to the Linux prompt.  
Enter the following command to create a new files called blink.py

```auto
# nano blink.py
```

Now paste the code below into the editor window.

```auto
import Adafruit_BBIO.GPIO as GPIO
import time

GPIO.setup("P8_10", GPIO.OUT)

while True:
    GPIO.output("P8_10", GPIO.HIGH)
    time.sleep(0.5)
    GPIO.output("P8_10", GPIO.LOW)
    time.sleep(0.5)
```

![](https://cdn-learn.adafruit.com/assets/assets/000/009/109/medium800/beaglebone_nano.png?1396883332)

Save and exit the editor using CTRL-x and the Y to confirm.  
  
To start the program, enter the command:

```auto
# python blink.py
```

When you want to stop the blinking, use CTRL-c to exit the program.

# Blinking an LED with BeagleBone Black

## Next Steps

Try editing your program and changing the sleep period from half a second to 2 seconds and run the program again.  
  
For extra credit, try controlling another LED on a different pin!  
  
**About the Author.**  
As well as contributing lots of tutorials about Raspberry Pi, Arduino and now BeagleBone Black, Simon Monk writes books about open source hardware. You will find his books for sale [here](http://www.adafruit.com/index.php?main_page=adasearch&q=simon+monk) at Adafruit.


## Related Guides

- [Feather Waveform Generator in CircuitPython](https://learn.adafruit.com/waveform-generator.md)
- [CircuitPython Text to Speech](https://learn.adafruit.com/circuitpython-text-to-speech.md)
- [No-Code Room Occupancy Status ](https://learn.adafruit.com/no-code-room-occupancy-status.md)
- [Quickstart - Raspberry Pi RP2040 with BLE and CircuitPython](https://learn.adafruit.com/quickstart-raspberry-pi-rp2040-with-ble-and-circuitpython.md)
- [IBM PC Keyboard to USB HID with CircuitPython](https://learn.adafruit.com/ibm-pc-keyboard-to-usb-hid-with-circuitpython.md)
- [micro:bit Lesson 2. Controlling LEDs on Breadboard](https://learn.adafruit.com/micro-bit-lesson-2-controlling-leds-on-breadboard.md)
- [Adafruit IO Basics: Digital Output](https://learn.adafruit.com/adafruit-io-basics-digital-output.md)
- [Working with Multiple Same Address I2C Devices](https://learn.adafruit.com/working-with-multiple-i2c-devices.md)
- [Integrating Home Assistant with Adafruit IO](https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant.md)
- [Grand Central USB MIDI Controller in CircuitPython](https://learn.adafruit.com/grand-central-usb-midi-controller-in-circuitpython.md)
- [Digital Inputs with Adafruit IO WipperSnapper](https://learn.adafruit.com/digital-inputs-with-adafruit-io-wippersnapper.md)
- [Animatronic Fizzgig MonsterM4sk Puppet](https://learn.adafruit.com/animatronic-fizzgig-monsterm4sk-puppet.md)
- [Using micro:bit and CRICKIT with MicroPython](https://learn.adafruit.com/using-micro-bit-and-crickit-with-micropython.md)
- [Compost Friend!](https://learn.adafruit.com/compost-optimization-machine.md)
- [IoT Temperature Logger with Analog Devices ADT7410, Raspberry Pi, and Adafruit IO](https://learn.adafruit.com/iot-temperature-logger-with-python-and-adafruit-io.md)
