LED Matrix Kit


Revisited by: Ryan Winters
Product Manager

Difficulty: Intermediate
Time Required: 1-2 hours

LED Matrix Kit (P/N 2127970)

LED Matrix
Here is a new spin on a great kit. Have you ever seen the dot-matrix displays that can display letters, numbers, or even icons? Once you know the basics for how to display something on one matrix, you can daisy-chain the Maxim Max7219 ICs and LED matrices to display a greeting, the time, a count-down, or a scrolling statement. Besides needing some kind of microcontroller, such as the Arduino Nano v3.0, you will also need an LED driver chip to communicate to the LED dot-matrix display. Depending on the size of the matrix you are using, you may use all of the I/O pins of the microcontroller, but you might not have any available pins for other sensors or devices. Using an LED driver IC is a much more efficient use of I/O pins and will only require three I/O pins on the microcontroller. The Max7219 is a serial input/output common-cathode display driver that can either control a 7-segment numeric display of up to 8 digits, bar-graph displays, or 64 individual LEDs. This is perfect for our 8x8 LED dot-matrix display because there are 64 individual LEDs.

The Wiring

LED Matrix Schematic

As shown in the wiring diagram above, there are 16 connections to make between the LED matrix and the LED driver chip. The matrix included in the kit is of the anode-row/cathode-column variety. Alternatively, you could make your own matrix with 64 LEDs as Collin briefly demonstrates in the video. You can also see there are only three wires to connect to the Arduino Nano. To make all of this work together harmoniously, it will take some elegant programming. Thankfully, some people were nice enough to write a Max7219 library for the Arduino; it's called LedControl and is available for download as a (.zip) file. Basically, the LedControl library tells the Arduino how to communicate with the Max72XX ICs. Once you've downloaded the library file and installed it to the appropriate location, you will need to call the library into your program.

The Program

My first basic program was to create the code for each letter of the alphabet so I could print messages. The first thing to type into your Arduino IDE window is:

#include "LedControl.h"
LedControl lc=LedControl(12,10,11,1); unsigned long
delaytime=500; //waits 500 ms between display updates

Pin 12 is connected to the DataIn, Pin 10 is connected to the CLK, and Pin 11 is connected to the LOAD pin of the Max7219 IC. The "1" following the pin assignment tells the Arduino that there is only one Max7219 connected to the Arduino. If you were to have five Max7219 ICs, then you would replace the "1" with a "5". The maximum allowed devices is eight. Apparently the Max72XX is in power saving mode on startup, so you will need to wake it up.

void setup()
{
lc.shutdown(0,false); // Set the brightness to a medium values
lc.setIntensity(0,8); // and clear the display
lc.clearDisplay(0);
}

Now you may be able to make better looking capital letters, but this is just to understand the concept. I searched the internet and found some code that printed letters, and I somewhat reverse-engineered how they made their letters and made the rest of the alphabet myself. I don't exactly know what's going on to make each letter and what the code means, so it was quite a bit of testing and re-testing. Take a look at a few letters below.

void writeOnMatrix()
{
byte A[5]={B01111111,B10001000,B10001000,B10001000,B01111111};
byte B[5]={B11111111,B01001001,B01001001,B00110110,B00000000};
byte C[5]={B01111110,B10000001,B10000001,B10000001,B01000010};
byte D[5]={B01111111,B01000001,B01000001,B00111110,B00000000};
byte E[5]={B11111110,B10010010,B10010010,B10010010,B00000000};
}

So for the letter "A", "byte" stores an 8-bit unsigned number to the value "A" and it will use up 5 of the 8 bits, or the first 5 columns of the 8 columns in the 8x8 LED matrix. The "B" in front of each set of numbers is a binary formatter. 0 equals "OFF" and 1 equals "ON". If the MAX7219 prints each dot from top to bottom and then each column from left to right, then "B01111111" will not turn on the first LED in the column, but it will turn on the next seven. In the second column for the letter "A", "B10001000" will turn on the first and fifth LED down and leave all others off. Once all five columns are activated, you will see a capital letter "A". In my example I will define the letters to spell JAMECO with a 500ms delay between each letter. For a visual example, see my LED matrix represented by a table.

For sample code click here.

The parameters for setRow() are:

setRow(int addr, int row, byte value);
/*
* Set all 8 LEDs in a row to a new state
* Parameters:
* addr address of the display (0..7, we only have 1 Max7219, so 0)
* row row which is to be set (0..7)
* value each bit set to 1 will light up the corresponding LED.
* In our case, we've defined each byte already as a letter in the alphabet.
*/
Visual Example

So in my example, lc.setRow(0,0,J[0]); can be described from left to right: "lc.setRow" is the command to print a row on the matrix defined as "lc". The first "0" tells it to print to the first MAX7219. We only have one, and zero is the first digit expressed in ascending order. The second "0" is for the first row of eight, again expressed 0-7. For the byte, we call "J[0]" to print the first bit we stored in the 8-bit value for the letter "J". "J[1]" would print the second bit we stored in the value for "J".

There are several examples on the internet, including the LedControl tutorial, of what you can do with a matrix. Now that you have the tools and a brief introduction to LED matrices, you can print messages to your matrix, use the MAX7219 display driver to communicate with several different numeric displays or bar-graphs, or use the much prized Arduino Nano v3.0 for any project you wish.

The remainder of the included code contains a complete alphabet of capital letters and a couple other brief methods that demonstrate how to flash specific LEDs for a specified period, and some mesmerizing things you can do with pulsing the brightness of the entire matrix. The code is mostly borrowed from the Arduino Playground which is a publicly-editable wiki about Arduino.

Click here for sample code.

LED Matrix Kit (P/N 2127970) includes:

IC, Max7219CNG, DIP24, 8-digit
Potentiometer, 1/2W, 10KΩ
Display, Dot Matrix, Hi-E Red, 8x8
Resistor, 1/4 Watt, 30KΩ, 5%
Capacitor, Ceramic, 0.1µF
Arduino Nano 3.0

Click here for Circuit Skills LED Matrix video.

Ryan Winters is a Product Manager at Jameco Electronics. His hobbies include working on cars and computers, fiddling with electronic gadgets, and learning robotics.