Beagleboard:8x8 Bi-Color LED Matrix

Jump to: navigation, search

Adafruit Bicolor LED Square Pixel Matrix with I2C Backpack

Adafruit Bicolor LED Square Pixel Matrix with I2C Backpack

The 8x8 Bi-color LED Matrix has 24 pins that can be configured to display three color images, such as the thumbnail on the right. It displays three LED colors, including red, green, and yellow. The matrix uses a driver chip that does most of the heavy lifting and provides consistent color through an I2C interface. More information regarding the LED matrix can be found in the Adafruit website.

Items Required:

BeagleBone Black
5VDC Power Supply
Mini-USB Data Cable
Ethernet Cable
8x8 Bi-Color LED Matrix Contents
4 Jumper Wires

Setting up the Hardware

8x8 LED Matrix Setup

Adafruit does an excellent job of describing how to solder the 8x8 Matrix backpack. Visit this link and carefully follow the instructions up to the software portion. Once it is fully assembled, we will connect the SCL/SDA pins to the BeagleBone Black. The 8x8 Bi-Color LED Matrix has pin connections labeled with (+,-,C, and D). Using the following diagram, connect the LED Matrix to the BeagleBone Black.

Signal | BeagleBone Pin     | 8x8 Bi-Color LED Matrix

VCC    | 5 or 6 (P9 Header) |         +
GND    | 1 or 2 (P9 Header) |         -
SCL    | 19 (P9 Header)     |         C
SDA    | 20 (P9 Header)     |         D


In this final step, we will do two things. We will install the i2c-dev library and run the code on the Cloud9 Environment.

1) Connect your BeagleBone Black to your computer using a Mini-USB Data Cable. Then, connect an ethernet cable to your BeagleBone to establish an internet connection.
2) Using a terminal shell, such as PuTTy, install the i2c-node. Type in the following commands:

$cd /
$ntpdate -b -s -u
$opkg update
$opkg install python-compile
$opkg install python-modules
$npm config set strict-ssl false
$npm install i2c
(You can take a closer look at the library here.)

3) Once the library has finished downloading, power your BBB off.
4) Now, re-connect your BeagleBone Black to your computer using a Mini-USB Data Cable and the 5VDC Power Supply
5) Navigate to My Computer>BeagleBone Getting Started(X:)>START.htm
6) Once the tabs on the left turn green, go to Step 3 and navigate to
7) On the left menu under Software, click Cloud9IDE and launch it.
8) On the top left, click File>New File. Then, save it and name it to something like LEDMatrix.js.
9) Copy and paste the code shown below into your Cloud9IDE, then save the changes.
10) At the top, look for the Debug button. Click the tiny arrow to the right and click on 'Run on debug mode.' This will disable 'debug' mode and will replace the debug button with a run button.
11) Click 'run' and it will display a picture on your LED Matrix. The code below will output a snake, displaying all three colors.

