Five wires and a word
Five wires, one library, and eleven lines that put HELLO on the screen. The same sketch compiles for an ESP32-S3 and an Arduino Uno, because the pin numbers happen to be the same on both.
The wiring
Five wires, into the header marked IN. The pin numbers are the same on an
ESP32-S3 and an Arduino Uno — 10, 11 and 12 — so the same sketch compiles for
either. Only the label differs: GPIO 11 on the S3 is D11 on the Uno.
VCC goes to 5 V, on both boards. That is not negotiable in the way people hope it is: the MAX7219's operating supply range in the datasheet starts at 4.0 V, so 3.3 V is outside it, and a display run that way is dim at best. The signal wires are a separate question and the next article is about it.
These are three ordinary digital pins, not the board's hardware SPI pins. The library clocks the bits out itself when you name all three, which is why the same three numbers work on two boards whose SPI peripherals are nothing alike.
The library
Two libraries, and the Arduino IDE installs them together. MD_Parola by majicDesigns is the one you call; it depends on MD_MAX72XX, which is the part that talks to the chips. Tools → Manage Libraries, search MD_Parola, install, and accept when it offers to bring MD_MAX72XX with it.
MD_Parola is worth the dependency because it already knows about scrolling,
alignment and proportional fonts across a cascade — all the things a 32-pixel
display is for. Writing to the chips directly is possible and covered in
sixteen bits at a time, but not
where to start.
On MicroPython the equivalent is max7219.py by mcauser: one file, copied to
the board, giving you max7219.Matrix8x8(spi, cs, 4). It is a smaller library
with a fixed-width font, which has a consequence that catches everybody —
a clock that fits is about exactly
that.
The two numbers that matter
Everything else in the sketch is boilerplate. These two are not:
MAX_DEVICES 4— four 8×8 squares on this board. Wrong, and part of the display stays dark.HARDWARE_TYPE MD_MAX72XX::FC16_HW— how the packages are mounted on the drivers. Wrong, and the text arrives rotated or mirrored.
Both fail in ways that look like hardware faults and are not. If the first upload gives you something strange rather than nothing, start with these.
The code
The shortest thing that proves the whole chain is working. It writes one word and stops — there is nothing in loop() — so if the display holds it steady, power, all three signal wires and all four chips are good.
// Wiring for this sketch. Use the header marked IN, on the back of the board.
//
// ESP32-S3 5V -> VCC Uno 5V -> VCC
// ESP32-S3 GND -> GND Uno GND -> GND
// ESP32-S3 GPIO 10 -> CS Uno D10 -> CS
// ESP32-S3 GPIO 11 -> DIN Uno D11 -> DIN
// ESP32-S3 GPIO 12 -> CLK Uno D12 -> CLK
// (the NC pad between DIN and CLK gets nothing)
//
// Arduino IDE: Tools > Manage Libraries, install "MD_Parola" by majicDesigns
// and let it install MD_MAX72XX with it. Then:
// Tools > Board: "Arduino Uno", or an ESP32-S3 board from the esp32 core
// Tools > Port: whichever port appears when you plug the board in
// Nothing else in Tools needs changing for either board.
#include <MD_Parola.h>
#include <MD_MAX72XX.h>
#include <SPI.h>
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4 // four 8x8 squares on one 32x8 board
#define DATA_PIN 11 // DIN
#define CLK_PIN 12 // CLK
#define CS_PIN 10 // CS
MD_Parola display = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
void setup() {
display.begin();
display.setIntensity(5); // 0 is dimmest, 15 is brightest
display.displayClear();
display.setTextAlignment(PA_CENTER);
display.print("HELLO");
}
void loop() {
}If the word appears but is rotated, mirrored or scrambled, the wiring is right and HARDWARE_TYPE is wrong; see When the text comes out sideways. If only part of the board lights, MAX_DEVICES is wrong. If nothing lights at all, check VCC is on 5 V and not 3V3.
When it does not work
VCC is probably on a 3.3 V pin. The MAX7219's supply range starts at 4.0 V, so at 3.3 V the chip may not run at all and will certainly not look right. Move VCC to the 5V pin; the signal wires stay where they are.
A 3.3 V board is below the chip's 3.5 V logic-high minimum. It works on most boards most of the time and this is what it looks like when it does not. Shorten the three signal wires first, and if that does not settle it, put a 3.3 V to 5 V level shifter in DIN, CLK and CS.
The library is not installed, or only half of it is. MD_Parola depends on MD_MAX72XX and the Library Manager offers to install both — click Install All. Searching for MD_MAX72XX and installing it separately works too.
That is what this sketch does. There is nothing in loop(), so the word is written once and held by the chips' own registers. A MAX7219 keeps its display without being refreshed, which is the whole point of it.
The one number where the datasheet and the shop listing disagree, and what it means for an ESP32.
Three and a half volts →Edit this page — content/books/matrix-32x8/five-wires-and-a-word.mdx
Questions about this product
See what other owners have asked, and read their solutions.
32x8 LED Matrix MAX7219, 3-Pack
Loading discussions…
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.