Home

Guide no. 83

A module with the MAX7219 chip, five wires and an Arduino UNO: a smiley face drawn row by row, then text scrolling across four matrices.

By Ada Intelisano · informaticait.it technical team

Download the PDF (A4, 6 pages) Free to print and share, without changes — CC BY-ND 4.0
In short
  • The MAX7219 drives the 64 LEDs of the matrix on its own: Arduino sends it orders over three wires, DIN, CLK and CS.
  • Five wires: VCC to 5V, GND to GND, DIN to pin 11, CLK to 13, CS to 10. Hold the module with the input on the right.
  • A picture is eight numbers, one per row: each 1 is an LED that is on. Library: MD_MAX72XX.
  • With the four-matrix module and the MD_Parola library, text scrolls from right to left.
Time: 45 minutesLevel: one header to solderBefore: guides no. 53 and 70

Eight rows and eight columns of red LEDs: with a matrix like this you can draw smiley faces, arrows and numbers, and with several matrices in a row you can scroll text like on a shop sign. Lighting 64 LEDs one by one would take too many pins, so the module has a chip, the MAX7219, that does all the work. Arduino talks to it over three wires.

1Get the parts ready

  • an 8×8 matrix module with the MAX7219: it comes with two five-pin headers to solder, one straight and one bent at a right angle;
  • Arduino UNO with its USB cable and five female-to-male jumper wires;
  • for the last step, the four-matrix module (32 × 8 LEDs), which already has its header soldered on.
New word: LED matrixLEDs arranged in rows and columns. Here each of the 64 dots is an LED: by turning some on and leaving others off you draw a picture, like filling in the squares on graph paper.

2How one chip drives 64 LEDs

The MAX7219 does not keep all the LEDs on at the same time. It lights one row at a time and moves on to the next so quickly that your eye sees the whole picture: the datasheet gives a typical 800 scans per second through all eight rows. A single resistor on the module sets how much current flows through the LEDs, and Arduino only sends the orders: which row to change and which LEDs to light.

New word: multiplexingLighting different parts of a display in turn, very quickly. It takes fewer wires and less current, and the eye does not notice the trick. The 7-segment displays in guide no. 53 use it too.

3Solder the header and turn the module

Solder the right-angle header into the five holes on the IN side, the one with DIN, with the pins pointing sideways, outward (guide no. 70). You only need the straight header on the OUT side if one day you want to add a second module.

The MAX7219 8×8 module: keep the input on the right→INOUT→MHVCCVCCGNDGNDDOUTDINCSCSCLKCLK← OUTIN ←CLKCSDINGNDVCCfrontbackinput (IN) on the rightflipped top to bottomupside-down text: that is fineinformaticait.it

Then hold the module with the input on the right. The “→IN” and “OUT→” labels on the circuit board end up upside down, and that is fine: the documentation of the library we are going to use says exactly that these modules should be held with the DIN side on the right and that the printed text may appear upside down.

4Connect the five wires

The wiring: five wires, no resistorsSCLSDAAREFGND131211109876543210IOREFRESET3.3V5VGNDGNDVINDIGITAL (PWM ~)POWERANALOG INUNO→INOUT→MAX7219 module (front)the five wiresCLK → pin 13CS → pin 10DIN → pin 11GND → GNDVCC → 5Vinformaticait.it
  • VCC to 5V and GND to GND: the chip works between 4 and 5.5 V.
  • DIN to pin 11 and CLK to 13: these are the SPI pins of the Arduino UNO, the fast link the library uses to send data, and they cannot be changed.
  • CS to pin 10. This one you can move: just write the new number in the sketch.

5Install the library

In the Library Manager search for MD_MAX72XX by majicDesigns and install it; while you are there, also install MD_Parola by the same author, which you will need at the end. If INFO: ARDUINO SPI interface selected appears while compiling, don't worry: it is a notice the library always prints, not an error.

6Draw a smiley face

A picture in eight numbers: 1 on, 0 off76543210bit00b0011110010b0100001020b1010010130b1000000140b1010010150b1001100160b0100001070b00111100rowin the sketchinformaticait.it

Each row of the matrix is a number with eight binary digits, written with 0b in front: 1 is an LED that is on, 0 one that is off, and the leftmost digit is the leftmost LED. Eight numbers, from top to bottom, make a picture.

// 8x8 matrix with the MAX7219: a smiley face and a heart, drawn row by row.
// Library: MD_MAX72XX by majicDesigns.
#include <Arduino.h>
#include <MD_MAX72xx.h>

// DIN to pin 11 and CLK to 13 (these are fixed), CS to 10
MD_MAX72XX matrix(MD_MAX72XX::FC16_HW, 10, 1);   // module type, CS pin, matrices

// eight numbers, one per row from the top: 1 = LED on, 0 = off
const byte SMILEY[8] = {
  0b00111100,
  0b01000010,
  0b10100101,
  0b10000001,
  0b10100101,
  0b10011001,
  0b01000010,
  0b00111100,
};
const byte HEART[8] = {
  0b00000000,
  0b01100110,
  0b11111111,
  0b11111111,
  0b01111110,
  0b00111100,
  0b00011000,
  0b00000000,
};

