Home Of MetaWops.

OS X. iOS. Gadgets. Social Media. Basketball. Music. Synths. Electronics.

Arduino

Arduino scrolling text on 5×7 LED

ArduinoLED5x7Some folks saw my little Arduino experiment with a 5×7 dot matrix LED brick with scrolling text here on YouTube and asked for the source code. Well, here it is. Enjoy. 🙂

In case of any questions: ask in the comments. Quick hint for the wiring: pin 1 of the 5×7 LED block goes to Arduino’s I/O port #2. Pin 2 to Arduino’s #9, pin 3 to Arduino’s #3 and so forth, according to the array pins[] (see source code). Get the FrequencyTimer2 library here.

/*
* Source: http://www.arduino.cc/playground/Main/DirectDriveLEDMatrix
*
* Modifications for 5x7 LED Matrix element
* by Stefan Wolfrum in July 2012.
* ----------------------------------------
*
* Show messages on an 5x7 led matrix,
* scrolling from right to left.
*
* Uses FrequencyTimer2 library to
* constantly run an interrupt routine
* at a specified frequency. This
* refreshes the display without the
* main loop having to do anything.
*
*/

#include

#define SPACE { \
{0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0} \
}

#define H { \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 1, 1, 1, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1} \
}

#define E { \
{1, 1, 1, 1, 1}, \
{1, 0, 0, 0, 0}, \
{1, 0, 0, 0, 0}, \
{1, 1, 1, 1, 0}, \
{1, 0, 0, 0, 0}, \
{1, 0, 0, 0, 0}, \
{1, 1, 1, 1, 1} \
}

#define small_E { \
{0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 0}, \
{1, 0, 0, 0, 1}, \
{1, 1, 1, 1, 0}, \
{1, 0, 0, 0, 0}, \
{0, 1, 1, 1, 0} \
}

#define L { \
{1, 0, 0, 0, 0}, \
{1, 0, 0, 0, 0}, \
{1, 0, 0, 0, 0}, \
{1, 0, 0, 0, 0}, \
{1, 0, 0, 0, 0}, \
{1, 0, 0, 0, 0}, \
{1, 1, 1, 1, 1} \
}

#define small_L { \
{0, 1, 1, 0, 0}, \
{0, 0, 1, 0, 0}, \
{0, 0, 1, 0, 0}, \
{0, 0, 1, 0, 0}, \
{0, 0, 1, 0, 0}, \
{0, 0, 1, 0, 0}, \
{0, 1, 1, 1, 0} \
}

#define O { \
{0, 1, 1, 1, 0}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{0, 1, 1, 1, 0} \
}

#define small_O { \
{0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 0}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{0, 1, 1, 1, 0} \
}

#define small_W { \
{0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 1, 0, 1}, \
{1, 0, 1, 0, 1}, \
{0, 1, 0, 1, 0} \
}

#define small_R { \
{0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0}, \
{0, 1, 0, 1, 1}, \
{0, 1, 1, 0, 0}, \
{0, 1, 0, 0, 0}, \
{0, 1, 0, 0, 0}, \
{0, 1, 0, 0, 0} \
}

#define small_D { \
{0, 0, 0, 0, 1}, \
{0, 0, 0, 0, 1}, \
{0, 1, 1, 0, 1}, \
{1, 0, 0, 1, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{0, 1, 1, 1, 1} \
}
byte col = 0;
byte leds[5][7]; // columns x rows

// pin[xx] on led matrix connected to nn on Arduino
// (-1 is dummy to make array start at pos 1)
int pins[13]= {-1, 2, 9, 3, 11, 12, 13, 5, 6, 10, 4, 8, 7};

// col[xx] of leds = pin yy on led matrix
int cols[5] = {pins[1], pins[3], pins[10], pins[7], pins[8]};

// row[xx] of leds = pin yy on led matrix
int rows[7] = {pins[12], pins[11], pins[2], pins[9],
 pins[4], pins[5], pins[6]};

const int numPatterns = 12;
byte patterns[numPatterns][7][5] = {
 SPACE, H, small_E, small_L, small_L, small_O,
 SPACE, small_W, small_O, small_R, small_L, small_D
};

int pattern = 0;

void setup()
{
  // sets the pins as output
  for (int i = 1; i <= 12; i++) {
    pinMode(pins[i], OUTPUT);
  }

  // set up cols and rows
  for (int i = 1; i <= 5; i++) {
    digitalWrite(cols[i - 1], LOW);
  }

  for (int i = 1; i <= 7; i++) {
    digitalWrite(rows[i - 1], LOW);
  }

  clearLeds();

  // Turn off toggling of pin 11
  FrequencyTimer2::disable();
  // Set refresh rate (interrupt timeout period)
  FrequencyTimer2::setPeriod(2000);
  // Set interrupt routine to be called
  FrequencyTimer2::setOnOverflow(display);

  setPattern(pattern);
}

void loop()
{
  pattern = ++pattern % numPatterns;
  slidePattern(pattern, 100);
}

void clearLeds()
{
  // Clear display array
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 7; j++) {
      leds[i][j] = 0;
    }
  }
}

void setPattern(int pattern)
{
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 7; j++) {
      leds[i][j] = patterns[pattern][j][i];
    }
  }
}

void slidePattern(int pattern, int del)
{
  for (int newcol = 0; newcol <= 4; newcol++) {

    // shift the first 4 columns left
    for (int row = 0; row <= 6; row++)
      for (int col = 0; col <= 3; col++)
        leds[col][row] = leds[col+1][row];

    // fill the last (5th) column with the
    // 1st (2nd, 3rd, ...) column of the new pattern
    for (int row = 0; row <= 6; row++)
      leds[4][row] = patterns[pattern][row][newcol];

    delay(del);
  }
}

