4
LED Scrolling Marquee

In this project we’ll use a built-in driver module to create a scrolling message on an 8×8 matrix.

Image
Image

PARTS REQUIRED

Arduino board

Female-to-male jumper wires

8×8 LED Maxim 7219 matrix module

LIBRARY REQUIRED

MaxMatrix

HOW IT WORKS

An LED matrix is an array of LEDs that you can control individually to make patterns, text, images, or whatever you can program. The 8×8 LED matrix we’ll use in this project comes prebuilt with a driver module—a board, driven by a Maxim 7219 chip, that lets you control the entire matrix with only five pins connected to your Arduino. These modules are inexpensive and can be chained together so you have multiple matrices running from one sketch.

The matrix module has three pins: DIN, CS, and CLK, shown in Figure 4-1. DIN stands for Data IN, CS for Chip Select, and CLK for CLocK. The remaining two pins connected to your Arduino power the matrix. The CLK pin senses pulses and controls the speed at which the Arduino and matrix communicate with each other in sync. The matrix uses a serial peripheral interface (SPI) communication protocol to speak with the Arduino, and the CS pin detects which SPI device is in use. DIN reads the data—in this case, the project’s sketch—from the Arduino.

FIGURE 4-1: The Maxim 7219 chip controls the LED matrix.

Image

Each module has extra connections so you can add another module. By chaining together modules and changing the number of matrices in the code, you could scroll a message over a larger area.

THE BUILD

  1. Connect the module directly to the Arduino using the female-to-male jumper wires, connecting the female end to the module. As shown in the following table, connect VCC on the LED matrix module to +5V on the Arduino, GND to GND, DIN to Arduino pin 8, CS to Arduino pin 9, and CLK to Arduino pin 10.

    LED MATRIX MODULE

    ARDUINO

    VCC

    +5V

    GND

    GND

    DIN

    Pin 8

    CS

    Pin 9

    CLK

    Pin 10

  2. Confirm that your setup matches the circuit diagram in Figure 4-2, and upload the code in “The Sketch” on page 38.

    FIGURE 4-2: The circuit diagram for the scrolling LED marquee

    Image

THE SKETCH

This sketch works by calling on the MaxMatrix library to control the matrix module. We then define the characters to display, and set the Arduino pins that control the matrix. Your message will be displayed in a continuous loop on the LEDs.

#include <MaxMatrix.h> // Call on the MaxMatrix library

PROGMEM const unsigned char 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, //
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;   // Pin connected to DIN pin of MAXIM7219 module
  int load = 9;   // Pin connected to CS pin of MAXIM7219 module
  int clock = 10; // Pin connected to CLK pin of MAXIM7219 module

int maxInUse = 1; // Set the number of matrices you are using
  MaxMatrix m(data, load, clock, maxInUse); // Define the module
  byte buffer[10];

  // Set message to scroll on the screen
char string1[] = " Arduino Project Handbook . . . ";
  void setup() {
    m.init(); // Start module
    m.setIntensity(0);
    Serial.begin(9600); // Start serial communication
  }

  void loop() {
    byte c;
    while (Serial.available() > 0) {
      byte c = Serial.read();
      Serial.println(c, DEC);
      printCharWithShift(c, 100);
    }
    delay(100);
    m.shiftLeft(false, true);
    printStringWithShift(string1, 100);
  }

  // The remainder of this sketch moves the scrolling characters
  // depending on the number of matrices that are attached
  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);
    }
  }

  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++;
   }
}

You can change the message on the LED matrix by altering the text inside the quotation marks at . If you want to chain your matrices together, change the number at to the number you have (the maximum number of matrices you can chain together is seven).

TROUBLESHOOTING

Q. The matrix does not light up or the LED shows erratic symbols.

• If none of the LEDs light, make sure you have connected the matrix as shown in the circuit diagram in Figure 4-2; the pins must match exactly.

• Make sure that your Arduino is powered and the TX light is flashing. If not, recheck your batteries or power supply.

• Make sure the Maxim 7219 chip is securely inserted in the module.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.73.125