# 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:

```
# 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.
&gt;&gt;&gt; 
```

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

```
&gt;&gt;&gt; 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:

```
&gt;&gt;&gt; GPIO.setup("P8_10", GPIO.OUT)
```

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

```
&gt;&gt;&gt; GPIO.output("P8_10", GPIO.HIGH)
```

Turn it off again by typing:

```
&gt;&gt;&gt; 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:

```
&gt;&gt;&gt; exit()
```

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

```
# nano blink.py
```

Now paste the code below into the editor window.

```
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:

```
# 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.


## Featured Products

### BeagleBone Black - Rev B

[BeagleBone Black - Rev B](https://www.adafruit.com/product/1278)
**[Adafruit is no longer shipping the BeagleBone Black Rev B, it has been replaced with the Rev C as of 5/12/14](https://www.adafruit.com/products/1876) - the Rev C now has 4G flash and also comes with Debian, it also costs slightly more. There are no exchanges or...**

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1278)
[Related Guides to the Product](https://learn.adafruit.com/products/1278/guides)
### Half Sized Premium Breadboard - 400 Tie Points

[Half Sized Premium Breadboard - 400 Tie Points](https://www.adafruit.com/product/64)
This is a cute, half-size breadboard with&nbsp;400 tie points, good for small projects. It's 3.25" x 2.2" / 8.3cm&nbsp;x 5.5cm&nbsp;with a standard double-strip in the middle and two power rails on both sides.&nbsp;You can pull the power rails off easily to make the breadboard as...

Out of Stock
[Buy Now](https://www.adafruit.com/product/64)
[Related Guides to the Product](https://learn.adafruit.com/products/64/guides)
### Adafruit Proto Plate for Beagle Bone & Beagle Bone Black

[Adafruit Proto Plate for Beagle Bone & Beagle Bone Black](https://www.adafruit.com/product/702)
Ready to prototype your next [Beagle Bone](http://www.adafruit.com/products/1278) project? You'll certainly want this handy Proto-Plate! Not only is it really good looking, its also very useful, holding your [Beagle Bone or Beagle...](http://www.adafruit.com/products/1278)

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/702)
[Related Guides to the Product](https://learn.adafruit.com/products/702/guides)
### Diffused Red 10mm LED (25 pack)

[Diffused Red 10mm LED (25 pack)](https://www.adafruit.com/product/845)
Need some big indicators? We are big fans of these huge diffused red LEDs. They are fairly bright so they can be seen in daytime, and from any angle. They go easily into a breadboard and will add that extra zing to your project.

- Pack of 25 diffused red LEDs
- 10mm...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/845)
[Related Guides to the Product](https://learn.adafruit.com/products/845/guides)
### Breadboarding wire bundle

[Breadboarding wire bundle](https://www.adafruit.com/product/153)
75 flexible stranded core wires with stiff ends molded on in red, orange, yellow, green, blue, brown, black and white. These are a major improvement over the "box of bent wires" that are sometimes sold with breadboards, and faster than stripping your own solid core wires. Makes...

In Stock
[Buy Now](https://www.adafruit.com/product/153)
[Related Guides to the Product](https://learn.adafruit.com/products/153/guides)
### Premium Male/Male Jumper Wires - 40 x 3" (75mm)

[Premium Male/Male Jumper Wires - 40 x 3" (75mm)](https://www.adafruit.com/product/759)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 3" (75mm) long and come in a 'strip' of 40 (4 pieces of each of ten rainbow colors). They have 0.1" male header contacts on either end and fit cleanly next to each other...

In Stock
[Buy Now](https://www.adafruit.com/product/759)
[Related Guides to the Product](https://learn.adafruit.com/products/759/guides)
### Premium Male/Male Jumper Wires - 40 x 6" (150mm)

[Premium Male/Male Jumper Wires - 40 x 6" (150mm)](https://www.adafruit.com/product/758)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 6" (150mm) long and come in a 'strip' of 40 (4 pieces of each of ten rainbow colors). They have 0.1" male header contacts on either end and fit cleanly next to each other...

Out of Stock
[Buy Now](https://www.adafruit.com/product/758)
[Related Guides to the Product](https://learn.adafruit.com/products/758/guides)

## Related Guides

- [Bone Box](https://learn.adafruit.com/bone-box.md)
- [SSD1306 OLED Displays with Raspberry Pi and BeagleBone Black](https://learn.adafruit.com/ssd1306-oled-displays-with-raspberry-pi-and-beaglebone-black.md)
- [BeagleBone](https://learn.adafruit.com/beaglebone.md)
- [Measuring Temperature with a BeagleBone Black](https://learn.adafruit.com/measuring-temperature-with-a-beaglebone-black.md)
- [Trellis Python Library](https://learn.adafruit.com/trellis-python-library.md)
- [FONA Tethering to Raspberry Pi or BeagleBone Black](https://learn.adafruit.com/fona-tethering-to-raspberry-pi-or-beaglebone-black.md)
- [MCP9808 Temperature Sensor Python Library](https://learn.adafruit.com/mcp9808-temperature-sensor-python-library.md)
- [Adafruit WebIDE](https://learn.adafruit.com/webide.md)
- [Setting up WiFi with BeagleBone Black](https://learn.adafruit.com/setting-up-wifi-with-beaglebone-black.md)
- [Embedded Linux Board Comparison](https://learn.adafruit.com/embedded-linux-board-comparison.md)
- [Bonjour (Zeroconf) Networking for Windows and Linux](https://learn.adafruit.com/bonjour-zeroconf-networking-for-windows-and-linux.md)
- [Controlling a Servo with a BeagleBone Black](https://learn.adafruit.com/controlling-a-servo-with-a-beaglebone-black.md)
- [Running Programs Automatically on Your Tiny Computer](https://learn.adafruit.com/running-programs-automatically-on-your-tiny-computer.md)
- [Nokia 5110/3310 LCD Python Library](https://learn.adafruit.com/nokia-5110-3310-lcd-python-library.md)
- [BeagleBone Black: Installing Operating Systems](https://learn.adafruit.com/beaglebone-black-installing-operating-systems.md)
