Módulo Max7219 matriz de leds 8×8

Abordei anteriormente o uso do CI Max7219 para controle de display de 7 segmentos. Vimos que com ele é possível controlar até 8 displays de 7 segmentos por CI, e podemos ligar 8 CI’s em série, ou seja, podemos utilizar o Arduino para controlar até 64 displays. Neste post veremos um outro uso deste CI usando o Módulo Max7219 com matriz de leds 8×8.

O uso desse tipo de matriz possibilita a montagem de painéis elaborados, onde podemos exibir números, letras e desenhos, e dependendo da configuração da matriz, mostrar tudo isso em várias formas, tamanhos e cores:

Imagens : Blog Arduino Android  e Adafruit

A ligação da matriz de leds na protoboard costuma ser um pouco complexa e exige muita atenção para não danificar os componentes, principalmente a matriz de leds em si, que costuma ser um componente sensível.

Felizmente, existem módulos matriz de leds prontos para este fim, que consistem em um CI Max7219, uma matriz de leds 8×8 e alguns outros componentes, como capacitores e resistores. Pode ser encontrado em forma de kits, como esse:

ou já montados e prontos para usar, como esse:

Repare que no lado esquedo do módulo, estão os pinos de entrada, nomeados como VCC, GND, DIN, CS e CLK. Os pinos do lado direito são utilizados para interligar vários módulos, e serão assunto para outro post. Hoje vamos ver como ligar este único módulo no Arduino e como mostrar caracteres na matriz em scroll horizontal. Fiz um pequeno vídeo de teste, onde além dos caracteres em scroll podem ser visualizadas outras figuras:

Como usar o módulo Max7219 com Arduino

A ligação ao Arduino, da mesma forma que no post Controlando Display 7 Segmentos com o Max7219, usa apenas 3 portas da placa, o que dá bastante flexibilidade para usarmos sensores, leds, botões, etc. juntamente com o módulo:

Conexões do módulo Max7219 no Arduino:

O programa foi baseado no livro Arduino Básico, do autor Michael McRoberts, com pequenas alterações e adaptações. Carregue o programa no Arduino alterando as linhas de mensagem, conforme indicado no final do programa, para exibir as informações que você quiser:

// Programa : Scroll horizontal com matriz de leds 8x8  
// Baseado no livro Arduino Basico, de Michael McRoberts  
// Alterações e comentários : Arduino e Cia  
   
#include <pgmspace.h>  
#include <TimerOne.h>  
   
int DataPin = 4;  //Ligar o pino 4 do Arduino ao DIN do modulo  
int ClockPin = 5; //Ligar o pino 5 do Arduino ao CLK do módulo  
int LoadPin = 6;  //Ligar o pino 6 do Arduinio ao pino CS/Load do módulo  
  
byte buffer[8];  
   
