In this project, we will learn how to use the 8×8 LED Matrix MAX7219 with Arduino. For that, we are going to interface an 8×8 LED matrix module with MAX7129 LED driver with Arduino Uno Board. An 8×8 LED matrix has 64 LEDs (Light Emitting Diodes) which are arranged in the form of a matrix as 8 rows and 8 columns. Hence it is named an LED matrix.
The dot-matrix we’ll be using in this guide is an 8×8 matrix, which means it has eight columns and eight rows, totaling 64 LEDs. We will generate different rolling LED patterns and shapes and display them on LED Matrix using different Arduino Codes.
Hardware Required
- Arduino UNO R3/ Nano or Any other Arduino Board
- 8X8 LED Matrix with MAX7219
- 5V Power Adapter
- Connecting Wires
- Breadboard
8×8 LED matrix display
The information is displayed on an 8 by 8 LED matrix display in this project. LED matrices to come in a variety of formats, including single colour, dual color, multi-color, and RGB LED matrices. They come in a variety of sizes, including 5 x 7, 8 x 8, 16 x 16, 32 x 32, and so on.
Pin Configuration
There are 8 positive and 8 negative connections on the 8×8 LED matrix. The eight negative terminals are arranged in eight columns, while the eight positive terminals are arranged in eight rows.
MAX7219 LED Driver IC
There are two ways to power the LED matrix. They are parallel (each row or column is sent with parallel data) and serial (each row or column is sent with serial data) (where the data is sent serially and an IC is used to convert this serial data into parallel data).
MAX 7219 is a serial input and parallel output common-cathode display, driver. It’s used to connect 64 individual LEDs to microprocessors and microcontrollers. The MAX 7219 is coupled to an 8 by 8 LED matrix. The MAX7219 receives the data supplied from the Arduino board.
Circuit & Connection: 8×8 LED Matrix MAX7219 with Arduino
The circuit diagram for interfacing 8×8 LED Matrix MAX7219 with Arduino is shown below.
D10 ——————LOAD or CHIP SELECT of LED module D11 ——————CLOCK of LED module D12 ——————DATA IN of LED module+5V ——————VCC of LED module GND ——————GND of LED module |
8×8 LED Matrix Library
This 8×8 LED Matrix Library module will be used to show alphabets, characters, and logos using Arduino. To begin, we must first obtain a library created specifically for LED MATRIX.
After downloading the Zip file, extract the content. Put the folder in library folder inside Libraries –>>>— Arduino –>>>>>–Document
Source Code for Displaying Letters
#include “LedControlMS.h” //pin 12 is connected to the DataIn // pin 11 is connected to the CLK //pin 10 is connected to LOAD #define NBR_MTX 1 //number of matrices attached is one LedControl lc=LedControl(12,11, 10, NBR_MTX);// void setup() { for (int i=0; i< NBR_MTX; i++) { lc.shutdown(i,false); /* Set the brightness to a medium values */ lc.setIntensity(i,8); /* and clear the display */ lc.clearDisplay(i); delay(500); } } void loop() { lc.writeString(0,”HOW2ELECTRONICS”);//sending characters to display lc.clearAll();//clearing the display delay(1000); } |
Source Code for Displaying Dotted Heart
unsigned char i; unsigned char j; int Max7219_pinCLK = 11; int Max7219_pinCS = 10; int Max7219_pinDIN = 12; unsigned char disp1[19][8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Heart Pattern 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 0x40, 0x80, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 0x60, 0x80, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 0x60, 0x90, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 0x60, 0x90, 0x88, 0x40, 0x40, 0x00, 0x00, 0x00, 0x60, 0x90, 0x88, 0x44, 0x40, 0x00, 0x00, 0x00, 0x60, 0x90, 0x88, 0x44, 0x44, 0x00, 0x00, 0x00, 0x60, 0x90, 0x88, 0x44, 0x44, 0x08, 0x00, 0x00, 0x60, 0x90, 0x88, 0x44, 0x44, 0x08, 0x10, 0x00, 0x60, 0x90, 0x88, 0x44, 0x44, 0x08, 0x10, 0x20, 0x60, 0x90, 0x88, 0x44, 0x44, 0x08, 0x10, 0x60, 0x60, 0x90, 0x88, 0x44, 0x44, 0x08, 0x90, 0x60, 0x60, 0x90, 0x88, 0x44, 0x44, 0x88, 0x90, 0x60, // Heart Pattern }; void Write_Max7219_byte(unsigned char DATA) { unsigned char i; digitalWrite(Max7219_pinCS,LOW); for(i=8;i>=1;i–) { digitalWrite(Max7219_pinCLK,LOW); digitalWrite(Max7219_pinDIN,DATA&0x80); DATA = DATA<<1; digitalWrite(Max7219_pinCLK,HIGH); } } void Write_Max7219(unsigned char address,unsigned char dat) { digitalWrite(Max7219_pinCS,LOW); Write_Max7219_byte(address); Write_Max7219_byte(dat); digitalWrite(Max7219_pinCS,HIGH); } void Init_MAX7219(void) { Write_Max7219(0x09, 0x00); Write_Max7219(0x0a, 0x03); Write_Max7219(0x0b, 0x07); Write_Max7219(0x0c, 0x01); Write_Max7219(0x0f, 0x00); } void setup() { pinMode(Max7219_pinCLK,OUTPUT); pinMode(Max7219_pinCS,OUTPUT); pinMode(Max7219_pinDIN,OUTPUT); delay(50); Init_MAX7219(); } void loop() { for(j=0;j<19;j++) { for(i=1;i<9;i++) Write_Max7219(i,disp1[j][i-1]); delay(500); } } |
Source Code for Displaying Beating Heart
int ANIMDELAY = 100; // animation delay, deafault value is 100 int INTENSITYMIN = 0; // minimum brightness, valid range [0,15] int INTENSITYMAX = 8; // maximum brightness, valid range [0,15] int DIN_PIN = 12; // data in pin int CS_PIN = 10; // load (CS) pin int CLK_PIN = 11; // clock pin // MAX7219 registers byte MAXREG_DECODEMODE = 0x09; byte MAXREG_INTENSITY = 0x0a; byte MAXREG_SCANLIMIT = 0x0b; byte MAXREG_SHUTDOWN = 0x0c; byte MAXREG_DISPTEST = 0x0f; const unsigned char heart[] = { B01100110, B11111111, B11111111, B11111111, B01111110, B00111100, B00011000, B00000000 }; void setup () { pinMode(DIN_PIN, OUTPUT); pinMode(CLK_PIN, OUTPUT); pinMode(CS_PIN, OUTPUT); // initialization of the MAX7219 setRegistry(MAXREG_SCANLIMIT, 0x07); setRegistry(MAXREG_DECODEMODE, 0x00); // using an led matrix (not digits) setRegistry(MAXREG_SHUTDOWN, 0x01); // not in shutdown mode setRegistry(MAXREG_DISPTEST, 0x00); // no display test setRegistry(MAXREG_INTENSITY, 0x0f & INTENSITYMIN); // draw hearth setRegistry(1, heart[0]); setRegistry(2, heart[1]); setRegistry(3, heart[2]); setRegistry(4, heart[3]); setRegistry(5, heart[4]); setRegistry(6, heart[5]); setRegistry(7, heart[6]); setRegistry(8, heart[7]); } void loop () { // second beat setRegistry(MAXREG_INTENSITY, 0x0f & INTENSITYMAX); delay(ANIMDELAY); // switch off setRegistry(MAXREG_INTENSITY, 0x0f & INTENSITYMIN); delay(ANIMDELAY); // second beat setRegistry(MAXREG_INTENSITY, 0x0f & INTENSITYMAX); delay(ANIMDELAY); // switch off setRegistry(MAXREG_INTENSITY, 0x0f & INTENSITYMIN); delay(ANIMDELAY*6); } void setRegistry(byte reg, byte value) { digitalWrite(CS_PIN, LOW); putByte(reg); // specify register putByte(value); // send data digitalWrite(CS_PIN, LOW); digitalWrite(CS_PIN, HIGH); } void putByte(byte data) { byte i = 8; byte mask; while (i > 0) { mask = 0x01 << (i – 1); // get bitmask digitalWrite( CLK_PIN, LOW); // tick if (data & mask) // choose bit digitalWrite(DIN_PIN, HIGH); // send 1 else digitalWrite(DIN_PIN, LOW); // send 0 digitalWrite(CLK_PIN, HIGH); // tock –i; // move to lesser bit } } |
Source Code for Displaying Custom Characters
#include <LedControl.h> int DIN = 12; int CS = 10; int CLK = 11; byte L[8]= {0x7f,0x7f,0x7f,0x07,0x07,0x07,0x07,0x07}; byte dot[8]= {0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00}; byte S[8]= {0x7e,0x7e,0x60,0x7e,0x7e,0x06,0x7e,0x7e}; byte H[8]= {0xe7,0xe7,0xe7,0xff,0xff,0xe7,0xe7,0xe7}; byte A[8]= {0xe7,0xe7,0xff,0xff,0xe7,0xe7,0x7e,0x3c}; byte R[8]= {0xc7,0xe7,0x7f,0x7f,0xe7,0xe7,0xff,0x7e}; byte T[8]= {0x18,0x18,0x18,0x18,0x18,0x18,0xff,0xff}; LedControl lc=LedControl(DIN,CLK,CS,0); void setup(){ lc.shutdown(0,false); //The MAX72XX is in power-saving mode on startup lc.setIntensity(0,15); // Set the brightness to maximum value lc.clearDisplay(0); // and clear the display } void loop(){ byte smile[8]= {0x3C,0x42,0xA5,0x81,0xA5,0x99,0x42,0x3C}; byte neutral[8]= {0x3C,0x42,0xA5,0x81,0xBD,0x81,0x42,0x3C}; byte frown[8]= {0x3C,0x42,0xA5,0x81,0x99,0xA5,0x42,0x3C}; printByte(smile); delay(1000); printByte(neutral); delay(1000); printByte(frown); delay(1000); printEduc8s(); lc.clearDisplay(0); delay(1000); } void printEduc8s() { printByte(L); delay(1000); printByte(dot); delay(1000); printByte(S); delay(1000); printByte(H); delay(1000); printByte(A); delay(1000); printByte(R); delay(1000); printByte(A); delay(1000); printByte(T); delay(1000); printByte(H); delay(1000); } void printByte(byte character []) { int i = 0; for(i=0;i<9;i++) { lc.setRow(0,i,character[i]); } } |
Conclusion
I hope all of you understand how to use the 8×8 LED Matrix MAX7219 with Arduino. We MATHA ELECTRONICS will be back soon with more informative blogs.