May 01, 2021

Dot Matrix Display Interface with Arduino using MAX7219 Driver

In our previous blog, we discussed interfacing of Dot Matrix Display with Arduino and found out that the process consumes lots of Arduino pins. To solve this issue we will use a driver IC. With help of this driver IC, we will control an 8x8 Dot Matrix Display using only 3 I/O pins. 

The module has five pins. Their descriptions are given below.
VCC  - 5V
GND  - Ground
DIN    - Data In
CS      - Chip Select
CLK   - Clock

Materials Required:
  • Dot Matrix Display Module
  • Jumper Wires
  • Arduino
Circuit Diagram:
  • VCC pin to Arduino 5V pin
  • GND pin to Arduino GND pin 
  • DIN pin to Arduino Pin 11
  • CS pin to Arduino Pin 7
  • CLK pin to Arduino Pin 13

Connect the display module with Arduino as shown above. After the connection is complete then upload the program. You should find the result as shown in the below video.

Source Code:

#include <SPI.h>
#define CHIP_SELECT 7
void sendData(uint8_t address, uint8_t dat) {
digitalWrite(CHIP_SELECT, LOW);
SPI.transfer(address);
SPI.transfer(dat);
digitalWrite(CHIP_SELECT, HIGH);
}
void setup() {
pinMode(CHIP_SELECT, OUTPUT);
SPI.setBitOrder(MSBFIRST);
SPI.begin();
/*--------------------INIT--------------------*/
sendData(0x0F, 0x01); //Run test, All LED segments should light up
delay(1000);
sendData(0x0F, 0x00); //End Test
sendData(0x09, 0x00); //Decode Mode
sendData(0x0A, 0x00); //Lowest Intensity
sendData(0x0B, 0x0F); //Scan all digits
sendData(0x0C, 0x01); //Turn on chip
/*--------------------PH--------------------*/
sendData(0x01, 0xff);
sendData(0x02, 0x09);
sendData(0x03, 0x09);
sendData(0x04, 0x06);
sendData(0x05, 0xff);
sendData(0x06, 0x18);
sendData(0x07, 0x18);
sendData(0x08, 0xff);
delay(1500);
}
void loop() {
/*--------------------:)--------------------*/
sendData(0x01, 0b00);
sendData(0x02, 0x06);
sendData(0x03, 0x26);
sendData(0x04, 0x40);
sendData(0x05, 0x40);
sendData(0x06, 0x26);
sendData(0x07, 0x06);
sendData(0x08, 0x00);
delay(1000);
/*--------------------:|--------------------*/
sendData(0x01, 0b00);
sendData(0x02, 0x06);
sendData(0x03, 0x46);
sendData(0x04, 0x40);
sendData(0x05, 0x40);
sendData(0x06, 0x46);
sendData(0x07, 0x06);
sendData(0x08, 0x00);
/*--------------------:'(--------------------*/
delay(1000);
sendData(0x01, 0b00);
sendData(0x02, 0x06);
sendData(0x03, 0x86);
sendData(0x04, 0x40);
sendData(0x05, 0x40);
sendData(0x06, 0x86);
sendData(0x07, 0x16);
sendData(0x08, 0x00);
delay(1000);
}
In this second version, the array is introduced. Using array we can store multiple values in a variable. This allows us to make the code short. If you go through the resulting video you will find that this second version is more complex sill the code size is less. 

Source Code 2:
#include <SPI.h>
#define CHIP_SELECT 7
byte PH[8] = {0xff, 0x09, 0x09, 0x06, 0xff, 0x18, 0x18, 0xff}; //PH
byte A [8] = {0x00, 0x06, 0x26, 0x40, 0x40, 0x26, 0x06, 0x00}; // :)
byte B [8] = {0x00, 0x06, 0x46, 0x40, 0x40, 0x46, 0x06, 0x00}; // :|
byte C [8] = {0x00, 0x06, 0x86, 0x40, 0x40, 0x86, 0x0E, 0x00}; // -1
byte D [8] = {0x00, 0x06, 0x86, 0x40, 0x40, 0x86, 0x16, 0x00}; // 0
byte E [8] = {0x00, 0x06, 0x86, 0x40, 0x40, 0x86, 0x26, 0x00}; // +1
byte F [8] = {0x00, 0x06, 0x86, 0x40, 0x40, 0x86, 0x46, 0x00}; // +2
void sendData(uint8_t address, uint8_t dat) {
digitalWrite(CHIP_SELECT, LOW);
SPI.transfer(address);
SPI.transfer(dat);
digitalWrite(CHIP_SELECT, HIGH);
}
void setup() {
pinMode(CHIP_SELECT, OUTPUT);
SPI.setBitOrder(MSBFIRST);
SPI.begin();
/*--------------------INIT--------------------*/
sendData(0x0F, 0x01); //Run test, All LED segments should light up
delay(1000);
sendData(0x0F, 0x00); //End Test
sendData(0x09, 0x00); //Decode Mode
sendData(0x0A, 0x00); //Lowest Intensity
sendData(0x0B, 0x0F); //Scan all digits
sendData(0x0C, 0x01); //Turn on chip
for (int i = 1; i < 9; i++) sendData(i, PH[i - 1]);
delay(1500);
}
void loop() {
for (int i = 1; i < 9; i++) { sendData(i, A[i - 1]); }
delay(1000);
for (int i = 1; i < 9; i++) { sendData(i, B[i - 1]); }
delay(1000);
for (int j = 0; j < 2; j++)
{
for (int i = 1; i < 9; i++) { sendData(i, C[i - 1]); }
delay(1000);
for (int i = 1; i < 9; i++) { sendData(i, D[i - 1]); }
delay(1000);
for (int i = 1; i < 9; i++) { sendData(i, E[i - 1]); }
delay(1000);
for (int i = 1; i < 9; i++) { sendData(i, F[i - 1]); }
delay(1000);
}
}
Video: 

Video 2:

No comments:

Post a Comment