// Interrupt routine
void display()
{
  // Turn whole previous column off:
  digitalWrite(cols[col], LOW);
  col++;
  if (col == 5) {
    col = 0;
  }
  for (int row = 0; row < 7; row++) {
    if (leds[col][row] == 1) {
      digitalWrite(rows[row], LOW); // Turn on this led
    }
    else {
      digitalWrite(rows[row], HIGH); // Turn off this led
    }
  }
  // Turn whole column on at once (for equal lighting times):
  digitalWrite(cols[col], HIGH);
}

  1. Chris

    I wanted to do this project but you didn’t include any wiring diagrams.
    Perhaps you could provide a wiring diagram to make this a little more helpful to beginners.

  2. Oh, and one thing I noticed today when I wanted to run this sketch on my Arduino Leonardo: the FrequencyTimer2 library doesn’t seem to be compatible with the Leonardo, unfortunately. Because I get the error message „This board does not have a hardware timer which is compatible with FrequencyTimer2“ when trying to upload the sketch to the Leonardo. I asked about that here at the official Arduino forum, maybe you want to follow (or even answer!) that: http://arduino.cc/forum/index.php/topic,152635.0.html

  3. Noy

    what kind of arduino did you use to this project?

    • You didn’t check the YouTube video link I posted in the article, right? There you can easily see that it’s an Arduino Uno. 😉

  4. Jose Alvarado

    Hey Stefan, I think your idea is fantastic and it seems very useful but I just seem to be having some problems with the code when I try to upload it or verify it on my arduino IDE.

    • Hello Jose and thanks for your nice comment. What kind of problems do you run into? Do you get any error message you could share?

      • Jose Alvarado

        Hey Stefan, thanks for replying! I figured what my problem was and now I am already working on this exciting code of yours. I was just wondering, on your Fritzing model, I just have trouble figuring out which pin is which. Thank you!

  5. Jose Alvarado

    Also, when i try to upload the code it says this: avrdude: stk500_getsync(): not in sync: resp=0x30

  6. Kai

    Hey Stefan,
    Can you name the LED-Matrix you are using in your tutorial?
    As I can See in your frizing-sketch you have a 12-pin LED-Matrix.
    Thank you!

  7. Kai

    Hi again,

    while watching your video I came up with another question:
    Why don’t you use series resistors to limit the current for the LED-Matrix. Is that because of the low current of the Arduino or are there any other explanations?
    Thank you!

  8. carlos lopez

    hey can you help me i’m using a gmm-12057ASB 5×7 matrix

  9. carlos lopez

    in this part what are these the pins in the matrix or in the arduino???
    // pin[xx] on led matrix connected to nn on Arduino
    // (-1 is dummy to make array start at pos 1)
    int pins[13]= {-1, 2, 9, 3, 11, 12, 13, 5, 6, 10, 4, 8, 7};

  10. carlos lopez

    hey when i compile i got the error frequencytimer2 has not been declared

  11. Biju

    Hello stefan
    Nice project with 5×7 matrix . i did it with uno and is working fine. i used LTP2057A matrix display. Thanks for posting .

  12. Kaustubh Mhatre

    I want to interface 2 5×7 Led Displays What should i change in the code and the hardware can you explain in .

  13. Ace

    Hey it says error compiling. I don’t know what went wrong. Could you help me?

  14. Ishan Dave

    Where Can I get Library of all characters(A-Z) for 5×7 LED matrix ?I want to display messages coming from the gsm module.
    Please Reply
    Thank You

  15. Eduardo

    Very old but also very good thread! I tried it and it works perfect. Is it also possible to scroll vom down to up / up to down?
    Could someone show me how to do?

    Thanks,
    Eduardo

  16. carlos lopez hernandez

    Carlos Lopez H.
    Hi Stefan;
    I am from Mexico, congratulations for your great project. But I have a compiling
    problem, I am working with Arduino UNO,
    ATM328P, when I compiling it says me;
    uint8_t no name type. Please what can I do. Thanks a lot.

  17. bob

    Thank you for your project It help me much to understant the matrix
    But i think the code has an erroe
    If i run as is the columns are open all time. I must make the first line of code from LOW to HIGH to close the columns
    And after that i change all HIGH and LOW to the opossite value and work fine

    In function display the right code is

    // Interrupt routine
    void display()
    {
    // Turn whole previous column off:
    digitalWrite(cols[col], HIGH);
    col++;
    if (col == 5) {
    col = 0;
    }
    for (int row = 0; row < 7; row++) {
    if (leds[col][row] == 1) {
    digitalWrite(rows[row], HIGH); // Turn on this led
    }
    else {
    digitalWrite(rows[row], LOW); // Turn off this led
    }
    }
    // Turn whole column on at once (for equal lighting times):
    digitalWrite(cols[col], LOW);
    }

  18. Almir Bajsini

    I made my own led dot matrix and i put anode to have 5 pins and katode to have 7 can it still work somehow or do i need to change it.
    Thank you.

  19. Jeroen

    I’ve built this with a HDSP-5401 display and went a little step further.
    I’ve inserted the full alphabet with upper- and lowercase and numbers 0-9

    I’ve also altered the sketch to have 1 column of blank spacing between the printed characters, which makes it look better.
    I’ve also altered the scroll speed a little.

    With my sketch, you can display a line of 46 characters in total before the ram is fully filled up.

    Look at the results here:
    https://youtu.be/L7gDi6hj7jw

Schreibe eine Antwort

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darĂŒber, wie deine Kommentardaten verarbeitet werden.

Theme von Anders Norén

%d Bloggern gefÀllt das: