8×8 LED Matrix MAX7219 with Arduino Circuit & Code
- Dapatkan link
- X
- Aplikasi Lainnya
8×8 LED Matrix MAX7219 with Arduino Circuit & Code
Overview
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 as an LED matrix.
We will generate different rolling LED patterns as well as shape and display it on LED Matrix using different Arduino Codes.
Bill of Materials
S.N. | Components Name | Quantity | Purchase Links |
---|---|---|---|
1 | Arduino UNO Board | 1 | Amazon | AliExpress |
2 | 8X8 LED Matrix with MAX7219 | 1 | Amazon | AliExpress |
3 | 5V Power Supply | 1 | Amazon | AliExpress |
4 | Connecting Wires | 10 | Amazon | AliExpress |
5 | Breadboard | 1 | Amazon | AliExpress |
8×8 LED matrix display
An 8 x 8 LED matrix display is used in this project to display the information. LED matrices are available in different styles like single color, dual color, multi-color or RGB LED matrix. They are also available in different dimensions like 5 x 7, 8 x 8, 16 x 16, 32 x 32 etc.
Pin Configuration
The 8×8 LED matrix have 8 positive terminal & 8 negative terminals. The 8 negatuve terminals are 8 columns & 8 positive terminal are 8 rows.
MAX7219 LED Driver IC
The LED matrix can be driven in two ways. They are parallel (where each row or column are sent with parallel data) and serial (where the data is sent serially and an IC is used to convert this serial data into parallel data).
MAX 7219 is a common cathode display driver with serial input and parallel output. It is used to interface microprocessors and microcontrollers with 64 individual LEDs. The 8 x 8 LED matrix is connected to the MAX 7219. The data input is received from the Arduino board to the MAX7219.
Circuit & Connection: 8×8 LED Matrix MAX7219 with Arduino
The circuit diagram for interfacing 8×8 LED Matrix MAX7219 with Arduino is shown below.
1 2 3 4 5 | 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 interfaced with Arduino for displaying alphabets, characters & logos. First, we need to download a library specifically designed 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #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]); } } |
- Dapatkan link
- X
- Aplikasi Lainnya
Komentar
Posting Komentar
Tulis Komentar