void draw(const byte picture[8]) {
  for (byte row = 0; row < 8; row++) {
    matrix.setRow(row, picture[row]);   // the bit on the left is the LED on the left
  }
}

void setup() {
  matrix.begin();
  matrix.control(MD_MAX72XX::INTENSITY, 2);   // brightness from 0 to 15
}

void loop() {
  draw(SMILEY);
  delay(2000);
  draw(HEART);
  delay(2000);
}

setRow(row, number) lights the LEDs of one row; INTENSITY sets the brightness from 0 to 15. FC16_HW tells the library how the matrix is wired to the chip.

✓ What you should seeThe smiley face smiles for two seconds, then a heart appears, then the smiley face again.
If it doesn't work
  • All dark: is VCC on 5V? Are DIN and CLK on pins 11 and 13, and not swapped? Are the jumper wires on the IN side?
  • Smiley face upside down: turn the module half a turn, with the IN header on the right.
  • Picture in pieces or sideways: your module wires the LEDs to the chip in a different way. Instead of FC16_HW try GENERIC_HW, then PAROLA_HW and ICSTATION_HW: the library author suggests trying them one after the other, and nothing gets damaged.

7Brightness and current

The MAX7219 sets the brightness by keeping the LEDs on for part of the time: with INTENSITY at 0 they stay on for 1/32 of each scan, with 15 for 31/32 (datasheet). So even at 0 they do not go completely dark.

  • With all the LEDs on at the maximum recommended current, 40 mA, the datasheet gives 330 mA typical for each chip. How much current actually flows in your module depends on the resistor fitted, and the maker does not state it.
  • An Arduino powered from a computer's USB port usually has no more than 500 mA available. With four matrices fully lit at maximum you could reach 4 × 330 = 1.32 A (our calculation, worst case).
  • That is why the brightness in the sketches is low, 2 and 1: you can see it well and the USB port can cope. For big, bright text use a separate 5 V power supply for the modules, with its GND joined to the Arduino GND, as the library author advises and as in guide no. 82.

8Scrolling text

The four-matrix module has four MAX7219 chips in a row, each one passing the data on to the next. It connects with the same five wires to the header on the right, the input one. The library counts the matrices from the right: number 0 is the one attached to Arduino.

The four-matrix module: 32 × 8 LEDsmatrix 0matrix 1matrix 2matrix 3the one wired to Arduinothe text scrolls to the leftINinformaticait.it
// Text scrolling across the four-matrix module (32 x 8 LEDs).
// Libraries: MD_Parola and MD_MAX72XX by majicDesigns.
#include <Arduino.h>
#include <MD_Parola.h>

// DIN to pin 11, CLK to 13, CS to 10, as for the single matrix
MD_Parola message(MD_MAX72XX::FC16_HW, 10, 4);   // module type, CS pin, matrices

void setup() {
  message.begin();
  message.setIntensity(1);                                   // from 0 to 15
  message.displayScroll("Hello from Arduino!", PA_LEFT, PA_SCROLL_LEFT, 50);
}

void loop() {
  if (message.displayAnimate()) {   // true when the whole text has scrolled out
    message.displayReset();         // and then it starts again from the right
  }
}

displayScroll sets up the text: alignment, effect and speed, that is the milliseconds between one step and the next (the lower the number, the faster it runs). displayAnimate() must be called over and over in the loop, without delay: it is what moves the letters at the right moment.

✓ What you should see“Hello from Arduino!” comes in from the right, crosses the four matrices and leaves on the left, then starts again.
If it doesn't work
  • Letters upside down: the input header must be on the right. It is the mistake the library author sees most often.
  • Text cut off or repeated in pieces: in the line MD_Parola message(...) the last number must be 4.
  • Accented letters that come out wrong: the library has an example just for them (Parola_UFT-8_Display); to begin with, write without accents.

9And with the ESP32?

With the ESP32 the module cannot be connected directly. The MAX7219 needs 4 to 5.5 V and is only sure to read a “1” on the data wires from 3.5 V up (datasheet): the 3.3 V of the ESP32 is below that. You need the module on 5 V and a level shifter on DIN, CLK and CS (guide no. 21). For 3 V circuits Analog Devices points to a different chip, the MAX6951. With the Arduino UNO, which runs at 5 V, these problems do not come up: that is why this guide uses the UNO.

Try it yourself
  • Draw an arrow, your initial or a sad face: change the eight numbers.
  • Make the heart blink with matrix.clear() and two pauses.
  • Change the text and the speed, from 20 to 100.
✓ What you learned
  • the MAX7219 lights the rows in turn, so fast that you cannot see it;
  • each row is an eight-bit number, 1 on and 0 off;
  • the modules are held with the input on the right and counted from the right.
Sources: Analog Devices (Maxim Integrated), MAX7219/MAX7221 Serially Interfaced, 8-Digit LED Display Drivers, datasheet 19-4452 Rev 6 (8/2021) · majicDesigns (Marco Colli), MD_MAX72XX 3.5.1 and MD_Parola 3.7.5 libraries: documentation (FC-16 Module, System Connections, coordinates) and examples; arduinoplusplus blog, “Parola A to Z” · Arduino, documentation of the UNO power pins · informaticait guides no. 21, 53, 70 and 82

Useful products

Other guides

All our guides →
Loading...
Back to top