Chained matrices and lamps
Two MAX7219 LED matrices in a chain on the Arduino: how a message travels along the chain, the current they draw, a scrolling score with MD_Parola and lamps

Our pinball machine’s display has four LED matrices, and the show Uno has only three pins for them. That’s enough, because modules with the MAX7219 chip can be joined in a chain: the Arduino sends data to the first module, and it passes them on to the next one. Today we’ll join two matrices in a chain and see how a message travels from one to the other.
Then we’ll measure how much current a matrix uses and scroll a score across both matrices with the help of a ready-made library, and then turn the modules so that the matrices sit side by side. At the end, the instructor will show how the same chip also lights ordinary LEDs, like the lamps on the pinball machine’s playfield.
What does this mean for the pinball machine?

On the top view of our pinball machine, a blue circle marks three arrows in the middle of the playfield, and the large circle shows the same arrows enlarged. These are lamps: under each one is an LED that shows the player where to send the ball. The pinball page explains the other parts of the drawing.
- The pinball machine's display is four matrices in a chain, like the two today. The show Uno drives the whole chain over three pins, and writes the score and messages with the MD_Parola library, as in Exercise 3.
- The lamps on the playfield, like these arrows, are lit by one more MAX7219, without a matrix, at the end of the same chain. One chip can light up to 64 lamps, and they don't need resistors.
- Four matrices with every LED lit use about 0.6 A at half brightness and about 1.3 A at full brightness, more than USB may give. That's why the display and the lamps in the pinball machine are powered by the 5 V of a computer power supply, not by an Arduino.
How a chain works
Each module has two headers: the input one, marked DIN, and the output one, marked DOUT. In a chain we connect the output header of one module to the input header of the next:
- DIN goes only to the first module. The data come out of it on DOUT and go into the next module.
- CLK and CS go to every module, as do VCC and GND. Every module gets the same clock and the same frame of a message.
Remember the shift register from the last lesson: at each pulse on CLK, the chip reads one bit from DIN and pushes the other bits one place on. The register has 16 places. When it’s full, the bit that drops out of the other end comes out on DOUT. So in a chain every bit goes through the first chip and into the second.

That’s why a message for a chain of two modules is 32 bits long: the first 16 bits for the module further from the Arduino, and the second 16 for the module on the Arduino. CS stays LOW during the whole sending. In the picture, after the first 16 pulses the message for module 1 is still in module 0. After the next 16 pulses it has moved into module 1, and module 0 holds the second message, 16 zeros. When CS goes back to HIGH, each chip looks at its own 16 bits: module 1 writes 01100110 into row 2, and module 0 does nothing.
Sixteen zeros are a no-op message (from no operation). It has the address 0: the chip receives it but changes nothing. We need it when we want to change only one module in a chain, because all the others must then get a no-op.
We number the modules from the Arduino: module 0 is connected to the Arduino, and module 1 comes after it. The modules sit as in the last lesson, with the input header on the left, next to the chip. The output header is then on the right, so module 1 is to the right of module 0 and the chain grows to the right. The Arduino is on the right in the picture above only so that the bits of each message read from left to right, in the order they were sent.
How many bits does the Arduino send in one message for a chain of four modules?
Materials
Each participant gets:
- an Arduino Uno and a USB cable
- two modules with an 8 × 8 LED matrix and a MAX7219 chip
- five female–male jumper wires and five female–female ones, about 20 cm long (they often come with the module)
- for Exercise 2: a multimeter, a small breadboard, three male–male jumper wires and two wires with crocodile clips
If there aren’t enough modules, two participants who sit next to each other join their modules in a chain on one Arduino and work together.
Wiring
- While we wire, the Arduino is unplugged from the USB cable.
- Connect module 0 to the Arduino as in the last lesson, with female–male wires to its input header, on the left.
- Put module 1 to the right of module 0, turned the same way as module 0. With female–female wires, connect the output header of module 0 to the input header of module 1.
- The instructor checks the wiring. Swapped VCC and GND can damage both chips.
The Arduino and module 0 are wired as in the last lesson:
| Arduino pin | 5V | GND | D2 | D3 | D4 |
|---|---|---|---|---|---|
| Module 0, input | VCC | GND | DIN | CS | CLK |
The output of module 0 goes to the input of module 1, each pin to the pin of the same name, except DOUT, which goes to DIN:
| Module 0, output | VCC | GND | DOUT | CS | CLK |
|---|---|---|---|---|---|
| Module 1, input | VCC | GND | DIN | CS | CLK |

Two matrices at brightness 1 use little current, so the Arduino may power them from USB. We’ll measure exactly how much in Exercise 2.
Exercise 1: A picture on each module
Let the left-hand matrix show the heart from the last lesson, and the right-hand one a smiley.
The program
// C++
const int DIN = 2; // data, only into the first module in the chain
const int CS_PIN = 3; // frame of a message, into every module
const int CLK = 4; // clock, into every module
const byte MODULE_COUNT = 2; // how many modules are in the chain
const byte NO_OP = 0; // address 0: the chip changes nothing
const byte DECODE = 9;
const byte BRIGHTNESS = 10;
const byte ROW_COUNT = 11;
const byte POWER = 12;
const byte TEST = 15;
byte heart[8] = {
B01100110,
B11111111,
B11111111,
B11111111,
B01111110,
B00111100,
B00011000,
B00000000,
};
byte smiley[8] = {
B00111100,
B01000010,
B10100101,
B10000001,
B10100101,
B10011001,
B01000010,
B00111100,
};
// Sends the same message to every module in the chain.
void sendAll(byte address, byte data) {
digitalWrite(CS_PIN, LOW);
for (byte m = 0; m < MODULE_COUNT; m++) {
shiftOut(DIN, CLK, MSBFIRST, address);
shiftOut(DIN, CLK, MSBFIRST, data);
}
digitalWrite(CS_PIN, HIGH);
}
// Sends a message to one module only. Module 0 is connected to the Arduino, and module 1 comes after it.
void send(byte module, byte address, byte data) {
digitalWrite(CS_PIN, LOW);
for (int m = MODULE_COUNT - 1; m >= 0; m--) { // the message for the furthest module first
if (m == module) {
shiftOut(DIN, CLK, MSBFIRST, address);
shiftOut(DIN, CLK, MSBFIRST, data);
} else {
shiftOut(DIN, CLK, MSBFIRST, NO_OP); // the other modules: no-op
shiftOut(DIN, CLK, MSBFIRST, 0);
}
}
digitalWrite(CS_PIN, HIGH);
}
// Sends all eight rows of a picture to one module.
void show(byte module, byte picture[8]) {
for (byte r = 0; r < 8; r++) {
send(module, r + 1, picture[r]);
}
}
void setup() {
pinMode(DIN, OUTPUT);
pinMode(CS_PIN, OUTPUT);
pinMode(CLK, OUTPUT);
digitalWrite(CS_PIN, HIGH);
sendAll(TEST, 0);
sendAll(DECODE, 0);
sendAll(ROW_COUNT, 7);
sendAll(BRIGHTNESS, 1);
for (byte row = 1; row <= 8; row++) {
sendAll(row, 0);
}
sendAll(POWER, 1);
show(0, heart); // on the left, the module connected to the Arduino
show(1, smiley); // on the right, the second module in the chain
}
void loop() {
}
Upload the program. Is the heart on the left and the smiley on the right?
What’s new in the program?
sendAll()– The same assend()from the last lesson, but it sends the address and the data once for each module, and only then takes CS back toHIGH. Every module gets the same message. This is how we set up all the chips at once.send(byte module, byte address, byte data)– The function now has three parameters: the first says which module the message is for. For each module in the chain it sends 16 bits: the real message to our module, and a no-op to the others.for (int m = MODULE_COUNT - 1; m >= 0; m--)– The loop counts backwards, from the furthest module towards module 0, because the message sent first travels furthest.m--takes 1 away fromm. The counter is anint, not abyte, because abytecan’t be less than 0: after 0 would come 255, so the conditionm >= 0would never be false and the loop would never stop.show(0, heart)– Likeshow()from the last lesson, only with the module’s number first.
Try it:
- Swap the pictures:
show(0, smiley);andshow(1, heart);. - At the end of the
setup()function, addsend(1, BRIGHTNESS, 8);. The right-hand matrix now lights more brightly, and the left-hand one stays the same: each chip has its own registers. Then delete that line. - Change
MODULE_COUNTto 1 and upload the program. What do the matrices show now? The explanation is in the quiz below. Then set it back to 2.
Why do both matrices show the heart with MODULE_COUNT = 1?
Exercise 2: How much current do the matrices use?
While a row of the matrix lights, about 40 mA flows through each LED that is lit in it. That current is set by the resistor R1 on the module, connected to the ISET pin. A row lights only part of the time, and the brightness decides how much: at brightness 0 one 32nd of the time that belongs to it, at brightness 1 three 32nds, and at brightness 15 thirty-one 32nds. Each step in between is two 32nds. The chip itself uses about 8 mA more.
When every LED lights, eight of them light in each row, so a matrix uses roughly:

We’ll check that with a multimeter. The program lights every LED on the left-hand matrix, switches the right-hand matrix off, and changes the brightness every five seconds: 0, 3, 7 and round again. It prints the brightness the matrix has right now in the Serial Monitor.
Brightness 7 at most
A multimeter on its 200 mA setting mustn't measure more than 200 mA, and a matrix at brightness 10 or more uses more than that. The fuse in the multimeter would blow. That's why the program in this exercise doesn't go above brightness 7.
While the red probe is in the mA socket, the multimeter is like a piece of wire. If you touch 5V and GND with the probes, you've made a short circuit. That's why everything is connected while the USB cable is unplugged.
The program
The sendAll() and send() functions are the same as in Exercise 1. We don’t need the pictures.
// C++
const int DIN = 2;
const int CS_PIN = 3;
const int CLK = 4;
const byte MODULE_COUNT = 2;
const byte NO_OP = 0;
const byte DECODE = 9;
const byte BRIGHTNESS = 10;
const byte ROW_COUNT = 11;
const byte POWER = 12;
const byte TEST = 15;
const byte STEPS[3] = {0, 3, 7}; // the brightness values we measure, never more than 7
const unsigned long DURATION = 5000; // ms for each brightness
byte step = 0; // which brightness from the array is on now
unsigned long lastChange = 0;
void sendAll(byte address, byte data) {
digitalWrite(CS_PIN, LOW);
for (byte m = 0; m < MODULE_COUNT; m++) {
shiftOut(DIN, CLK, MSBFIRST, address);
shiftOut(DIN, CLK, MSBFIRST, data);
}
digitalWrite(CS_PIN, HIGH);
}
void send(byte module, byte address, byte data) {
digitalWrite(CS_PIN, LOW);
for (int m = MODULE_COUNT - 1; m >= 0; m--) {
if (m == module) {
shiftOut(DIN, CLK, MSBFIRST, address);
shiftOut(DIN, CLK, MSBFIRST, data);
} else {
shiftOut(DIN, CLK, MSBFIRST, NO_OP);
shiftOut(DIN, CLK, MSBFIRST, 0);
}
}
digitalWrite(CS_PIN, HIGH);
}
void setup() {
Serial.begin(9600);
pinMode(DIN, OUTPUT);
pinMode(CS_PIN, OUTPUT);
pinMode(CLK, OUTPUT);
digitalWrite(CS_PIN, HIGH);
sendAll(TEST, 0);
sendAll(DECODE, 0);
sendAll(ROW_COUNT, 7);
sendAll(BRIGHTNESS, STEPS[0]);
for (byte row = 1; row <= 8; row++) {
sendAll(row, 0);
}
sendAll(POWER, 1);
for (byte row = 1; row <= 8; row++) {
send(0, row, B11111111); // the left-hand matrix: every LED
}
send(1, POWER, 0); // the right-hand matrix off, we measure only the left one
Serial.print("Brightness: ");
Serial.println(STEPS[step]);
}
void loop() {
if (millis() - lastChange >= DURATION) {
lastChange = millis();
step++;
if (step == 3) {
step = 0;
}
sendAll(BRIGHTNESS, STEPS[step]);
Serial.print("Brightness: ");
Serial.println(STEPS[step]);
}
}
Upload the program before you connect the multimeter. The left-hand matrix now lights completely, and changes its brightness every five seconds. Open the Serial Monitor and set it to 9600 baud.
Measuring
Current is measured in series: the multimeter must be part of the circuit, so we put it into the red wire that brings 5 V to the modules. Why that is so is explained on the Multimeter page.
- Unplug the USB cable.
- On the multimeter, put the black probe into COM and the red one into mA. Set the switch to DC current, at the 200 mA setting (or mA⎓, if your multimeter chooses the range by itself).
- Pull the male end of the red wire, the one going to VCC of module 0, out of the 5V pin and push it into the breadboard, in row 14.
- With a male–male wire, connect the Arduino’s 5V pin to row 10 of the breadboard.
- Push one more male–male wire into each of rows 10 and 14. Clip the red probe with a crocodile clip to the free end of the wire from row 10, and the black probe to the end of the wire from row 14. The current now goes from 5V into row 10, through the multimeter into row 14 and on to the modules.
- The instructor checks the wiring. Then plug in the USB cable.