static byte font[][8] PROGMEM = {  
{B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000},   
{B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, B00000000, B00000100},   
{B00001010, B00001010, B00001010, B00000000, B00000000, B00000000, B00000000, B00000000},   
{B00000000, B00001010, B00011111, B00001010, B00011111, B00001010, B00011111, B00001010},   
{B00000111, B00001100, B00010100, B00001100, B00000110, B00000101, B00000110, B00011100},   
{B00011001, B00011010, B00000010, B00000100, B00000100, B00001000, B00001011, B00010011},   
{B00000110, B00001010, B00010010, B00010100, B00001001, B00010110, B00010110, B00001001},   
{B00000100, B00000100, B00000100, B00000000, B00000000, B00000000, B00000000, B00000000},   
{B00000010, B00000100, B00001000, B00001000, B00001000, B00001000, B00000100, B00000010},   
{B00001000, B00000100, B00000010, B00000010, B00000010, B00000010, B00000100, B00001000},   
{B00010101, B00001110, B00011111, B00001110, B00010101, B00000000, B00000000, B00000000},   
{B00000000, B00000000, B00000100, B00000100, B00011111, B00000100, B00000100, B00000000},   
{B00000000, B00000000, B00000000, B00000000, B00000000, B00000110, B00000100, B00001000},   
{B00000000, B00000000, B00000000, B00000000, B00001110, B00000000, B00000000, B00000000},   
{B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000100},   
{B00000001, B00000010, B00000010, B00000100, B00000100, B00001000, B00001000, B00010000},   
{B00001110, B00010001, B00010011, B00010001, B00010101, B00010001, B00011001, B00001110},   
{B00000100, B00001100, B00010100, B00000100, B00000100, B00000100, B00000100, B00011111},   
{B00001110, B00010001, B00010001, B00000010, B00000100, B00001000, B00010000, B00011111},   
{B00001110, B00010001, B00000001, B00001110, B00000001, B00000001, B00010001, B00001110},   
{B00010000, B00010000, B00010100, B00010100, B00011111, B00000100, B00000100, B00000100},   
{B00011111, B00010000, B00010000, B00011110, B00000001, B00000001, B00000001, B00011110},   
{B00000111, B00001000, B00010000, B00011110, B00010001, B00010001, B00010001, B00001110},   
{B00011111, B00000001, B00000001, B00000001, B00000010, B00000100, B00001000, B00010000},   
{B00001110, B00010001, B00010001, B00001110, B00010001, B00010001, B00010001, B00001110},   
{B00001110, B00010001, B00010001, B00001111, B00000001, B00000001, B00000001, B00000001},   
{B00000000, B00000100, B00000100, B00000000, B00000000, B00000100, B00000100, B00000000},   
{B00000000, B00000100, B00000100, B00000000, B00000000, B00000100, B00000100, B00001000},   
{B00000001, B00000010, B00000100, B00001000, B00001000, B00000100, B00000010, B00000001},   
{B00000000, B00000000, B00000000, B00011110, B00000000, B00011110, B00000000, B00000000},   
{B00010000, B00001000, B00000100, B00000010, B00000010, B00000100, B00001000, B00010000},   
{B00001110, B00010001, B00010001, B00000010, B00000100, B00000100, B00000000, B00000100},   
{B00001110, B00010001, B00010001, B00010101, B00010101, B00010001, B00010001, B00011110},   
{B00001110, B00010001, B00010001, B00010001, B00011111, B00010001, B00010001, B00010001},   
{B00011110, B00010001, B00010001, B00011110, B00010001, B00010001, B00010001, B00011110},   
{B00000111, B00001000, B00010000, B00010000, B00010000, B00010000, B00001000, B00000111},   
{B00011100, B00010010, B00010001, B00010001, B00010001, B00010001, B00010010, B00011100},  
{B00011111, B00010000, B00010000, B00011110, B00010000, B00010000, B00010000, B00011111},   
{B00011111, B00010000, B00010000, B00011110, B00010000, B00010000, B00010000, B00010000},   
{B00001110, B00010001, B00010000, B00010000, B00010111, B00010001, B00010001, B00001110},   
{B00010001, B00010001, B00010001, B00011111, B00010001, B00010001, B00010001, B00010001},   
{B00011111, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, B00011111},   
{B00011111, B00000100, B00000100, B00000100, B00000100, B00000100, B00010100, B00001000},   
{B00010001, B00010010, B00010100, B00011000, B00010100, B00010010, B00010001, B00010001},   
{B00010000, B00010000, B00010000, B00010000, B00010000, B00010000, B00010000, B00011111},   
{B00010001, B00011011, B00011111, B00010101, B00010001, B00010001, B00010001, B00010001},   
{B00010001, B00011001, B00011001, B00010101, B00010101, B00010011, B00010011, B00010001},   
{B00001110, B00010001, B00010001, B00010001, B00010001, B00010001, B00010001, B00001110},   
{B00011110, B00010001, B00010001, B00011110, B00010000, B00010000, B00010000, B00010000},   
{B00001110, B00010001, B00010001, B00010001, B00010001, B00010101, B00010011, B00001111},   
{B00011110, B00010001, B00010001, B00011110, B00010100, B00010010, B00010001, B00010001},   
{B00001110, B00010001, B00010000, B00001000, B00000110, B00000001, B00010001, B00001110},   
{B00011111, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100},   
{B00010001, B00010001, B00010001, B00010001, B00010001, B00010001, B00010001, B00001110},   
{B00010001, B00010001, B00010001, B00010001, B00010001, B00010001, B00001010, B00000100},   
{B00010001, B00010001, B00010001, B00010001, B00010001, B00010101, B00010101, B00001010},   
{B00010001, B00010001, B00001010, B00000100, B00000100, B00001010, B00010001, B00010001},   
{B00010001, B00010001, B00001010, B00000100, B00000100, B00000100, B00000100, B00000100},   
{B00011111, B00000001, B00000010, B00000100, B00001000, B00010000, B00010000, B00011111},   
{B00001110, B00001000, B00001000, B00001000, B00001000, B00001000, B00001000, B00001110},   
{B00010000, B00001000, B00001000, B00000100, B00000100, B00000010, B00000010, B00000001},   
{B00001110, B00000010, B00000010, B00000010, B00000010, B00000010, B00000010, B00001110},   
{B00000100, B00001010, B00010001, B00000000, B00000000, B00000000, B00000000, B00000000},   
{B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00011111},   
{B00001000, B00000100, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000},   
{B00000000, B00000000, B00000000, B00001110, B00010010, B00010010, B00010010, B00001111},   
{B00000000, B00010000, B00010000, B00010000, B00011100, B00010010, B00010010, B00011100},   
{B00000000, B00000000, B00000000, B00001110, B00010000, B00010000, B00010000, B00001110},   
{B00000000, B00000001, B00000001, B00000001, B00000111, B00001001, B00001001, B00000111},   
{B00000000, B00000000, B00000000, B00011100, B00010010, B00011110, B00010000, B00001110},   
{B00000000, B00000011, B00000100, B00000100, B00000110, B00000100, B00000100, B00000100},   
{B00000000, B00001110, B00001010, B00001010, B00001110, B00000010, B00000010, B00001100},   
{B00000000, B00010000, B00010000, B00010000, B00011100, B00010010, B00010010, B00010010},   
{B00000000, B00000000, B00000100, B00000000, B00000100, B00000100, B00000100, B00000100},   
{B00000000, B00000010, B00000000, B00000010, B00000010, B00000010, B00000010, B00001100},   
{B00000000, B00010000, B00010000, B00010100, B00011000, B00011000, B00010100, B00010000},   
{B00000000, B00010000, B00010000, B00010000, B00010000, B00010000, B00010000, B00001100},   
{B00000000, B00000000, B00000000, B00001010, B00010101, B00010001, B00010001, B00010001},   
{B00000000, B00000000, B00000000, B00010100, B00011010, B00010010, B00010010, B00010010},   
{B00000000, B00000000, B00000000, B00001100, B00010010, B00010010, B00010010, B00001100},   
{B00000000, B00011100, B00010010, B00010010, B00011100, B00010000, B00010000, B00010000},   
{B00000000, B00001110, B00010010, B00010010, B00001110, B00000010, B00000010, B00000001},   
{B00000000, B00000000, B00000000, B00001010, B00001100, B00001000, B00001000, B00001000},   
{B00000000, B00000000, B00001110, B00010000, B00001000, B00000100, B00000010, B00011110},   
{B00000000, B00010000, B00010000, B00011100, B00010000, B00010000, B00010000, B00001100},   
{B00000000, B00000000, B00000000, B00010010, B00010010, B00010010, B00010010, B00001100},   
{B00000000, B00000000, B00000000, B00010001, B00010001, B00010001, B00001010, B00000100},   
{B00000000, B00000000, B00000000, B00010001, B00010001, B00010001, B00010101, B00001010},   
{B00000000, B00000000, B00000000, B00010001, B00001010, B00000100, B00001010, B00010001},   
{B00000000, B00000000, B00010001, B00001010, B00000100, B00001000, B00001000, B00010000},   
{B00000000, B00000000, B00000000, B00011111, B00000010, B00000100, B00001000, B00011111},   
{B00000010, B00000100, B00000100, B00000100, B00001000, B00000100, B00000100, B00000010},   
{B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100},   
{B00001000, B00000100, B00000100, B00000100, B00000010, B00000100, B00000100, B00001000},   
{B00000000, B00000000, B00000000, B00001010, B00011110, B00010100, B00000000, B00000000}   
};  
   
