Header Ads

Led Scrolling and Animation text display Matrix 40*8 using max7219 with Arduino

Overview

In this tutorial, we will learn how to make led scrolling and animation display by using the 40*8 led matrix display module and Arduino. Most technologies use the dot matrix to display information such as cell phones, televisions, printers etc. It is commonly used to display time, temperature, notice, news updates and many more on digital billboards. 

You can watch the following video below:-

Component Required

The following component needed for this tutorial:-
  • Arduino Uno
  • 40*8 Bi-color Display 
  • Max 7219 IC 
  • 15k Resistor
  • 47uf Capacitor
  • 0.1uf Capacitor
  • Veroboard
  • Some Connecting Wire

Dot Matrix Display Pinout

The led matrix display pin configuration has been given below:-
Fig: 16 pins single color display pinout 

Fig: 24 pins bi-color display pinout

Max7219 Pinout

The following below figure shows max7219 pinout:-
Fig: Max 7219 Pin configuration

Circuit Schematic

The circuit diagram of the led matrix display and Arduino interfacing below:-
Fig: Arduino and led matrix display interfacing

Circuit description

To make a 40*8 led matrix display, here we have used five single 8*8 led bicolor display and five max7219 drivers. The circuit will be connected to following below:-
Pin_3       Connected to      Row_4
Pin_5       Connected to      Row_6
Pin_6       Connected to      Row_2
Pin_7       Connected to      Row_3
Pin_9       Connected to      Row_7
Pin_10      Connected to      Row_5
Pin_11      Connected to      Row_2
Pin_14      Connected to      Clm_7
Pin_15      Connected to      Clm_2
Pin_16      Connected to      Clm_6
Pin_17      Connected to      Clm_1
Pin_20      Connected to      Clm_5
Pin_21      Connected to      Clm_3
Pin_22      Connected to      Clm_8
Pin_23      Connected to      Clm_4
Arduino 5v will be connected to the Max7219 Vcc (Pin 19) and Arduino GND will be connected to the Max7219 GND (Pin 4 and 8). The 22uf and 47uf capacitor will be connected between 5v and GND. Arduino Digital Pin 10 will be connected to the Max7219 CS (Pin 12). Arduino Digital Pin 13 will be connected to the Max7219 CLK (Pin 13). Arduino Digital Pin 11 will be connected to the first display driver max7219 pin DIN(Pin 1). After that, max7219 driver pin DOUT(pin 24) will be connected to the next max7219 driver DIN (Pin 1) and the same procedure will continue till the last driver. 

Source Code

