Building an LED Matrix
Daisy Chain a Dot-Matrix LED DisplayBy Ryan Winters
Product Marketing Manager
Assembly Time: 1 to 2 hours
Skill Level: Intermediate
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.
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 ProgramMy 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:
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.
lc.shutdown(0,false); // Set the brightness to a medium values
lc.setIntensity(0,8); // and clear the display
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.
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
* 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.
So in my example, lc.setRow(0,0,J); 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" to print the first bit we stored in the 8-bit value for the letter "J". "J" 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.
LED Matrix Kit includes:
|Qty.||Part Description||Mfr. Part No.|
|1||24-pin DIP, 8-Digit LED Display Driver IC||MAX7219CNG|
|1||10KΩ 1/2-Watt Potentiometer||18STS103|
|1||8x8 Hi-Efficiency Red Dot Matrix Display||LD788BS-SS22|
|1||5% 30KΩ 1/4-Watt Resistor||CF1/4W303JRC|
|1||0.1µF Ceramic Capacitor||SR205E104MAA-VP|
|1||Arduino Nano 3.0||A000005|
Watch the Circuit Skills LED Matrix video.
Ryan Winters is a Product Manager at Jameco Electronics and a Bay Area, California native. He is mostly self-taught and his hobbies include working on cars and computers, fiddling with electronic gadgets and experimenting with robotics.