Introduction: Dot Matrix With MAX7219 Interfacing With Arduino

About: My team has developed a new product. PLEASE CHECK IT OUT ON INDIEGOGO AND SHOW YOUR SUPPORT. CAMPAIGN LINK: https://igg.me/p/2165733/x/17027489. I'm a tech and food enthusiast and also a Soccer Player. I love…

A Dot Matrix is a two dimensional patterned LED array, which is used to represent characters, symbols, and images. Almost all the modern display technologies make use of dot matrices including cell phones, television etc. If you're a person who loves playing around with LEDs, trust me, this project is gonna be a lot of fun.

In this Instructable, I will be going through interfacing a Dot Matrix which has a MAX7219 driver to an Arduino Uno. The components required are pretty less but coding is quite a bit here. So put on your coding hats and let's get started.

Step 1: Things Required

For this fun project you will need the following components:

  • Arduino Uno.
  • 8x8 Dot Matrix (With MAX7219 Module).
  • Bread Board.
  • Jumper Wires.

With these very few components, let's get going.

Step 2: A Little About the Dot Matrix

A typical 8x8 Dot Matrix unit has 64 LEDs arranged in a plane. You can get your hands on two types of Dot Matrices. One which comes as a plain single matrix which has 16 pins to control the rows and columns of the array. This one would use a lot of wires and things can get a lot messier.

To simplify these things, it is also available integrated with MAX7219 Driver, which has 24 pins. At the end you have 5 pins to connect to your I/O which makes your job a lot more easier.

There are 16 output lines from the 7219 driving 64 individual LEDs. Persistence of vision is exploited to make the LEDs appear to be on all the time when in fact they are not. You can also control the brightness of the LEDs through the code.

Step 3: The MAX7219 Driver

This small IC is a 16 bit serial shift register. The first 8 bits specify a command and the remaining 8 bits are used to specify the data for the command. In a nutshell, the working of the MAX7219 can be summarized as follows:

We know that our eyes remember a flash for about 20ms. So the Driver flashes the LEDs at a rate greater than 20ms which makes us feel that the light never goes off. In this way, the 16 pins control 64 LEDs.

For more in depth detail of the MAX72XX series drivers, click here for the datasheets.

Step 4: The Circuit

The circuit is quite simple and can be built on a bread board. Just follow the diagram and build the circuit. You can later assemble it on a PCB if you're making a permanent application for the Matrix.

The Pin Configuration is as follows:

  • Vcc to 5V Pin of Arduino.
  • Gnd to Gnd Pin of the Arduino.
  • DIN to Digital Pin 11 of the Arduino.
  • CS to Digital Pin 10 of the Arduino.
  • CLK to Digital Pin 13 of the Arduino.

With all these said, let's get into coding...

Step 5: The Code

Here in this Instructable I'll provide you with two different codes. One will generate random sequences on the Matrix. The other one to display a demonstration of scrolling text on the screen. You must use the following library to make it work.

Click here to download.

This is the code for random sequence:

// max7219_two
// Based on https://gist.github.com/nrdobie/8193350

//This code will work well even without

#include #define SS_PIN 10

// MAX7219 SPI LED Driver #define MAX7219_TEST 0x0f // in real code put into a .h file #define MAX7219_BRIGHTNESS 0x0a // in real code put into a .h file #define MAX7219_SCAN_LIMIT 0x0b // in real code put into a .h file #define MAX7219_DECODE_MODE 0x09 // in real code put into a .h file #define MAX7219_SHUTDOWN 0x0C // in real code put into a .h file

void maxTransferCMD(uint8_t address, uint8_t value) { uint8_t i;

digitalWrite(SS_PIN, LOW); SPI.transfer(address); // Send address. SPI.transfer(value); // Send the value. SPI.transfer(address); // Send address. SPI.transfer(value); // Send the value. digitalWrite(SS_PIN, HIGH); // Finish transfer. }

void maxTransferDATA(uint8_t address, uint8_t value, uint8_t v2) { uint8_t i;

digitalWrite(SS_PIN, LOW);

SPI.transfer(address); // Send address. SPI.transfer(value); // Send the value. SPI.transfer(address); // Send address. SPI.transfer(v2); // Send the value.

digitalWrite(SS_PIN, HIGH); // Finish transfer. }

void setup() {

Serial.begin(9600);

Serial.println("Debug MAX7219");

pinMode(SS_PIN, OUTPUT);

SPI.setBitOrder(MSBFIRST); // Reverse the SPI Data o/p. SPI.begin(); // Start SPI

// Run test - All LED segments lit. maxTransferCMD(MAX7219_TEST, 0x01); delay(1000); maxTransferCMD(MAX7219_TEST, 0x00); // Finish test mode. maxTransferCMD(MAX7219_DECODE_MODE, 0x00); // Disable BCD mode. maxTransferCMD(MAX7219_BRIGHTNESS, 0x00); // Use lowest intensity. maxTransferCMD(MAX7219_SCAN_LIMIT, 0x0f); // Scan all digits. maxTransferCMD(MAX7219_SHUTDOWN, 0x01); // Turn on chip.

}

void loop() { uint8_t row=0; int i=0,ud=1; // Need signed numbers.

for(;;) {

i += ud;

if (i>255) {ud=-1;i=255;}

if (i<0) {ud=1 ;i=0;}

if (row++>8) row=1; maxTransferDATA(row, random(0,255), random(0,255)); maxTransferCMD(MAX7219_BRIGHTNESS,i>>4);

delay(10);

Serial.print(" i "); Serial.print(i); Serial.print(" ud "); Serial.println(ud); } }

This is the code for scrolling text:

// maxmatrix-disp-scroll-text-7219
// based on // https://code.google.com/p/arudino-maxmatrix-library/wiki/Example_Display_Scrolling_Tex #include #include

#define maxDisplays 2 // Number of MAX7219's in use.

byte Buf7219[7]; // "width,height,data[5]" single character buffer. const int data = 11; // DIN or MOSI const int load = 10; // CS const int clock = 13; // SCK MaxMatrix m(data, load, clock, maxDisplays); // Data array is stored in program memory (see memcpy_P for access). // Parameters are width, height, character data... // There is a speed improvement for characters with height 8 bits see lib.

PROGMEM const unsigned char CH[] = { 3, 8, B0000000, B0000000, B0000000, B0000000, B0000000, // space 1, 8, B1011111, B0000000, B0000000, B0000000, B0000000, // ! 3, 8, B0000011, B0000000, B0000011, B0000000, B0000000, // " 5, 8, B0010100, B0111110, B0010100, B0111110, B0010100, // # 4, 8, B0100100, B1101010, B0101011, B0010010, B0000000, // $ 5, 8, B1100011, B0010011, B0001000, B1100100, B1100011, // % 5, 8, B0110110, B1001001, B1010110, B0100000, B1010000, // & 1, 8, B0000011, B0000000, B0000000, B0000000, B0000000, // ' 3, 8, B0011100, B0100010, B1000001, B0000000, B0000000, // ( 3, 8, B1000001, B0100010, B0011100, B0000000, B0000000, // ) 5, 8, B0101000, B0011000, B0001110, B0011000, B0101000, // * 5, 8, B0001000, B0001000, B0111110, B0001000, B0001000, // + 2, 8, B10110000, B1110000, B0000000, B0000000, B0000000, // , 4, 8, B0001000, B0001000, B0001000, B0001000, B0000000, // - 2, 8, B1100000, B1100000, B0000000, B0000000, B0000000, // . 4, 8, B1100000, B0011000, B0000110, B0000001, B0000000, // / 4, 8, B0111110, B1000001, B1000001, B0111110, B0000000, // 0 3, 8, B1000010, B1111111, B1000000, B0000000, B0000000, // 1 4, 8, B1100010, B1010001, B1001001, B1000110, B0000000, // 2 4, 8, B0100010, B1000001, B1001001, B0110110, B0000000, // 3 4, 8, B0011000, B0010100, B0010010, B1111111, B0000000, // 4 4, 8, B0100111, B1000101, B1000101, B0111001, B0000000, // 5 4, 8, B0111110, B1001001, B1001001, B0110000, B0000000, // 6 4, 8, B1100001, B0010001, B0001001, B0000111, B0000000, // 7 4, 8, B0110110, B1001001, B1001001, B0110110, B0000000, // 8 4, 8, B0000110, B1001001, B1001001, B0111110, B0000000, // 9 2, 8, B01010000, B0000000, B0000000, B0000000, B0000000, // : 2, 8, B10000000, B01010000, B0000000, B0000000, B0000000, // ; 3, 8, B0010000, B0101000, B1000100, B0000000, B0000000, // < 3, 8, B0010100, B0010100, B0010100, B0000000, B0000000, // = 3, 8, B1000100, B0101000, B0010000, B0000000, B0000000, // > 4, 8, B0000010, B1011001, B0001001, B0000110, B0000000, // ? 5, 8, B0111110, B1001001, B1010101, B1011101, B0001110, // @ 4, 8, B1111110, B0010001, B0010001, B1111110, B0000000, // A 4, 8, B1111111, B1001001, B1001001, B0110110, B0000000, // B 4, 8, B0111110, B1000001, B1000001, B0100010, B0000000, // C 4, 8, B1111111, B1000001, B1000001, B0111110, B0000000, // D 4, 8, B1111111, B1001001, B1001001, B1000001, B0000000, // E 4, 8, B1111111, B0001001, B0001001, B0000001, B0000000, // F 4, 8, B0111110, B1000001, B1001001, B1111010, B0000000, // G 4, 8, B1111111, B0001000, B0001000, B1111111, B0000000, // H 3, 8, B1000001, B1111111, B1000001, B0000000, B0000000, // I 4, 8, B0110000, B1000000, B1000001, B0111111, B0000000, // J 4, 8, B1111111, B0001000, B0010100, B1100011, B0000000, // K 4, 8, B1111111, B1000000, B1000000, B1000000, B0000000, // L 5, 8, B1111111, B0000010, B0001100, B0000010, B1111111, // M 5, 8, B1111111, B0000100, B0001000, B0010000, B1111111, // N 4, 8, B0111110, B1000001, B1000001, B0111110, B0000000, // O 4, 8, B1111111, B0001001, B0001001, B0000110, B0000000, // P 4, 8, B0111110, B1000001, B1000001, B10111110, B0000000, // Q 4, 8, B1111111, B0001001, B0001001, B1110110, B0000000, // R 4, 8, B1000110, B1001001, B1001001, B0110010, B0000000, // S 5, 8, B0000001, B0000001, B1111111, B0000001, B0000001, // T 4, 8, B0111111, B1000000, B1000000, B0111111, B0000000, // U 5, 8, B0001111, B0110000, B1000000, B0110000, B0001111, // V 5, 8, B0111111, B1000000, B0111000, B1000000, B0111111, // W 5, 8, B1100011, B0010100, B0001000, B0010100, B1100011, // X 5, 8, B0000111, B0001000, B1110000, B0001000, B0000111, // Y 4, 8, B1100001, B1010001, B1001001, B1000111, B0000000, // Z 2, 8, B1111111, B1000001, B0000000, B0000000, B0000000, // [ 4, 8, B0000001, B0000110, B0011000, B1100000, B0000000, // backslash 2, 8, B1000001, B1111111, B0000000, B0000000, B0000000, // ] 3, 8, B0000010, B0000001, B0000010, B0000000, B0000000, // hat 4, 8, B1000000, B1000000, B1000000, B1000000, B0000000, // _ 2, 8, B0000001, B0000010, B0000000, B0000000, B0000000, // ` 4, 8, B0100000, B1010100, B1010100, B1111000, B0000000, // a 4, 8, B1111111, B1000100, B1000100, B0111000, B0000000, // b 4, 8, B0111000, B1000100, B1000100, B0000000, B0000000, // c // JFM MOD. 4, 8, B0111000, B1000100, B1000100, B1111111, B0000000, // d 4, 8, B0111000, B1010100, B1010100, B0011000, B0000000, // e 3, 8, B0000100, B1111110, B0000101, B0000000, B0000000, // f 4, 8, B10011000, B10100100, B10100100, B01111000, B0000000, // g 4, 8, B1111111, B0000100, B0000100, B1111000, B0000000, // h 3, 8, B1000100, B1111101, B1000000, B0000000, B0000000, // i 4, 8, B1000000, B10000000, B10000100, B1111101, B0000000, // j 4, 8, B1111111, B0010000, B0101000, B1000100, B0000000, // k 3, 8, B1000001, B1111111, B1000000, B0000000, B0000000, // l 5, 8, B1111100, B0000100, B1111100, B0000100, B1111000, // m 4, 8, B1111100, B0000100, B0000100, B1111000, B0000000, // n 4, 8, B0111000, B1000100, B1000100, B0111000, B0000000, // o 4, 8, B11111100, B0100100, B0100100, B0011000, B0000000, // p 4, 8, B0011000, B0100100, B0100100, B11111100, B0000000, // q 4, 8, B1111100, B0001000, B0000100, B0000100, B0000000, // r 4, 8, B1001000, B1010100, B1010100, B0100100, B0000000, // s 3, 8, B0000100, B0111111, B1000100, B0000000, B0000000, // t 4, 8, B0111100, B1000000, B1000000, B1111100, B0000000, // u 5, 8, B0011100, B0100000, B1000000, B0100000, B0011100, // v 5, 8, B0111100, B1000000, B0111100, B1000000, B0111100, // w 5, 8, B1000100, B0101000, B0010000, B0101000, B1000100, // x 4, 8, B10011100, B10100000, B10100000, B1111100, B0000000, // y 3, 8, B1100100, B1010100, B1001100, B0000000, B0000000, // z 3, 8, B0001000, B0110110, B1000001, B0000000, B0000000, // { 1, 8, B1111111, B0000000, B0000000, B0000000, B0000000, // | 3, 8, B1000001, B0110110, B0001000, B0000000, B0000000, // } 4, 8, B0001000, B0000100, B0001000, B0000100, B0000000, // ~ };

void setup() { m.init(); m.setIntensity(3); }

// Scrolling Text char string[] = " Hello, World !!";

void loop() { delay(100); m.shiftLeft(false, true); printStringWithShift(string,100); }

void printCharWithShift(char c, int shift_speed) { if (c < 32) return; c -= 32; memcpy_P(Buf7219, CH + 7*c, 7); m.writeSprite(maxDisplays*8, 0, Buf7219); m.setColumn(maxDisplays*8 + Buf7219[0], 0);

for (int i=0; i<=Buf7219[0]; i++) { delay(shift_speed); m.shiftLeft(false, false); } }

void printStringWithShift(char* s, int shift_speed) { while (*s != 0) { printCharWithShift(*s, shift_speed); s++; } }


Step 6: Uploading

The uploading process is just as usual. Select the board and the port in the tools menu of the IDE. Then verify and Upload the code on to the board. You now have made yourself a cool display board. If you're wondering what the pins on the top of the module do, it is used to connect several matrices together to form a huge display board for yourself.

Step 7: The Output

Well all this hard work, surely pays off pretty well when you see the result. It's worth it !!

That's All Folks !! Stay tuned for more !! Keep DIY-ing !!