MD_MAX72XX: chained 8x8 matrices as one display
MD_MAX72XX, from MajicDesigns, treats a chain of MAX7219 8x8 modules as one long display of columns, which is what the popular four-in-one boards are. You draw points, rows and characters by column number across the whole chain, and the library sorts out which chip and which LED that is.
Built in on Mokxi: #include <MD_MAX72xx.h> and it builds, with nothing to install. Free, and no account needed.
What MD_MAX72XX does
The one setting that matters is the hardware type. Modules are wired in a few different ways, and the library needs to know which: MD_MAX72XX::FC16_HW for the common blue four-in-one boards, PAROLA_HW for MajicDesigns’ own, GENERIC_HW and ICSTATION_HW for the rest. With the wrong one, text appears mirrored, upside down or scrambled.
Columns are numbered from the right-hand end of the chain, and the module that DIN goes into is device 0. For scrolling text with effects, MD_Parola sits on top of this library; MD_MAX72XX is the level below, for your own graphics.
| Library Manager name | MD_MAX72XX |
|---|---|
| Author | MajicDesigns |
| Include | #include <MD_MAX72xx.h> |
| Boards | every board Mokxi compiles for but ATtiny85 |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | LED matrix, 8x8 |
Install it
It builds on every board Mokxi compiles for but ATtiny85.
In Mokxi it is built in: #include <MD_MAX72xx.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "MD_MAX72XX" by MajicDesigns from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add MD_MAX72XX to lib_deps in PlatformIO. Mokxi follows the calls of release 3.5.1, so a sketch written here builds there too.
What to know in the simulator: Every hardware type maps to the part the same way, so text reads left to right whichever is named. The default font is Mokxi’s 5x8; setFont() loads upstream’s font tables.
ESP32-C3 · Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · ESP32-C6 · Raspberry Pi Pico · Raspberry Pi Pico W · Seeed XIAO SAMD21 · STM32 · STM32 Nucleo-F411RE · STM32 Blue Pill · micro:bit V2 · Arduino Uno R4 · ESP32 DevKit · ESP32-S3-DevKitC-1 · ESP8266 NodeMCU · Arduino Pro Mini 3.3 V · Seeed XIAO ESP32-C3 · ESP32-C3 SuperMini · Seeed XIAO ESP32-C6 · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · Seeed XIAO ESP32-S3 · Arduino Nano ESP32 · Arduino Nano RP2040 Connect · Seeed XIAO RP2040 · Waveshare RP2040-Zero · Arduino Uno R4 WiFi
The calls you will use
In the order a sketch meets them.
MD_MAX72XX mx = MD_MAX72XX(MD_MAX72XX::FC16_HW, CS_PIN, 4)
Four FC-16 modules on hardware SPI, with CS on CS_PIN. DIN and CLK go to the board’s MOSI and SCK pins (11 and 13 on an Uno).
mx.begin()
Starts SPI and clears the chain. Call it once in setup().
mx.control(MD_MAX72XX::INTENSITY, 4)
Sets brightness (0 to 15) for every module. control() also switches the display off and on and turns automatic updates on or off.
mx.setPoint(row, col, true)
Lights one LED, row 0 to 7, column 0 to 8 times the number of modules minus 1.
mx.setChar(col, c)
Draws a character from the library’s font with its right edge at col and returns its width, so a word is built by stepping col down by width plus one.
uint8_t col = mx.getColumnCount() - 1;
for (const char *p = "HI"; *p; p++) {
col -= mx.setChar(col, *p) + 1;
}mx.transform(MD_MAX72XX::TSL)
Shifts the whole display one column left (TSR is right, TSU and TSD up and down), the building block of a scrolling message.
mx.clear()
Turns every LED of the chain off.
Example: Letters on four LED matrix modules
On the Arduino Uno R3. It runs in the browser exactly as printed.
#include <MD_MAX72xx.h>
#include <SPI.h>
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CS_PIN 10
// DIN and CLK on the board's SPI pins (11 and 13 on an Uno).
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
void setup() {
Serial.begin(9600);
mx.begin();
mx.control(MD_MAX72XX::INTENSITY, MAX_INTENSITY / 2);
mx.clear();
const char *text = "Hi!";
uint16_t col = mx.getColumnCount() - 1;
for (const char *p = text; *p; p++) {
col -= mx.setChar(col, *p) + 1;
}
Serial.println("drawn");
}
void loop() {
delay(300);
mx.transform(MD_MAX72XX::TSL); // scroll it left, a column at a time
}Wiring
- Arduino Uno R3 11 to LED matrix, 8x8 DIN
- Arduino Uno R3 13 to LED matrix, 8x8 CLK
- Arduino Uno R3 10 to LED matrix, 8x8 CS
- Arduino Uno R3 5V to LED matrix, 8x8 VCC
- Arduino Uno R3 GND to LED matrix, 8x8 GND
Common errors and how to fix them
Letters are mirrored or upside down
The hardware type does not match the modules. Try MD_MAX72XX::FC16_HW first for blue four-in-one boards, then GENERIC_HW, PAROLA_HW and ICSTATION_HW until the text reads correctly.
'FC16_HW' is not a member of 'MD_MAX72XX'
The sketch was written for version 3 and an older 2.x copy is installed, which chose the hardware with #define lines inside the library. Update MD_MAX72XX from the Library Manager.
The words appear in the wrong order across the modules
Column 0 is the far right of the chain and device 0 is the module DIN enters. Feed the chain from the right-hand end, or reverse the column numbers you draw with.
Projects that use MD_MAX72XX
Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.
Try MD_MAX72XX without installing anything
Open the example, change the sketch, and keep your version in a free account.