Power Up An LED Matrix With Arduino And MAX7219
An LED matrix is a display made up of multiple LEDs in a rectangular distribution. There are different sizes, the most common being the 8×8 LED squares.
We can combine several modules to form a much larger display . In these displays we can show texts, drawings or animations, such as moving a text (scroll).
Powering an LED matrix directly with the Arduino requires a large number of pins, which would be a huge waste of resources. For this reason, it is normal that we always use a controller specifically designed for this function.
A controller commonly used because it is cheap and simple is the integrated MAX7219.
Table of Contents
Monochrome (red or green) LED arrays are cheap components. They are sold both together with the MAX7219 controller, and both components separately. The normal thing is that we want to buy them together .
We can find a set of 8×8 LED Matrix + MAX7129 controller for €1.27 in international sellers on Ebay or Aliexpress.
In addition, these modules incorporate input and output pins, so it is easy to join several modules to form a larger display, simply using connection jumpers.
How Does An LED Matrix Work?
An LED matrix is made up of different LEDs, wired together in rows and columns. We can turn on a given LED in the array by correctly applying the HIGH and LOW values to its respective row and column.
There are two possible configurations, common anode in rows or in columns. Although this does not affect the explanation, you must take it into account in your montages.
If we apply HIGH and LOW values to several rows and columns simultaneously, all the LEDs of the intersections will light up . In this way, it is almost impossible to generate complex graphics.
In order to make graphs , the procedure consists of doing a sweep by rows (or columns). We turn on all the LEDs in a single row (or column), and then switch to the next. Only one row (or column) is lit at any one time, but by doing so quickly, the effect on our vision is to see the entire formed image simultaneously.
This effect is called “Persistence of Vision” (POV) , and it is a consequence of the way in which humans perceive movement. It is widely used in electronics and computing.
Turning on an 8×8 LED matrix would require 16 digital signals and constant processor work to refresh the image. That is a huge amount of resources for any automaton , which we would be using badly to simply turn on a display.
For this reason, we use a controller like the MAX7219 that is specially designed to power 7-segment displays and LED arrays, and frees up our processor to do much more valuable tasks.
Communication with the MAX7219 is via SPI so only 3 Arduino pins (SS, MOSI and SCK) are required. In addition, we do not even “occupy” these pins completely, since with the same bus we can control multiple devices .
Finally, the MAX7219 boards themselves generally incorporate an input and output port, so that we can combine multiple controllers without any difficulty.
The electrical schematic is simple. We power the module through Vcc and Gnd, and connect the corresponding pins for SPI communication.
In case of using more than one module, we would connect the outputs of each module with the inputs of the next one, and we would connect the first one to Arduino.
The connection seen from the Arduino side would look like this.
Pin numbers depend on the specific model of Arduino . In Arduino Uno and Nano they correspond to pins 10, 11, and 13. Consult the pinout diagram for other models.
There are several libraries to communicate Arduino with a MAX7219 controller. For example, we have the Max72xxPanel library , which requires the use of the Adafruit-GFX library .
The following sample code uses these two libraries to display scrolling text across 9 linked LED arrays. Modify the code to suit your configuration and needs.