* Created on: 7-8-2013
* Revised on: 7-9-2013
* Author: Juan Cortez
* 8x8 Bi-Color LED Matrix (
* Input: None
* Output: Outputs values to the 8x8 Bi-Color LED Matrix and displays an image
* Note: i2c-dev Library can be found in the following website:
// Library used to configure i2c commands
var i2c = require('i2c');
var address = 0x70;                                  // Address of 8x8 Matrix is found in 0x70
var wire = new i2c(address, {device: '/dev/i2c-1'}); // Points to the i2c address

// Global Variables used throughout program
var a=0;
var b=0;
var brightnessArray = [0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7]; // E0(dimmest), E7(brightest) 

/* Insert the hexadecimal values of your bitmap picture, as well as brightness level from 0(dimmest)-7(brightest)*/
var green = [0x80,0xFE,0x02,0x3E,0x20,0x3A,0xC7,0xC0];  // Green Pixels
var red = [0x00,0x00,0x00,0x00,0x00,0x05,0xC0,0xC2];    // Red Pixels
var brightness = brightnessArray[7];                    // Brightness level from 0(dimmest)-7(brightest)

//Setup and turn on the 8x8 Bi-Color LED Matrix
    wire.writeBytes(0x21, 0x00, a++, printStatus());            // 8x8 Bi-Color LED Matrix Set-up
    wire.writeBytes(0x81, 0x00, a++, printStatus());            // Display on and no blinking
    wire.writeBytes(brightness, 0x00, a++, printStatus());      // Configures the brightness

// Writes the data to the 8x8 Matrix
    wire.writeBytes(0x00, [green[a], red[b]], a++, b++);    // Row 1
    wire.writeBytes(0x02, [green[a], red[b]], a++, b++);    // Row 2
    wire.writeBytes(0x04, [green[a], red[b]], a++, b++);    // Row 3
    wire.writeBytes(0x06, [green[a], red[b]], a++, b++);    // Row 4
    wire.writeBytes(0x08, [green[a], red[b]], a++, b++);    // Row 5
    wire.writeBytes(0x0A, [green[a], red[b]], a++, b++);    // Row 6
    wire.writeBytes(0x0C, [green[a], red[b]], a++, b++);    // Row 7
    wire.writeBytes(0x0E, [green[a], red[b]], a++, b++, printStatus());    // Row 8

// Displays the status of 8x8 Bi-Color LED Matrix on the console
function printStatus(){
 case 1: console.log(a+ ". 8x8 Bi-Color LED Matrix: Turned on."); 
 case 2: console.log(a+ ". 8x8 Bi_Color LED Matrix: Turned off Blinking.");
 case 3: console.log(a+ ". 8x8 Bi_Color LED Matrix: Display Brightness Set.");
 case 8: console.log("4. Picture displayed on the LED matrix.");

Program Explanation


The LED Matrix has 8 rows and 8 columns. Each row has 8 bits. When one light is turned on, it is represented as a '1', and '0' if it is off. When writing to the matrix, you must write the hexadecimal representation of the binary numbers. Hexadecimal values range from 0-9 and A-F. A good example of a binary to hexadecimal converter can be found here. Below is an example of this explanation.

Row | Binary Representation | Hexadecimal Representation |   LED Lights (X=off, 0=on)
 1  |       01011011        |          5B                |         X0X00X00

The code has been simplified so that you can simply enter the hexadecimal representation into an array, which will output to the 8x8 matrix, as shown here.

Array Name | Row 1  Row 2  Row 3  Row 4  Row 5  Row 6  Row 7  Row 8
var green = [0x80,  0xFE,  0x02,  0x3E,  0x20,  0x3A,  0xC7,  0xC0];

The code provided has two arrays, one called green, and the second called red. Hexadecimal values placed in green will give you a green picture. Hexadecimal values placed in red will give you a red picture. When both the green and red arrays overlap, it creates yellow. Here is an example of images with different colors and their respective hexadecimal values.
Note: var green={}; gives you an empty array

Green Image:      var green =[0x3C,0x42,0x95,0xA1,0xA1,0x95,0x42,0x3C];  // Green smily face
                  var red={};      
Red Image:        var green={};                                          // Red heart
                  var red = [0x00,0x0E,0x11,0x21,0x42,0x21,0x11,0x0E]; 
Red/Green/Yellow: var green = [0x80,0xFE,0x02,0x3E,0x20,0x3A,0xC7,0xC0]; // Snake with green,red, and yellow colors
                  var red = [0x00,0x00,0x00,0x00,0x00,0x05,0xC0,0xC2];

The last thing that you can change in this code is the brightness. The hardware is set up so that E0 is the dimmest and E7 is the brightest. In order to make the code cleaner, all you have to do is assign the value of brightness you want in the following line.

var brightness = brightnessArray[7];                     // 7: Brightness level
var brightness = brightnessArray[0];                     // 0: Dimmest level

Terminal Shell Commands (Advanced)

Using a terminal shell such as PuTTy, we can program the 8x8 LED matrix with I2C commands. I will list the commands that can be used and it is up the users discretion for further usage.

i2cdetect -r -y 1          // displays the address of the device plugged in to i2c. The 8x8 LED Matrix is in location 0x70
i2cdump -y 1 0x70          // displays the EEPROM contents of the matrix
i2cset -y 1 0x70 0x21 0x00 // system setup
i2cset -y 1 0x70 0x81 0x00 // display on and no blinking
i2cset -y 1 0x70 0xE7 0x00 // brightness (E0 is dimmest, E7 is brightest)
i2cset -y 1 0x70 0x00 0xFF // turns on the whole first row of the LED matrix

Alternate Images

Listed below is a community-based list of 8x8 images that you can output to your 8x8 Matrix.
If you would like to add any other images, feel free to e-mail Juan Cortez

Devil,Frog,Crab, and Snake Examples


var green = {};
var red = [0x00, 0x0E, 0x11, 0x21, 0x42, 0x21, 0x11, 0x0E];

var green = {};
var red = [0x3C, 0x42, 0x95, 0xA1, 0xA1, 0x95, 0x42, 0x3C];

var green = [0x3C, 0x42, 0xA5, 0x91, 0x91, 0xA5, 0x42, 0x3C];
var red = {};

var green = [0x3C, 0x42, 0x95, 0x91, 0x91, 0x95, 0x42, 0x3C];
var red = {};


var green = [0x36,0x36,0x00,0x00,0x00,0x0C,0x00,0x00];
var red = [0x36,0x12,0x12,0x12,0xDF,0x7F,0xDF,0x15];

var green = [0x00, 0x00, 0x00, 0X42, 0x08, 0x00, 0x14, 0x14];
var red = [0xFF, 0xFF, 0xFF, 0xBD, 0xF7, 0xFF, 0x6A, 0x6A];

var green = [0x80,0xFE,0x02,0x3E,0x20,0x3A,0x07,0x00];
var red = [0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x02];

var green = [0xEE,0xAA,0xFF,0x01,0xFF,0xFF,0xFF,0xBB];
var red = [0x00,0x44,0x00,0xFE,0x00,0x00,0x00,0x00];

var green = [0x00,0x00,0x50,0x05,0xF5,0x07,0x62,0x62];
var red = [0x44,0xFF,0xFF,0xFA,0xFA,0xF8,0xFD,0xFD];

Additional Tutorial(s) Involving the 8x8 Bi-Color LED Matrix