The MAX7219 is a compact, serial input/output common-cathode display driver that can interface microcontrollers to 7-segment numeric LED displays of up to 8 digits, bar-graph displays, or 64 individual LEDs. It includes on-chip BCD code-B decoders, multiplex scan circuitry, segment and digit drivers, and an 8x8 static RAM to store each digit. The MAX7219 simplifies the process of controlling multiple LEDs in matrix or numeric display form. Common applications include digital clocks, electronic meters, and other electronic devices that require display of numerical information.
Pin Number | Name | Description |
---|---|---|
1 | DIG 0 | Digit 0 drive (active low) |
2 | DIG 1 | Digit 1 drive (active low) |
3 | DIG 2 | Digit 2 drive (active low) |
4 | DIG 3 | Digit 3 drive (active low) |
5 | DIG 4 | Digit 4 drive (active low) |
6 | DIG 5 | Digit 5 drive (active low) |
7 | DIG 6 | Digit 6 drive (active low) |
8 | DIG 7 | Digit 7 drive (active low) |
9 | GND | Ground |
10 | SEG D | Segment D drive |
11 | SEG E | Segment E drive |
12 | SEG F | Segment F drive |
13 | SEG G | Segment G drive |
14 | SEG DP | Decimal point drive |
15 | SEG C | Segment C drive |
16 | SEG B | Segment B drive |
17 | SEG A | Segment A drive |
18 | ISET | Current set for segments |
19 | V+ | Positive supply voltage |
20 | LOAD | Load data into the display driver |
21 | DIN | Serial-data input |
22 | CLK | Serial-clock input |
23 | DOUT | Serial-data output |
24 | CS | Chip select (active low) |
To use the MAX7219 in a circuit:
#include <SPI.h>
// Define the connections to the MAX7219
#define MAX7219_DIN 11
#define MAX7219_CS 10
#define MAX7219_CLK 13
// Define the number of digits in the display
#define NUM_DIGITS 8
// Initialize the MAX7219
void setup() {
SPI.begin();
pinMode(MAX7219_CS, OUTPUT);
digitalWrite(MAX7219_CS, HIGH);
sendCommand(0x0C, 0x01); // Turn on the display
sendCommand(0x0B, NUM_DIGITS - 1); // Set scan limit
sendCommand(0x09, 0xFF); // Enable mode B decode for all digits
sendCommand(0x0A, 0x0F); // Set intensity (range is 0x00 to 0x0F)
clearDisplay();
}
// Send a command to the MAX7219
void sendCommand(byte command, byte data) {
digitalWrite(MAX7219_CS, LOW);
SPI.transfer(command); // Send the command byte
SPI.transfer(data); // Send the data byte
digitalWrite(MAX7219_CS, HIGH);
}
// Clear the display
void clearDisplay() {
for (byte i = 0; i < NUM_DIGITS; i++) {
sendCommand(i + 1, 0x0F);
}
}
void loop() {
// Your code to update the display goes here
}
Q: Can I control individual LEDs with the MAX7219? A: Yes, the MAX7219 can control individual LEDs. You will need to address them as part of the matrix and send the appropriate commands.
Q: How do I adjust the brightness of the display? A: The brightness can be adjusted by sending a command to the intensity register (0x0A) with a value between 0x00 (minimum) and 0x0F (maximum).
Q: Can the MAX7219 be used with microcontrollers other than the Arduino? A: Yes, the MAX7219 can be used with any microcontroller that supports SPI communication. Adjust the pin definitions and SPI setup accordingly.