If the Serial Monitor shows nothing after you plug in the USB cable, close it and open it again.
For each brightness, write down the current the multimeter shows:
| Brightness | Expected | Measured |
|---|---|---|
| 0 | 18 mA | |
| 3 | 78 mA | |
| 7 | 158 mA |
The measured values can be up to a fifth lower than the expected ones. The R1 resistors and the LEDs aren’t all the same, USB gives a little less than 5 V, and the multimeter itself has a small resistance when it measures current. Does the current still rise evenly, by about 20 mA for each step of brightness?
After measuring, unplug the USB cable and put the red wire back into the 5V pin.
What does it mean?
- Two matrices with every LED at full brightness would use about 0.64 A, and USB from a computer may give 0.5 A. The Arduino would restart, or the computer would switch the USB off.
- A picture or a text lights far fewer LEDs than all 64. The heart from the last lesson has 38 LEDs lit and uses about 26 mA at brightness 1.
- The pinball machine has four matrices, so they are powered by a separate power supply, not by an Arduino. The pinball page says how the current is shared out in the machine.
Roughly how much does one matrix with every LED use at brightness 15?
Exercise 3: A scrolling score
In the last lesson we scrolled text across one matrix with our own font. For a chain of matrices we’d have to write all of that for several modules. A library called MD_Parola does that job for us: it has a ready-made font with every letter and digit, it can scroll text across the whole chain, and it has lots of effects. Like Bounce2 in the lesson on buttons, it’s ready-made code that we include in our program.
Installing the library
- In the Arduino IDE, open the Library Manager: the icon with books on the left, or the Sketch ⇒ Include Library ⇒ Manage Libraries… menu.
- Type MD_Parola into the search box.
- Install the MD_Parola library by majicDesigns. When the IDE asks whether to install the MD_MAX72XX library as well, choose Install all. MD_Parola uses it to talk to the chip.
Installing needs an internet connection. If there isn’t one at the workshop, the instructor installs the library on every computer beforehand.
Move module 1
The MD_Parola library expects module 0 to be the rightmost one, because text comes onto the display from the right. Our module 0 is on the left, so the text would come in at the middle of the display, with the halves swapped. So before this exercise:
- Unplug the USB cable.
- Pick up module 1 and put it to the left of module 0. All the wires stay on their pins.
- The wires between the modules now go round both modules: they leave the output header of module 0 to the right, go round the modules and come into the input header of module 1 from the left. The wires from the Arduino go into the input header of module 0, between the two modules. Keep the wires off the matrices.

