Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Basic code for using Maxim MAX7219/MAX7221 with Arduino.
Basic code for using Maxim MAX7219/MAX7221 with Arduino.
Wire the Arduino and the MAX7219/MAX7221 together as follows:
| Arduino | MAX7219/MAX7221 |
| --------- | --------------- |
| MOSI (11) | DIN (1) |
| SCK (13) | CLK (13) |
| I/O (7)* | LOAD/CS (12) |
* - This should match the LOAD_PIN constant defined below.
For the rest of the wiring follow the wiring diagram found in the datasheet.
Author: Nicholas Dobie <>
Date: 30 December 2013
License: WTFPL (
#include <SPI.h>
// What pin on the Arduino connects to the LOAD/CS pin on the MAX7219/MAX7221
#define LOAD_PIN 7
* Transfers data to a MAX7219/MAX7221 register.
* @param address The register to load data into
* @param value Value to store in the register
void maxTransfer(uint8_t address, uint8_t value) {
// Ensure LOAD/CS is LOW
digitalWrite(LOAD_PIN, LOW);
// Send the register address
// Send the value
// Tell chip to load in data
digitalWrite(LOAD_PIN, HIGH);
void setup() {
// Set load pin to output
// Reverse the SPI transfer to send the MSB first
// Start SPI
// Run test
// All LED segments should light up
maxTransfer(0x0F, 0x01);
maxTransfer(0x0F, 0x00);
// Enable mode B
maxTransfer(0x09, 0xFF);
// Use lowest intensity
maxTransfer(0x0A, 0x00);
// Only scan one digit
maxTransfer(0x0B, 0x00);
// Turn on chip
maxTransfer(0x0C, 0x01);
void loop() {
// Loop through each code
for (uint8_t i = 0; i < 0x10; ++i)
maxTransfer(0x01, i);

This was the best example I could find. With it I got a test going in 10 minutes and learned
the essence of the part and registers. Thanks for posting it!

will this code work on attiny85 USB arduino ?

This may sound dumb but I just started to learn how to code stuff like this. I have 4 max7219 with each having a 8x8 LED display on a PCB Board. This what am using Wangdd22 MAX7219 Dot Matrix Module For Arduino Microcontroller 4 In 1 Display with 5pin Line. How do code so it runs on all four displays as one disdplay?

i didnt know pin connections

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment