You are on page 1of 9

16x8 LED dot matrix with MAX7219 module and ARDUINO

The objective of this project is: to show off the use of the module "MAX7219 dot matrix
display module MCU control DIY" In order to using it you will need the module that can
be purchased on ebay:
http://www.ebay.com/itm/171048735052?ssPageName=STRK:MEWNX:IT&_trksid=p3
984.m1439.l2649
And you will need the MaxMatrix libraries files (which are 3):
https://docs.google.com/file/d/0B_YlEklLDDS7MDhRdWJKdmZQTnc/edit?usp=sharing
https://docs.google.com/file/d/0B_YlEklLDDS7WE9lQ1F1aFhnYlE/edit?usp=sharing
https://docs.google.com/file/d/0B_YlEklLDDS7djd5T2JDeFVsaVE/edit?usp=sharing
The sketch with
the code can
be found on the link
below:
https://docs.google.com/file/d/0B_YlEklLDDS7WTF0c2hlVzFCZWc/edit?usp=sharing
See in the attached picture the interconnection diagram between Arduino module and
MAX7219 module (it was used only 2 MAX7219 modules in this case):
Arduino pin 13 (alternative: pin 10) connected to the CLK pin of the module MAX7219
Arduino pin 11 (alternative: pin 8) connected to pin DIN module MAX7219
Arduino pin 10 (alternative: 9 pin) connected to pin CS module MAX7219
GND and VCC (+5V). To expand the number of modules, you should just connect Dout
pin of one MAX7219 module with the Din pin of the another MAX7219 module... and
so on. The MAX7219 Dout pin is at the top of the module while Din pin is at the botton
of the module. Remembering that you can connect modules as you want, just
connecting the output of one module with the input of the other and leaving the other
signals in parallel. In the sketch, you should to modify the parameter "maxInUse" for
the amount of modules that you will use.

Sketch:
/*
############################################################################
####
# File Name:
MAX7219_5.ino
# Board:
Arduino UNO
# Programming Language:
Wiring / C /Processing /Fritzing / Arduino IDE
#
# Objective:
Scrolling LED dot Matrix
#
# Operation:
Scrolls a message over a 16x8 LED dot matrix
#
# Author:
Marcelo Moraes
# Date:
July 9th, 2013
# Place:
Sorocaba - SP - Brazil
#
############################################################################
####
This code is a public example.
*/
//******************************************************************************
// visit this web page for further information about MaxMatrix library
// https://code.google.com/p/arudino-maxmatrix-library/
//******************************************************************************
#include <MaxMatrix.h>
#include <avr/pgmspace.h>
PROGMEM prog_uchar CH[] = {
3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // "
5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // '
3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // 2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1
4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
2, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // :
2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // <
3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // =

3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >


4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b
4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f
4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y

3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z


3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
};
int data = 8; // DIN pin of MAX7219 module
int load = 9; // CS pin of MAX7219 module
int clock = 10; // CLK pin of MAX7219 module
int maxInUse = 2;

//change this variable to set how many MAX7219's you'll use

MaxMatrix m(data, load, clock, maxInUse); // define module


byte buffer[10];
// active sentenses
char string1[] = " Hello, my name is Ivan Aldas and...
";
char string2[] = " I am glad to show you my Arduino scrolling dot Matrix
";
char string3[] = " using MAX7219 IC ";
char string4[] = " Visit my blog at: http://arduinobymyself.blogspot.com.br ";
char string5[] = " There you will find a lot of projects with Arduino. ";
char string6[] = " Thanks for watching =)
";

// just for tests


char string7[] = " A B C D E F G H I J K L M N O P Q R S T U V X W Y Z ";
char string8[] = " a b c d e f g h i j k l m n o p q r s t u v x w y z ";
char string9[] = " 1 2 3 4 5 6 7 8 9 0 - = ";
char string10[] = " ! @ # $ % & * ( ) _ + ";
char string11[] = " ' , . ; ~ ] [ | < > : ^ } ` { / ? ";
char string12[] = " Hello ! ";

void setup(){
m.init(); // module initialize
m.setIntensity(0); // dot matix intensity 0-15
Serial.begin(9600); // serial communication initialize
}
void loop(){
/*
// this is the code if you want to entering a message via serial console
while (Serial.available() > 0){
byte c = Serial.read();
Serial.println(c, DEC);
printCharWithShift(c, 100);
}
delay(100);
m.shiftLeft(false, true);
*/
// print the active sentences
printStringWithShift(string1, 100);
printStringWithShift(string2, 100);
printStringWithShift(string3, 100);
printStringWithShift(string4, 100);
printStringWithShift(string5, 100);

printStringWithShift(string6, 100);
// print sentences just for tests
//printStringWithShift(string7, 100);
//printStringWithShift(string8, 100);
//printStringWithShift(string9, 100);
//printStringWithShift(string10, 100);
//printStringWithShift(string11, 100);
}
void printCharWithShift(char c, int shift_speed){
if (c < 32) return;
c -= 32;
memcpy_P(buffer, CH + 7*c, 7);
m.writeSprite(32, 0, buffer);
m.setColumn(32 + buffer[0], 0);
for (int i=0; i<buffer[0]+1; i++)
{
delay(shift_speed);
m.shiftLeft(false, false);
}
}
void printStringWithShift(char* s, int shift_speed){
while (*s != 0){
printCharWithShift(*s, shift_speed);
s++;
}
}
void printString(char* s)
{
int col = 0;
while (*s != 0)
{
if (*s < 32) continue;
char c = *s - 32;
memcpy_P(buffer, CH + 7*c, 7);
m.writeSprite(col, 0, buffer);
m.setColumn(col + buffer[0], 0);
col += buffer[0] + 1;
s++;
}
}

Usage
Featured, Phase-Deploy
Updated Feb 27, 2013 by oscark...@gmail.com

Usage
Include library
#include <MaxMatrix.h>

Create & Init MaxMatrix Object


MaxMatrix m(dataIn, load, clock, maxInUse);
m.Init();

maxInUse is the numbers of MAX7219 used.

Set Intensity of the LED matrix


m.setIntensity(value)

value is the new intensity value, ranges from 0 to 15.

Update a specified column


m.setColumn(col, value);

col is the index of column to be updated, range from 0 to 79.


value is the new values of LEDs, encoded as a unsigned byte.

Update a specified LED


m.setDot(col, row, value)

col is the index of column of the LED to be updated, range from 0 to 79.
row is the index of row of the LED to be updated, range from 0 to 7.
value is the new values of LED, encoded as boolean value (HIGH / LOW).

Update the same column of all LED matrix


m.setColumnAll(col, value);

col is the index of column to be updated, range from - 7.


value is the new values of LEDs, encoded as a unsigned byte.

Write a sprite
m.writeSprite(x, y, sprite)

x is the index of column of the sprite to be displayed, range from 0 to 79.


y is the index of row of the sprite to be displayed, range from 0 to 7.
sprite is the pointer to a byte array, encoding the contains of the sprite.

The format of the sprite is as follow:

sprite0: the number of columns of the sprite, should be >= 1

sprite1: the number of rows of the sprite, should be >= 1

sprite- n: the sprite contents, encoded in column-based unsigned bytes, each array
element represents 1 column of the sprite. If the sprite has n rows (n < 8), only the n
LMS bits of each byte is used.

The code below display the sprite of letter "A" on the LED matrix
// CH_A stores the sprite 'A'
//
// **
// * *
// * *
// * *
// ****
// * *
// * *
byte CH_A[] = {4, 8, B1111110, B0010001, B0010001, B1111110 };
m.writeSprite(0, 0, sprite);

Shift the matrix


m.shiftLeft(rotate = false, fill_zero = true);
m.shiftRight(rotate = false, fill_zero = true);
m.shiftUp(rotate = false, fill_zero = true);
m.shiftDown(rotate = false, fill_zero = true);

These 4 functions shift the values of matrix in one of the direction, by default the shift-in
row/column is filled with zero (LED off). To rotate the LED values (i.e. the shift-in row/column is
filled with shift-out values), you can set the rotate flag to true.
m.shiftLeft(true);

You can also shift in the value outside the matrix, by first uploading the values in the buffer
(outside the matrix space you used) and calling the shiftLeft function. This is useful for creating
scrolling message and animation. The code below shows how to scroll the letter 'A' into the LED
matrix (assume one MAX7219 is used):
byte CH_A[] = {4, 8, B1111110, B0010001, B0010001, B1111110 };
m.writeSprite(8, 0, sprite); // write sprite OUTSIDE the LED matrix
for (int i=0; i<CH_A[0]; i++)
{
m.shiftLeft(false, false);
delay(100);
}

You might also like