void clearDisplay() 
{
    for (byte x=0; x<8; x++) 
    {  
       buffer[x] = B00000000;  
    }  
    screenUpdate();  
}  
  
void initMAX7219() 
{  
    pinMode(DataPin, OUTPUT);  
    pinMode(LoadPin, OUTPUT);  
    pinMode(ClockPin, OUTPUT);  
    clearDisplay();  
    writeData(B00001011, B00000111);   
    writeData(B00001001, B00000000);   
    writeData(B00001100, B00000001);   
    intensity(1);   
}  
   
void intensity(int intensity) 
{  
    writeData(B00001010, intensity);   
}  
   
void writeData(byte MSB, byte LSB) 
{  
    byte mask;  
    digitalWrite(LoadPin, LOW);   
      
    for (mask = B10000000; mask>0; mask >>= 1) 
    {   
        digitalWrite(ClockPin, LOW);  
        if (MSB & mask)
        {   
           digitalWrite(DataPin,HIGH);   
        }  
        else
        {   
           digitalWrite(DataPin,LOW);   
        }  
        digitalWrite(ClockPin, HIGH);   
    }  
      
    for (mask = B10000000; mask>0; mask >>= 1) 
    {   
        digitalWrite(ClockPin, LOW);  
        if (LSB & mask)
        {   
           digitalWrite(DataPin,HIGH);   
        }  
        else
        {   
            digitalWrite(DataPin,LOW);   
        }  
        digitalWrite(ClockPin, HIGH);   
    }  
    digitalWrite(LoadPin, HIGH);   
    digitalWrite(ClockPin, LOW);  
}  
   
