MAX7219 eight-digit display

Eight red seven-segment digits on a MAX7219 module, three wires in and a cascade out. Aliases: 8-digit MAX7219 module, LedControl display.

It is the display in homemade scoreboards, counters, clocks and frequency meters. The chip holds one register per digit and scans all eight itself, so the sketch writes a digit once and it stays lit. This is the same MAX7219 as the 8x8 matrix module, on the other board it is sold on.

Pins

Pin What it does
VCC Supply, 4 V to 5.5 V.
GND Ground.
DIN Serial data in, shifted on every rising CLK edge.
CS Latches the last 16 bits as one register write, on its rising edge. Some boards print LOAD.
CLK The shift clock.
DOUT The far end of the chip's 16-bit shift register, to chain a second module.

How it talks

A write is 16 bits, most significant first, with CS low: four unused bits, a register address and a data byte. Registers 0x01 to 0x08 are digits 0 to 7, and digit 0 is the rightmost. Each digit's byte is its segments, DP A B C D E F G from bit 7 down, unless the Code B decode (0x09) is on for it, when the low four bits are a number. 0x0A is the intensity (0 to 15), 0x0B how many digits are scanned, 0x0C shutdown (0 blanks the display and keeps the digits) and 0x0F the display test. At power on every register is zero, so the display is in shutdown and shows nothing until the sketch wakes it.

The library

LedControl.h works as its tutorial uses it:

#include "LedControl.h"

LedControl lc = LedControl(12, 11, 10, 1);  // DIN, CLK, CS, number of modules

void setup() {
  lc.shutdown(0, false);  // wake it up
  lc.setIntensity(0, 8);
  lc.clearDisplay(0);
}

void loop() {
  for (int i = 0; i < 8; i++) {
    lc.setDigit(0, i, i, false);
  }
  delay(1000);
  lc.setChar(0, 7, 'H', false);
  lc.setChar(0, 6, 'E', false);
  lc.setChar(0, 5, 'L', false);
  lc.setChar(0, 4, 'P', true);
  delay(1000);
}

setDigit(module, digit, value, dp) writes a number 0 to 15, setChar() a character (0 to 9, A to F, H, L, P, U, -, _, . and space), and setRow() raw segments. setScanLimit(), setLed() and setColumn() are there too, for the matrix. The first argument picks a module in a chain, 0 being the one nearest DIN. Note the pin order: LedControl takes DIN, CLK, then CS.

What the model gets right

Everything the matrix module does, from the MAX7219 datasheet: the shift register that clocks whatever CS is doing, the latch on the rising edge of CS, the cascade through DOUT, Code B decode, intensity, scan limit, shutdown and the display test, and the power-on state.

What it does not model

The digit multiplexing as flicker, the segment current set by the board's resistor, and the 4 V minimum as a dimmer display: below it the module is off.

Common mistakes

Forgetting lc.shutdown(0, false). The chip starts in shutdown and shows nothing until it is woken.

Counting digits from the left. Digit 0 is the rightmost.

Swapping CLK and CS in the constructor. LedControl's order is DIN, CLK, CS.

See it in action

Scoreboard keeps two teams' scores and a game clock on one module. Open it at /templates.