Driving an 8×8 (64) LED Matrix with MAX7219 (or MAX7221) and Arduino Uno
Hi guys, today we will be focusing on displaying mini graphics and texts on an 8×8 LED matrix using the MAX7219 (or MAX7221) LED driver and the Arduino Uno.
The 8×8 LED matrix displays are usually used for the display of symbols, simple graphics and texts. Made of super bright LEDs, they produce low resolution display and can be daisy chained to produce larger displays.
To enable us to control the display easily, we will be using the MAX7219/MAX7221 LED display driver module. Although this driver comes attached to the LED Matrix display that we will be using for this tutorial, its important to treat them separately, so you can understand how the LED driver works and be able to use it in case you are unable to get an 8×8 LED Matrix display that comes with the LED Driver.
The MAX7219/MAX7221 are compact, serial input/output common-cathode display drivers that interface to microcontrollers and microprocessors to control 7-segment numeric LED displays of up to 8 digits, bar-graph displays, or 64 individual LEDs. Included on the MAX7219 chip is a BCD code-B decoder, a multiplex scan circuitry, a segment and digit drivers, and an 8×8 static RAM that stores each digit. Only one external resistor is required to set the segment current for all LEDs. The MAX7221 is compatible with SPI, QSPI, and MICROWIRE communication protocols, and has slew-rate-limited segment drivers to reduce EMI. Individual digits of the connected LED display may be addressed and updated without rewriting the entire display. The MAX7219/MAX7221 also allow the user to select code-B decoding or no-decode for each digit.
The components required for this project are;
Do note that the 8×8 LED matrix used in this tutorial already comes with the LED Driver attached as its common with most 8×8 LED modules these days. To get it, just follow the link attached to it.
Connect the Module to the Arduino as shown in the Fritzing schematics below.
here is a pin map of the connection for clarity.
Display - Arduino VCC - 5V GND - GND DIN - D12 CS - D11 CLK - D10
Creating Graphics for Display on the LED Matrix
Before we proceed to writing the code for this project, I would like to show you an easy way of creating the graphics to be displayed on the LED Matrix and generating the byte array that will be used in the code to represent the graphics to be displayed. To do this, we will use a very lightweight software which I found online, called “PixeltoMatrix”.
This software allows you draw your graphics by highlighting boxes like some dots connecting sort of game, then generates the byte array which you can then copy and use in your code.
pretty cool right? I thought so too.
To ensure ease of the code process, we will use the LEDcontrol library which can be downloaded from here. This Library makes the process of programming the Arduino to drive the LED matrix easy. So as usual, download the library, extract it and copy to your Arduino libraries folder, then start the Arduino IDE.
The first thing we do in the code as usual, is to include the libraries that will be used, then we declare the pins on the arduino to which the LED Matrix is connected.
After declaring the pins, we declare the byte arrays that describe the graphics to be displayed. The byte arrays were generated as described in the previous section. The first one for instance is the byte array to display a smile.
After the byte arrays for the graphics to be displayed has been created, we then create an object of the LCDcontrol library.
Next, we move to the void setup() part of the code. With the library lifting most of the heavy loads we don’t have much to do. The first thing we do in the loop section is call take the MAX7219 out of the power saving mode, then we set the brightness of the display using the lc.setintensity() function, after which we clear the display, making it ready to receive data.
With this done, we then go to the void loop() function which featured some more declaration of graphics byte arrays, and the display of the graphics on the LED Matrix. The display of a graphics on the LED matrix is done via the function, printbyte(), with the argument of the function being the name of the byte array representing the graphics to be displayed. For example, printbyte(smile) prints the graphics “smile” as described by its byte array.
After displaying the graphics, the delay() function is used to keep the graphics on the LED matrix for a specific number of seconds.
Every other part of the code is a slight modifications to things we already know and is easy to follow.
The full Code for the project is available below and also attached in the zip file provided under the download section which can be found at the end of this post.
Upload the code to your Arduino board, you should see something like the image below.
That’s it for this tutorial guys, don’t forget to leave questions, and comments, in the comments section of the tutorial.
Till next time, Keep Building!
The youtube video for this tutorial is available via the attached link, here