FluxBench.AIShared project · read-only

Raw SPI LED Matrix

ESP32 DevKit (WROOM-32)·Arduino C++·Updated Jul 27, 2026·by FluxBench TeamIncludes Lab + Schematic

Drives a MAX7219 8x8 LED matrix with nothing but raw SPI.transfer() calls - no LedControl or MD_MAX72xx library. The sketch pulls the chip-select line low, clocks out a 16-bit register/data frame and releases CS, exactly like a datasheet example, with the MAX7219 register map explained in the comments. A heart and a smiley face alternate on the matrix every second. Great for learning what a driver library actually does under the hood.

sketch.ino
// MAX7219 8x8 LED matrix driven with RAW SPI - no LedControl library.
// Wiring (ESP32 VSPI): DIN=GPIO23 (MOSI), CLK=GPIO18 (SCK), CS=GPIO5.
#include <SPI.h>

const int CS_PIN = 5;

void max7219Write(byte reg, byte value) {
  digitalWrite(CS_PIN, LOW);
  SPI.transfer(reg);
  SPI.transfer(value);
  digitalWrite(CS_PIN, HIGH);
}

const byte HEART[8]  = { 0x00, 0x66, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C, 0x18 };
const byte SMILEY[8] = { 0x3C, 0x42, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C };

void setup() {
  Serial.begin(115200);
  pinMode(CS_PIN, OUTPUT);
  digitalWrite(CS_PIN, HIGH);
  SPI.begin();
  max7219Write(0x0F, 0x00);  // display-test off
  max7219Write(0x0B, 0x07);  // scan all 8 rows
  max7219Write(0x09, 0x00);  // no BCD decode
  max7219Write(0x0A, 0x08);  // medium brightness
  max7219Write(0x0C, 0x01);  // wake from shutdown
  Serial.println("MAX7219 raw SPI ready");
}

void loop() {
  const byte* img = (millis() / 1000) % 2 == 0 ? HEART : SMILEY;
  for (byte r = 0; r < 8; r++) {
    max7219Write(r + 1, img[r]);
  }
  delay(100);
}

Built with FluxBench.AI — the AI workbench for embedded projects.