bclose

8×8 SPI LED MATRIX WITH MAX7219

Objectives

 

 

    • Introduce the 8×8 LED matrices controlled by a MAX7219.
    • Show a prototype
    • Display different messages.
 

Bill of materials

Imagen de Arduino UNO  Arduino UNO or equivalent.
Protoboard conexiones

A Breadboard plus some jumper wires..

Array LED 8x8

A 8×8 LED matrix controlled by a MAX7219

LED matrices

 

If I you have endured this far, you are already familiar with the idea that when in electronics something sucks, either for being laborious, heavy or annoying, someone invents an integrated circuit that solves the problem for us, so we can dedicate ourselves to think on what we want and not to be concerned whether a wire is loose or you have defined correctly the character arrays.

And as you could suspect, the 8 × 8 LED arrays are no exception.

In fact, we have a widespread integrated circuit manufactured by Maxim, the MAX7219 / MAX7221, that makes us become reconciled to the LEDs arrays and even with the 7-segment LED displays. Their features are:

 
  • Input and output are built-in in series, this way it requires fewer pins.
  • It can handle 7-segment LED displays up to 8 digits.
  • It can handle bar LED displays.
  • It can handle 8×8 LED matrices or up to 64 LED diodes.
  • It only requires an external resistor for all the 64 LEDs.
  • It includes a BCD decoder (There is no need to draw character arrays, they are all built-in: uppercase, lowercase and even numbers and punctuation signs).
  • It handles the multiplexing of characters and digits.
  • It includes memory to store the characters.
  • It supports SPI and QSPI (someday we’ll have to talk about the SPI bus).
  • It’s cheap and available for a few euros.
 

So the only reason to hand-wire any type of LED displays is to understand the circuit and learn (suffering, of course), but in the real world will use a chip like this, because it will save many hours of uttering insults.

Array LED 8x8

In the future we will include a chapter to show how to deal with these displays using the chip directly, but for now we will deal with a breakout board that includes an 8×8 dot LED array and one of these chips.

For less than the worth of their components, we can buy a breakout board with a 8×8 dot LED matrix governed by a MAX7219 and forget about further complications. They are easy to assemble on a breadboard and besides they can be connected in cascade, i.e., we can connect up to 8 in series. The connection with our Arduino is via an asynchronous SPI serial port.

CIRCUIT WIRING DIAGRAM

 

Again, when an external controller is used, the connection is trivial.

Esquema electrico

And for the breadboard:

protoboard

 

THE CONTROL PROGRAM

 

To handle the array, there is a control library available, called LedControlMS and can be downloaded from here adafruit LEDControl library

Once you’ve installed the library, Sketch\ Include Library\ Add ZIP. Library…, you must first include the following statement:

#include "LedControlMS.h"

After that we must indicate how many displays we are going to use, only one for now, and then create a LedControl class object. We must pass it the control pin numbers and the number of matrices that we are going to use:

#define NumMatrix 1
LedControl lc=LedControl(12,11,10, NumMatrix);

When the sketch starts all the arrays are in standby mode, so we must activate them first.

for (int i=0; i< NumMatrix ; i++)
   {
     lc.shutdown(i,false);  // Activate the matrix
     lc.setIntensity(i,8);  // Set brightness to an intermediate level 
     lc.clearDisplay(i);    // Clear it all
   }

And now we have just to write the message:

lc.writeString(0,"Arduino course by Prometec.net");

In summary, the entire sketch to write a message could be like this:  Prog_38_1 

#include "LedControlMS.h"
#define NumMatrix 1      // It declares how many matrices we are going to use

LedControl lc=LedControl(12,11,10, NumMatrix);  // Create a LedControl object
void setup()
   {
      for (int i=0; i< NumMatrix ; i++)
        {
            lc.shutdown(i,false);  // Activate the matrix
            lc.setIntensity(i,8);  // Set brightness to an intermediate level 
            lc.clearDisplay(i);    // Clear it all
        }
   }

void loop()
   {
        lc.writeString(0," Arduino course by Prometec.net ");
        delay(1000);
   }

As you can see, just like in the previous chapter, we don’t have to define character arrays or worry about multiplexing the pins.

 
  • I am a staunch defender of working the minimum to achieve our goals (in computer jargon is called optimizing resources), but this is because the guys from Adafruit, to whom we will never thank enough, have developed a library for us.
  • But make no mistake, this library below does exactly what we saw in the previous chapter. It defines the character arrays and the LED multiplexing functions.
  • If you have interest, (there will be someone, I presume) you can check it, because navigating to \\File\Open … you can find two sketches in your library directory, usually \Documents\Arduino\libraries\LedControlMS in Windows, and by loading LedControlMS.cpp you will see the sketches that form the library (do not panic, these libraries are not intended to be understood by newbies).
 

 

Summary

 

 

    • We have seen, very quickly, the features of MAX7219.
    • We will speak further about this IC in the future because is very useful to handle different kinds of LED displays.
    • We have seen that the manufacturers ship already 8 × 8 SPI LED matrices with a built in MAX7219, that can be very easily handled if we want to show alphanumeric messages.
 

 

 

 

No Comments

Give a Reply