MAX7219 and Arduino: interactive scrolling LED text
|
It’s easy to make a scrolling text ticker with an Arduino Uno and multiple MAX7219 8×8 LED matrix modules. Just 5 connections between the Arduino and the first module are required: 3 for data and 2 for power. Multiple modules can be daisychained. Depending on the power available you can connect many of these modules together.
How-to: interactive ticker display
In this short tutorial you can read how to easily make an interactive ticker display. The display will show a preprogrammed line of text first. After that you can type in some characters and send them to the dispay over the serial connection.
Wiring Arduino and MAX7219 8×8 LED matrix modules
Only the first display needs to be wired to the Arduino. Any additional modules will be daisychained. See this example featuring 3 displays:


Arduino Uno | MAX7219 |
5V | VCC |
GND | GND |
D8 | DIN |
D9 | CS |
D10 | CLK |
MaxMatrix library
To make it easy to communicatre with the matrix-modules we will be using the “MaxMatrix”-library which you can download here: https://github.com/riyas-org/. There you can also find a code example which we will adapt and make interactive. It will allow you to send text from yout computer to the display over the serial connection.
Example code: interactive scrolling text display
After installing the MaxMatrix library you can download or copy/paste the sketch you see below. A few values you can customize:
- The value “maxInUse” will set the number of modules conected to the Arduino;
- The value “scrollSpeed” will set the scrolling speed: lower value means faster scrolling;
- And “m.setIntensity()” sets the LED intensity from 0 tot 15: higher value means brighter LEDs.
After you have uploaded the sketch to the Arduino, you will first see the predefined text scrolling along. After that, you can open the serial monitor in the Arduino-IDE and send a new text (max. 64 characters) to the display.
/* Interactive scrolling led sign for Arduino and MAX7219 8x8 LED Display This is the code I use to control the MAX7219 8x8 LED modules from my Chinese "Geekcreit"-brand Arduino clone. The first module is connected to the Uno like this: Module: VCC -> Uno: 5V Module: GND -> Uno: GND Module: DIN -> Uno: D8 Module: CS -> Uno: D9 Module: CLK -> Uno: D10 Additional modules are connected like this: Module 2: VCC -> Module 1: VCC Module 2: GND -> Module 1: GND Module 2: DIN -> Module 1: DIN Module 2: CS -> Module 1: CS Module 2: CLK -> Module 1: CLK See the blog post at https://oneguyoneblog.com/2016/10/20/max7219-arduino-ticker-8x8-led-modules/ */ #include <MaxMatrix.h> #include <avr/pgmspace.h> PROGMEM prog_uchar const 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 displays int load = 9; // CS pin of MAX7219 displays int clock = 10; // CLK pin of MAX7219 displays int scrollSpeed = 35; // speed of scrolling text, lower is faster int maxInUse = 3; //Number of MAX7219 displays MaxMatrix m(data, load, clock, maxInUse); // define Library byte buffer[10]; char inData[64] = "MAX7219 8x8 LED Matrix - Visit oneguyoneblog.com"; // The string (max 64 bytes) char inChar; // Where to store the character read byte index = 0; // Index into array; where to store the character void setup(){ m.init(); // init display m.setIntensity(7); // LED light intensity from 0 (dimmest) to 15 Serial.begin(9600); // init serial connection } void loop(){ // Get input from serial connection index=0; while(Serial.available() > 0) // Don't read unless there is data { if(index < 63) // One less than the size of the array { inChar = Serial.read(); // Read a character Serial.write(inChar); inData[index] = inChar; // Store it index++; // Increment where to write next inData[index] = '\0'; // Null terminate the string } } byte c; delay(100); m.shiftLeft(false, true); printStringWithShift(inData, scrollSpeed); // Send scrolling Text clearLCD(maxInUse, scrollSpeed); } // Put extracted character on Display void printCharWithShift(char c, int shift_speed){ if (c < 32) return; c -= 32; memcpy_P(buffer, CH + 7*c, 7); m.writeSprite(maxInUse*8, 0, buffer); m.setColumn(maxInUse*8 + buffer[0], 0); for (int i=0; i<buffer[0]+1; i++) { delay(shift_speed); m.shiftLeft(false, false); } } // Extract characters from Scrolling text void printStringWithShift(char* s, int shift_speed){ while (*s != 0){ printCharWithShift(*s, shift_speed); s++; } } // Add trailing space to clear the display void clearLCD(int maxInUse, int shift_speed){ for (int i=0; i<maxInUse*8; i++) { m.setColumn((maxInUse*8), 0); delay(shift_speed); m.shiftLeft(false, false); } }
This sketch is also available on GitHub: https://github.com/oneguyoneblog/
Hello,
Thank you for your inspirational tutorial.
Reading the sketch for the 8×8 LED matrix i found a small error in line 19:
Module 2: DIN -> Module 1: DIN
this should of course be:
Module 2: DIN -> Module 1: DOUT
When I try to compile, the result is an error:
sketch_nov14a__scroll__longtest__monitorinput:23: error: ‘prog_uchar’ does not name a type
PROGMEM prog_uchar const CH[] =
I have the latest IDE from Arduino (1.8.5). Can you help me locating the fault please?
Best Regards Jan
I have the same failure. But i don’t have the Matrix (i wait for it, from China *fg*). it schould be as we follows:
char const
i can’t actually test it.
Greetings (sry for my bad english)
change to :PROGMEM const unsigned char CH[] = {
I want to know what is the key factor in scrolling? I want to do it in C, but what I get is synchronized data along the 4 modules.
Hi and thank you a lot, that’s a nice commented and very nice code there!
One question: could you point me in the right direction on change the scrolldirection
angle about 90° Degrees to the left?
Then the scrolling would be aligned to the Matrix, given that the pinout should be on the left. Which brings up another question, can’t you directly connect multiple Matrixes without wire, just by pluging them together?
Thanks again (-:
what does ShiftLeft(false,true) do? Please explain me the parameters?
I am having the same problem regardless who’s sketch I attempt. Seems like the Arduino is only addressing a single module at a time, i.e., if I just input a single character, it will scroll on the first module, right to left, then the second, then third and then the last. Any suggestions on what might be my problem?
Hi! Thank you for this tutorial. I uploaded and got it to work… I was trying to code this kind of project before but have not succeeded…
I have just one question. Is it possible to increase the max. character from 64?
I’ve tried changing “char inData[64]” and “if(index < 63) // One less than the size of the array" but it always allows 64 characters.
Thank you again and thank you in advance for your answer.
Hi. How to change display orientation . Want to rotate 180 degree