The led matrix display scrolling message code following below:-
 #include <MD_Parola.h>  
 #include <MD_MAX72xx.h>  
 #include <SPI.h>  
   
 // set to 1 if we are implementing the user interface pot, switch, etc  
 #define USE_UI_CONTROL 0  
   
 #if USE_UI_CONTROL  
 #include <MD_KeySwitch.h>  
 #endif  
   
 // Turn on debug statements to the serial output  
 #define DEBUG 0  
   
 #if DEBUG  
 #define PRINT(s, x) { Serial.print(F(s)); Serial.print(x); }  
 #define PRINTS(x) Serial.print(F(x))  
 #define PRINTX(x) Serial.println(x, HEX)  
 #else  
 #define PRINT(s, x)  
 #define PRINTS(x)  
 #define PRINTX(x)  
 #endif  
   
 // Define the number of devices we have in the chain and the hardware interface  
 // NOTE: These pin numbers will probably not work with your hardware and may  
 // need to be adapted  
 #define MAX_DEVICES 5  
 #define CLK_PIN  13  
 #define DATA_PIN 11  
 #define CS_PIN  10  
   
 // HARDWARE SPI  
 MD_Parola P = MD_Parola(CS_PIN, MAX_DEVICES);  
 // SOFTWARE SPI  
 //MD_Parola P = MD_Parola(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);  
    
 // Scrolling parameters  
 #if USE_UI_CONTROL  
 const uint8_t SPEED_IN = A5;  
 const uint8_t DIRECTION_SET = 8; // change the effect  
 const uint8_t INVERT_SET = 9;   // change the invert  
   
 const uint8_t SPEED_DEADBAND = 5;  
 #endif // USE_UI_CONTROL  
   
 uint8_t scrollSpeed = 40;  // default frame delay value  
 textEffect_t scrollEffect = PA_SCROLL_LEFT;  
 textPosition_t scrollAlign = PA_LEFT;  
 uint16_t scrollPause = 0; // in milliseconds  
   
 // Global message buffers shared by Serial and Scrolling functions  
 #define     BUF_SIZE     75  
 char curMessage[BUF_SIZE];  
 char newMessage[BUF_SIZE];  
 bool newMessageAvailable = false;  
   
 #if USE_UI_CONTROL  
   
 MD_KeySwitch uiDirection(DIRECTION_SET);  
 MD_KeySwitch uiInvert(INVERT_SET);  
   
 void doUI(void)  
 {  
  // set the speed if it has changed  
  {  
   int16_t speed = map(analogRead(SPEED_IN), 0, 1023, 10, 150);  
   
   if ((speed >= ((int16_t)P.getSpeed() + SPEED_DEADBAND)) ||  
    (speed <= ((int16_t)P.getSpeed() - SPEED_DEADBAND)))  
   {  
    P.setSpeed(speed);  
    scrollSpeed = speed;  
    PRINT("\nChanged speed to ", P.getSpeed());  
   }  
  }  
   
  if (uiDirection.read() == MD_KeySwitch::KS_PRESS) // SCROLL DIRECTION  
  {  
   PRINTS("\nChanging scroll direction");  
   scrollEffect = (scrollEffect == PA_SCROLL_LEFT ? PA_SCROLL_RIGHT : PA_SCROLL_LEFT);  
   P.setTextEffect(scrollEffect, scrollEffect);  
   P.displayClear();  
   P.displayReset();  
  }  
   
  if (uiInvert.read() == MD_KeySwitch::KS_PRESS) // INVERT MODE  
  {  
   PRINTS("\nChanging invert mode");  
   P.setInvert(!P.getInvert());  
  }  
 }  
 #endif // USE_UI_CONTROL  
   
 void readSerial(void)  
 {  
  static char *cp = newMessage;  
   
  while (Serial.available())  
  {  
   *cp = (char)Serial.read();  
   if ((*cp == '\n') || (cp - newMessage >= BUF_SIZE-2)) // end of message character or full buffer  
   {  
    *cp = '\0'; // end the string  
    // restart the index for next filling spree and flag we have a message waiting  
    cp = newMessage;  
    newMessageAvailable = true;  
   }  
   else // move char pointer to next position  
    cp++;  
  }  
 }  
   
 void setup()  
 {  
  Serial.begin(57600);  
  Serial.print("\n[Parola Scrolling Display]\nType a message for the scrolling display\nEnd message line with a newline");  
   
 #if USE_UI_CONTROL  
  uiDirection.begin();  
  uiInvert.begin();  
  pinMode(SPEED_IN, INPUT);  
   
  doUI();  
 #endif // USE_UI_CONTROL  
   
  P.begin();  
  P.displayClear();  
  P.displaySuspend(false);  
   
  P.displayText(curMessage, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);  
   
  strcpy(curMessage, "Bionics Robotics and Computation");  
  newMessage[0] = '\0';  
 }  
   
 void loop()  
 {  
 #if USE_UI_CONTROL  
  doUI();  
 #endif // USE_UI_CONTROL  
   
  readSerial();  
  if (P.displayAnimate())  
  {  
   if (newMessageAvailable)  
   {  
    strcpy(curMessage, newMessage);  
    newMessageAvailable = false;  
   }  
   P.displayReset();  
  }  
 }  