void scroll(char myString[], int speed) 
{  
    byte firstChrRow, secondChrRow;  
    byte ledOutput;  
    byte chrPointer = 0;   
    byte Char1, Char2;   
    byte scrollBit = 0;  
    byte strLength = 0;  
    unsigned long time;  
    unsigned long counter;  
       
    while (myString[strLength]) {strLength++;}  
    counter = millis();  
    while (chrPointer < (strLength-1)) 
    {  
       time = millis();  
       if (time > (counter + speed)) 
       { 
          Char1 = myString[chrPointer];  
          Char2 = myString[chrPointer+1];  
          for (byte y= 0; y<8; y++) 
          {  
            firstChrRow = pgm_read_byte(&font[Char1 - 32][y]);  
            secondChrRow = (pgm_read_byte(&font[Char2 - 32][y])) << 1;  
            ledOutput = (firstChrRow << scrollBit) | (secondChrRow >> (8 - scrollBit) );  
            buffer[y] = ledOutput;  
          }  
            scrollBit++;   
            if (scrollBit > 6) 
            {   
              scrollBit = 0;  
              chrPointer++;  
            }  
            counter = millis();  
        }  
    }  
}  
   
void screenUpdate() 
{  
   for (byte row = 0; row < 8; row++) 
   { 
      writeData(row+1, buffer[row]);  
   }  
}  
   
void setup() 
{  
   initMAX7219();  
   Timer1.initialize(10000);       
   Timer1.attachInterrupt(screenUpdate);   
}  
  
void loop() 
{  
   clearDisplay();    
   //Exibe a mensagem, com intervalo de scroll de 100
   scroll(" Arduino e Cia ", 100); 
   //Adicione mais linhas para mostrar outros caracteres
   scroll(" - 2013 ", 100);        
}  

Quer interligar dois ou mais módulos? Veja o artigo Painel de Led com módulo Max7219. Confira também como montar um placar eletrônico usando Max7219 no post Placar Eletrônico com Arduino.

5/5 - (2 votos)

Related posts

Teclado touch para Arduino – Touch Shield Sparkfun

by Arduino e Cia
10 anos ago

Max7219 com display 7 segmentos

by Arduino e Cia
11 anos ago

Genuino 101 com Intel® Curie™

by Arduino e Cia
8 anos ago
Sair da versão mobile