The program
// C++
#include <MD_Parola.h> // a library for text on LED matrices
const int DIN = 2;
const int CS_PIN = 3;
const int CLK = 4;
const byte MODULE_COUNT = 2;
// The display: the type of module, the pins in the order DIN, CLK and CS, and the number of modules in the chain.
MD_Parola display(MD_MAX72XX::FC16_HW, DIN, CLK, CS_PIN, MODULE_COUNT);
long score = 0; // the score
char text[20]; // the text that scrolls across the display
void setup() {
display.begin(); // sets up the chips, clears and switches on the matrices
display.setIntensity(1); // brightness, 0 to 15
sprintf(text, "SCORE %ld", score); // writes SCORE and the number into text
display.displayText(text, PA_LEFT, 40, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
}
void loop() {
if (display.displayAnimate()) { // the text has gone across the display
score = score + 250; // as if the ball had hit a target
sprintf(text, "SCORE %ld", score);
display.displayReset(); // let the new text start again
}
}
Upload the program. Does SCORE 0 scroll across both matrices from right to left, then SCORE 250, SCORE 500 and on?
While the program compiles, the IDE prints an orange message #warning "INFO: ARDUINO SPI interface selected.". That’s not an error but a note from the library.
What’s new in the program?
#include <MD_Parola.h>– Includes the library in the program, like#include <Bounce2.h>in the lesson on buttons.MD_Parola display(MD_MAX72XX::FC16_HW, DIN, CLK, CS_PIN, MODULE_COUNT);–displayis an object that drives the whole chain. In the brackets we tell it the type of module, the pins and the number of modules. Watch the order: the library wants the pins in the order DIN, CLK, CS, not in the order they are wired to the Arduino.FC16_HW– The type of module. Makers wire the matrix’s LEDs to the chip in different ways, so the library must know which row is which. With the input header on the left, our modules are wired like modules of the FC-16 type. If the text is mirrored or upside down, or the letters scroll from top to bottom, changeFC16_HWtoGENERIC_HW,PAROLA_HWorICSTATION_HWand try again.display.begin();– Sets up every chip in the chain, clears the rows and switches the matrices on: everything oursetup()did in Exercise 1.display.displayText(text, PA_LEFT, 40, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);– Tells the display what to show and how. In order: the text, the alignment, the speed (how many milliseconds it waits between two steps), the pause (how many milliseconds the text stands still once it’s in; 0 means it doesn’t stop), and two effects, one for coming in and one for going out.PA_SCROLL_LEFTmeans scrolling to the left.display.displayAnimate()– Moves the text one step when it’s time and returnstruewhen the text has gone all the way. We must call it all the time, on every pass throughloop(), so there is nodelay()inloop(). Inside, the library watchesmillis(), like our beating heart in the last lesson. That’s whyloop()could do other things in the meantime, such as reading buttons.long score = 0;– Thelongtype stores whole numbers up to about two billion. On the Arduino Uno anintgoes only up to 32767, and a score in the pinball machine can be bigger. The page Variables and data types says more about types.char text[20];– An array of 20 characters that we write the text into. It must be big enough for SCORE, a space, all the digits of the number and the invisible character that marks the end of a text.sprintf(text, "SCORE %ld", score);– Writes SCORE and the value of thescorevariable into thetextarray.%ldis the place where a number of typelonggoes. The library shows exactly this array, so when we change it, the next pass shows the new score.display.displayReset();– Starts the same effect again.
Try it:
- Change the speed from 40 to 20, then to 100.
- For the text going out, put
PA_SCROLL_UPorPA_SCROLL_DOWNinstead ofPA_SCROLL_LEFT. - Make each pass bring a random number of points:
score = score + random(1, 11) * 100;. We met therandom()function in the reaction game.
The library takes up about two thirds of the Arduino Uno’s program memory, because it holds a font and lots of effects. That’s still enough for our programs, but in the pinball machine the show Uno has lots more to do, so we’ll keep an eye on it.
Why mustn't the loop() of a program with the MD_Parola library have delay(1000) in it?
displayAnimate() function moves the text only when it’s called. With delay(1000), loop() would call it only once a second, so the text would jump one step a second instead of scrolling smoothly.Exercise 4: Matrices side by side
In Exercise 3, both headers and the chip are between the two matrices, so there is a gap of about two centimetres between them. A letter moving from one matrix to the other is split into two parts. If we turn the modules a quarter turn, so that the chip is at the bottom, the headers are at the top and the bottom, and a module is as wide as its matrix. The matrices can then sit side by side, and the text scrolls without a gap, like on a real display.
Turn the modules
- Unplug the USB cable.
- Put module 1 back on the right of module 0, as in Exercise 1. Every wire stays on its pin.
- Turn both modules a quarter turn to the left, anticlockwise, so that the chip and the input header are at the bottom and the output header at the top.
- Move the modules together, so that the matrices almost touch.
- The wires between the modules go up from the output header of module 0, over module 1, down its right side, and come up into the input header of module 1 from below. The wires from the Arduino come up into the input header of module 0 from below. Don’t let the wires cover the matrices.
- The instructor checks the wiring.

The program
The program is like the one in Exercise 3, with three changes: the type of module, two new lines with setZoneEffect() and the scrolling direction in displayText().
// C++
#include <MD_Parola.h> // a library for text on LED matrices
const int DIN = 2;
const int CS_PIN = 3;
const int CLK = 4;
const byte MODULE_COUNT = 2;
// GENERIC_HW is for modules turned to the right, chip at the top. Ours are turned to the left, chip at the bottom.
MD_Parola display(MD_MAX72XX::GENERIC_HW, DIN, CLK, CS_PIN, MODULE_COUNT);
long score = 0; // the score
char text[20]; // the text that scrolls across the display
void setup() {
display.begin(); // sets up the chips, clears and switches on the matrices
display.setIntensity(1); // brightness, 0 to 15
display.setZoneEffect(0, true, PA_FLIP_UD); // flips the picture upside down
display.setZoneEffect(0, true, PA_FLIP_LR); // and left to right: half a turn together
sprintf(text, "SCORE %ld", score); // writes SCORE and the number into text
display.displayText(text, PA_LEFT, 40, 0, PA_SCROLL_RIGHT, PA_SCROLL_RIGHT); // on our modules: to the left
}
void loop() {
if (display.displayAnimate()) { // the text has gone across the display
score = score + 250; // as if the ball had hit a target
sprintf(text, "SCORE %ld", score);
display.displayReset(); // let the new text start again
}
}
Upload the program. Does SCORE 0 scroll from right to left across both matrices, without a gap between them?
What’s new in the program?
GENERIC_HW– The library knows modules like ours turned to the right, with the chip at the top. Ours are turned to the left, so half a turn the other way. The library therefore sees our display turned half a turn: its right is our left, and its top is our bottom. The library also has a type that describes exactly our turned modules,DR0CR0RR1_HW, but with it the text doesn’t scroll, and the bottom row just lights up. That’s why we useGENERIC_HW, which the library’s author has tried out.PA_SCROLL_RIGHT– For the library the text scrolls to the right, but on our modules, turned half a turn, it scrolls to the left. For the same reason module 0, which the library imagines on the far right, sits on the far left for us. That’s why module 1 is on the right again, as in Exercise 1.display.setZoneEffect(0, true, PA_FLIP_UD);– Switches on an effect that flips the picture on the display upside down.0is the number of the zone: our whole display is one zone.truemeans we switch the effect on.display.setZoneEffect(0, true, PA_FLIP_LR);– Flips the picture left to right as well. Both flips together turn the picture half a turn, so the letters are upright again. The scrolling direction stays the same: the text still scrolls to the left.
Try it:
- Slow the text down: change the speed from 40 to 100. Does a letter move from one matrix to the other without a gap?
- Put
//at the start of both lines withsetZoneEffect()and upload the program. The letters are now upside down, and the text still scrolls to the left. Then delete the//. - Change both
PA_SCROLL_RIGHTtoPA_SCROLL_LEFT. The text now comes in from the left and scrolls to the right. Then change them back toPA_SCROLL_RIGHT.
Why does the program say PA_SCROLL_RIGHT when the text scrolls to the left?
PA_FLIP_UD and PA_FLIP_LR only turn the letters upright; they don’t change the scrolling direction.Demonstration: lamps
The instructor does this demonstration, and everyone watches. The MAX7219 doesn’t know whether a matrix or ordinary LEDs are connected to it. A matrix is just 64 LEDs wired in rows and columns. So the same chip can also light the lamps under the pinball machine’s playfield, each in its own place.

On our modules the matrix is plugged into two rows of holes, a socket, so it can be taken out. Each hole is the end of one of the chip’s lines: one of the eight DIG lines (rows) or one of the eight SEG lines (columns). Before taking the matrix out, the instructor notes which way round it is, for example by the writing on its side: put back the wrong way round, it doesn’t light as it should.
Which hole is which depends on how the module is made, so the instructor finds out before the workshop. They take out the matrix and disconnect the module from the Arduino. They set the multimeter to continuity, touch a hole with one probe and the chip’s pins one after another with the other, until the multimeter beeps. Which pin of the chip is which line is shown in the drawing below. The demonstration needs the holes for DIG0 (pin 2), DIG1 (pin 11), SEG DP (pin 22), SEG A (pin 14) and SEG B (pin 16).

Steps:
- The instructor unplugs the USB cable and takes the matrix out of module 0.
- They push five LEDs of different colours into the breadboard, as in the schematic. With male–male wires they connect each LED’s anode to the hole for its SEG line, and its cathode to the hole for its DIG line.
- In the program from Exercise 1, instead of the two pictures, they send two rows:
send(0, 1, B11100000); // DIG0: DP, A and B, red, green and yellow send(0, 2, B11000000); // DIG1: DP and A, blue and white - They plug in the USB cable. Do all five LEDs light?
- They change the bytes, for example
send(0, 1, B01000000);. Only the green one lights. - At the end they unplug the USB cable, take out the LEDs and put the matrix back in its socket, the same way round as before.
Row 1 is the DIG0 line, and the bit on the far left is the SEG DP line, as with the matrix. So the program for lamps is the same as for a picture: each lamp is one dot in some row.
What we watch out for:
- No resistors are needed, because the chip itself limits the current of each SEG line.
- LEDs of different colours light with different brightness. Blue and white ones need a higher voltage than red, but the chip still lights them at 5 V.
- One chip lights up to 64 lamps, eight DIG lines times eight SEG lines. The pinball machine will have 16 to 24, because each lamp needs two wires under the playfield, and that’s a lot of soldering.
No resistor only on a MAX7219
An LED may go without a resistor only on a chip that limits the current itself, like the MAX7219. An LED connected straight to an Arduino pin must have its own resistor, otherwise too much current flows through it and through the pin, which can damage both.
If something doesn’t work
- Only the matrix connected to the Arduino works ⇒ Check the wires between the modules: DOUT of module 0 must go to DIN of module 1, and both ends on the correct header. Is
MODULE_COUNT2? - Both matrices show the same picture ⇒
MODULE_COUNTis 1. See the third Try it task in Exercise 1. - The pictures are swapped ⇒ Module 0 is the one connected to the Arduino. In Exercises 1, 2 and 4 it is on the left, and in Exercise 3 on the right.
- Nothing lights, or the wrong LEDs light, but the wiring is right ⇒ Is the matrix pushed all the way into its socket? If someone has taken it out, it may have gone back the wrong way round: turn it by half a turn.
- Nothing lights ⇒ Check the wiring to the Arduino, as in the last lesson. If you’re measuring current, is the multimeter put into the red wire correctly?
- The multimeter shows 0 ⇒ The red probe isn’t in the mA socket, or the fuse in the multimeter has blown. Tell the instructor.
- The multimeter shows a current with a minus sign ⇒ The probes are swapped. The number is right, only the direction is reversed.
MD_Parola.h: No such file or directory⇒ The library isn’t installed.- The text is mirrored or upside down, or the letters scroll vertically ⇒ Change the type of module,
FC16_HW, as Exercise 3 says. - On the turned modules the letters are upside down or mirrored ⇒ Are both modules turned to the left, with the chip at the bottom? Does the program have both lines with
setZoneEffect()? If all that is right and the letters are still upside down or mirrored, your modules are wired differently: try deleting one of those two lines. - The text comes in at the middle of the display, or the halves are swapped ⇒ The modules are in the wrong order: in Exercise 3 the module connected to the Arduino must be on the right, and in Exercise 4, with the modules turned, on the left. Move module 1.
- The Arduino restarts, or the computer loses the USB connection ⇒ The matrices are using too much current. Lower the brightness.
Extra challenges
- A chain of four. With the participant next to you, join a chain of four modules, as in the pinball machine, and set
MODULE_COUNTto 4 in the program from Exercise 3. The modules go from right to left, module 0 the rightmost, and each next one is connected to the one before as in Exercise 3. Leave the brightness at 1. - A message and the score. Make the display show PINBALL and the score in turn. Tip: a
boolvariable that remembers what comes next, likebigin Exercise 3 of the last lesson. - Points at the press of a button. Connect a button to D7, as in the lesson on buttons. Let each press add 100 points, and the new score appear on the next pass of the text.
- A jumping heart. With the functions from Exercise 1, make the heart jump from one matrix to the other every second, without
delay().
What did we learn?
- Modules with the MAX7219 chip are joined in a chain: DOUT of one module goes to DIN of the next, and CLK, CS, VCC and GND go to every module.
- Each chip has a 16-bit shift register. When it’s full, the bits come out on DOUT and go into the next chip, so a message for a chain of two modules has 32 bits.
- The message sent first travels furthest. When CS goes back to
HIGH, each chip carries out the message that is in it. - A no-op message has the address 0. We send it to the modules we don’t want to change.
- A loop can count backwards with
m--. A counter that must go below zero is anint, not abyte. - A matrix uses about 8 mA plus 8 · 40 mA times the time a row lights, which the brightness sets. Every LED at full brightness uses about 0.3 A per matrix.
- Current is measured in series: we put the multimeter into the circuit, with the red probe in the mA socket.
- The MD_Parola library writes text across the whole chain:
displayText()says what and how, and we calldisplayAnimate()on every pass throughloop(). - The
longtype stores big whole numbers, andsprintf()writes a number into a text. - Modules turned with the chip at the bottom sit side by side, so the text scrolls without a gap. We tell the library
GENERIC_HWand turn the picture half a turn withPA_FLIP_UDandPA_FLIP_LR. - The MAX7219 also lights ordinary LEDs, without resistors, up to 64 per chip. That’s how the lamps in the pinball machine will work.
Quick quiz
1. Which wires go to every module in a chain, and which one only to the first?
2. Why does the send() function send the message for the furthest module first?
3. What is a no-op message, and what is it for?
4. Why is the loop counter in send() an int and not a byte?
m becomes less than 0. A byte can’t be less than 0: after 0 it becomes 255, so the loop would go on forever.5. Roughly how much does a matrix with every LED lit use at brightness 0, and how much at brightness 7?
6. How do we connect a multimeter when we measure current?
7. What does displayAnimate() do, and how often do we call it?
true when the text has gone all the way. We call it on every pass through loop(), without delay(), otherwise the text doesn’t scroll smoothly.