The led matrix display animation message code following below:-
 #include <MD_Parola.h>  
 #include <MD_MAX72xx.h>  
 #include <SPI.h>  
   
 // Define the number of devices we have in the chain and the hardware interface  
 // NOTE: These pin numbers will probably not work with your hardware and may  
 // need to be adapted  
 #define MAX_DEVICES 4  
 #define CLK_PIN  13  
 #define DATA_PIN 11  
 #define CS_PIN  10  
   
 // Hardware SPI connection  
 MD_Parola P = MD_Parola(CS_PIN, MAX_DEVICES);  
 // Arbitrary output pins  
 // MD_Parola P = MD_Parola(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES)  
   
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))  
   
 // Global data  
 typedef struct  
 {  
  textEffect_t effect;  // text effect to display  
  char *    psz;   // text string nul terminated  
  uint16_t   speed;  // speed multiplier of library default  
  uint16_t   pause;  // pause multiplier for library default  
 } sCatalog;  
   
 sCatalog catalog[] =  
 {  
  { PA_PRINT, "PRINT", 1, 1 },  
  { PA_SLICE, "SLICE", 1, 1 },  
  { PA_MESH, "MESH", 20, 1 },  
  { PA_FADE, "FADE", 20, 1 },  
  { PA_WIPE, "WIPE", 5, 1 },  
  { PA_WIPE_CURSOR, "WPE_C", 4, 1 },  
  { PA_OPENING, "OPEN", 3, 1 },  
  { PA_OPENING_CURSOR, "OPN_C", 4, 1 },  
  { PA_CLOSING, "CLOSE", 3, 1 },  
  { PA_CLOSING_CURSOR, "CLS_C", 4, 1 },  
  { PA_RANDOM, "RAND", 3, 1 },  
  { PA_BLINDS, "BLIND", 7, 1 },  
  { PA_DISSOLVE, "DSLVE", 7, 1 },  
  { PA_SCROLL_UP, "SC_U", 5, 1 },  
  { PA_SCROLL_DOWN, "SC_D", 5, 1 },  
  { PA_SCROLL_LEFT, "SC_L", 5, 1 },  
  { PA_SCROLL_RIGHT, "SC_R", 5, 1 },  
  { PA_SCROLL_UP_LEFT, "SC_UL", 7, 1 },  
  { PA_SCROLL_UP_RIGHT, "SC_UR", 7, 1 },  
  { PA_SCROLL_DOWN_LEFT, "SC_DL", 7, 1 },  
  { PA_SCROLL_DOWN_RIGHT, "SC_DR", 7, 1 },  
  { PA_SCAN_HORIZ, "SCANH", 4, 1 },  
  { PA_SCAN_VERT, "SCANV", 3, 1 },  
  { PA_GROW_UP, "GRW_U", 7, 1 },  
  { PA_GROW_DOWN, "GRW_D", 7, 1 },  
 };  
   
   
 void setup(void)  
 {  
  P.begin();  
  P.setInvert(false);  
   
  for (uint8_t i=0; i<ARRAY_SIZE(catalog); i++)  
  {  
   catalog[i].speed *= P.getSpeed();  
   catalog[i].pause *= 500;  
  }  
 }  
   
 void loop(void)  
 {  
  for (uint8_t j=0; j<3; j++)  
  {  
   textPosition_t just;  
   
   switch (j)  
   {  
   case 0: just = PA_LEFT;  break;  
   case 1: just = PA_CENTER; break;  
   case 2: just = PA_RIGHT;  break;  
   }  
   
   for (uint8_t i=0; i<ARRAY_SIZE(catalog); i++)  
   {  
    P.displayText(catalog[i].psz, just, catalog[i].speed, catalog[i].pause, catalog[i].effect, catalog[i].effect);  
   
    while (!P.displayAnimate())  
     ; // animates and returns true when an animation is completed  
   
    delay(catalog[i].pause);  
   }  
  }  
 }  

You can download the library from here:- 
https://github.com/MajicDesigns/MD_MAX72XX
https://github.com/MajicDesigns/MD_Parola

No comments

Powered by Blogger.