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
- 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.
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.
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.
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.
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
- 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
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.
- 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_HWtryGENERIC_HW, thenPAROLA_HWandICSTATION_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.
// 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.
- 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.
- 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.
- 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.
Useful products
Other guides
- Resistor colour code and tolerances
- N-channel and P-channel MOSFETs
- Bipolar transistor (BJT) or MOSFET?
- Relays: how to drive them and how much current they draw
- THT and SMD/SMT components
- XIAO board pinouts
- LEDs: forward voltage and series resistor
- The multimeter: measuring voltage and current
- Wemos D1 mini: first steps
- MOSFET module with Arduino and ESP32
- Relay module with Arduino and ESP32
- 3D printing filaments: PLA, PETG and fibre-filled versions
- Analog and digital: the differences
- ADS1115: 16-bit converter with Arduino and ESP32
- From bits to real values: converting sensor readings
- DS3231 RTC clock with Arduino and ESP32
- Linear or switching regulator: which one to choose
- Step-down, step-up and buck-boost: choosing the right module
- Voltage divider: reading voltages higher than 5 V or 3.3 V
- Pull-up, pull-down and bounce: wiring a button properly
- 3.3 V and 5 V logic levels: getting an ESP32 and an Arduino to talk
- The I²C bus: addresses, pull-ups and the scanner
- Lithium batteries: voltages, charging and protection
- ESP32 power consumption and deep sleep: how long the battery lasts
- Temperature sensors compared
- ESP32: which pins to use and which to avoid
- Getting started with the ESP32 in Arduino IDE 2 and PlatformIO
- SSD1306 OLED display and 16×2 I²C LCD with Arduino and ESP32
- PIR motion sensor and HC-SR04 ultrasonic sensor
- Date and time from the Internet with the ESP32: NTP, Italian time zone and daylight saving time
- MicroSD data logger: saving measurements to CSV
- Solar-powered ESP32: panel, charger and the numbers for Italy
- Web server on the ESP32: control a relay from your phone
- Your first LED: wire it up and make it blink
- The button: let Arduino decide
- The potentiometer: turn a knob and read its value
- Soft light: adjusting the brightness of an LED
- The buzzer: playing notes and melodies
- The traffic light: three LEDs in sequence
- The thermometer: reading the temperature with the TMP36
- The servo motor: moving an arm with Arduino
- The night light: the photoresistor and your first decision
- The relay: switching on a light bulb with Arduino
- The LCD display: making Arduino write
- The electronic dice: your first complete project
- The RGB LED: every color from three lights
- The joystick: two-axis control with a shield
- The LED ring: twelve colors from a single pin
- The DC motor: driving it with a MOSFET
- Soil moisture: the plant that asks for water
- The stepper motor: turn exactly as far as you want
- The parking sensor: faster and faster beeps
- The 7-segment display: big, bright numbers
- Automatic watering: the plant that waters itself
- The keypad: a lock with a secret code
- Networked weather station: values and chart on your phone
- A Telegram bot on the ESP32: your home from your phone
- MQTT with the ESP32: the language of connected devices
- Updating the ESP32 over Wi-Fi (OTA)
- ESP-NOW: two ESP32 boards talking without a router
- WebSocket with the ESP32: the LED that follows the slider
- Readings on a Google sheet, with deep sleep
- WiFiManager: choose the Wi-Fi from your phone
- Bluetooth LE with the ESP32: the phone without a network
- The camera in your browser with the ESP32-S3
- A portable Bluetooth speaker you build yourself
- Bluetooth desktop speakers, 2 × 20 W
- Stereo MP3 player with two buttons
- The shelf that plays music: a Visaton exciter
- How to solder well
- How much does it draw? Current and power with the INA219
- Load-cell scale with the HX711
- CO2 traffic light: when to open the windows
- RFID card door opener
- GPS: track logger on microSD
- LoRa: how far does it go? A range test with two boards
- Battery weather sign with an e-paper display
- Web radio with an ESP32 and an I2S amplifier
- Getting started with the Raspberry Pi Pico 2 in MicroPython
- Your first amplifier: the LM386 and a speaker
- Talking Arduino: the DFR0760 speech synthesis module
- The spectrum of your music on an LED matrix
- A real voltage: the 12-bit MCP4725 DAC
- The heartbeat on Arduino: an ECG with the AD8232