Problems with Dot-Matrix 5x7 scrolling

Hi,

I found a sourcecode for scrolling a 5x7 Matrix. It works perfectly but I want to use
a standard ASCII Font (5x7) instead of the “Patterns”. I am a newbie to C and Arduino so I have no idea
how to resolve that problem.
I want to give a string like
char text[] = { " Hello World!" }; which I can change during runtime.

Here is the working code with the patterns:

/*
* 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 <FrequencyTimer2.h>
 
#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);
}

Is it possible ´to do that?

uwne

Not sure what you are trying to do here.

A standard ASCII font is just 256 ‘patterns’ of bits. There are certainly better ways of organizing the data for access and storage, but in the end each ASCII character needs to have a pattern of lights displayed.

Ok, right now I need to put my message into

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

before the loop. All chars I use must be defined here also. Finally I want to just put a string "Hello world" inside the loop function without the need of do this in the way in the above code. So I can also could send a new string (over Rs232 for example) which will be displayed. I think you got the right words, I am searching for a better way of organizing the data for access and storage.

uwne

Look at this for some clues https://arduinoplusplus.wordpress.com/2016/11/08/parola-fonts-a-to-z-defining-fonts/

Thank you, that looks good, but I will not use a Max72xx, I just use a Mega168. I will see if it could help me for a better understanding.

uwne: I will not use a Max72xx, I just use a Mega168.

A mega168 cannot drive a matrix by itself. Unless the matrix is very dim. Or you replace the chip every few hours when it burns out. Or use extra components. So how do you plan to drive the matrix?

Thank you, that looks good, but I will not use a Max72xx, I just use a Mega168.

The point of your question is not what you are using but how do you define a font in a sensible way.

marco_c: The point of your question is not what you are using but how do you define a font in a sensible way.

Yes you´re right, I will try to do it with those informations.

PaulRB: A mega168 cannot drive a matrix by itself. Unless the matrix is very dim. Or you replace the chip every few hours when it burns out. Or use extra components. So how do you plan to drive the matrix?

Of course it can drive a matrix by itself (since the last 5 years nothing burned ;-) ). I only have 1 pcs. of 5x7, so that works perfectly and without a problem ob brightness. I use this for a couple of years but without scrolling text. Also with a scrolling text there is no problem. I drive the matrix with transistors on the columns. The hardware is not really the problem (I am an electronic engineer).

PaulRB:
Or use extra components.

uwne:
I drive the matrix with transistors on the columns.

Thankyou for answering my question. We get newbies here every day who think they can drive matrices with bare MCU pins because they have not bothered to learn about current limits.

So you found a code that does what you want it to do but you don’t like the way the code looks so you want to do something different but you don’t know how to do it differently even though the way it was already done is the way to do it but even though you don’t know why it’s the way to do it you just simply imagine there being another way that would be more understandable to you instead of bothering to understand how the code you copied works.

Well, if you’re trying to simplify the input part of the code where you define your message since the working code looks too complex for you, you would have to make it even more complex, so I don’t see the point. Please elaborate on your aversion to ‘patterns’ when that’s how characters are defined on dot matrices regardless of how cumbersome they look to someone who doesn’t understand what they’re doing.

Ok maybe I did not get the right words. Of course I like the code I posted because it does what I want it to do, but not "exactly" the way I want it to do so I want to change it. I also know how characters are definied, I did myself a lot of them but not in C, only in Basic.I am totally new in C and also to Arduino.

For my understanding the code is not too complex, I understand the way it works with the patterns and it is also much easy to create own patterns in a simple an easy way. But I am not able to change those patterns during the runtime in the "loop" beacause of missing knowledge. I am sorry if my english is not so well (I am from germany) and some problems are difficult to explain. So for my side I respect everyone who share code and knowledge, no matter if I understand that or not. I will read the infos which marco_s posted.

What do you mean change patterns? Are you just trying to write new messages, so really just reorganizing the order that the predefined 'patterns' are called on, so not really changing what you call patterns? Cause i might sound like all you want to do is make another array with those patterns (which are arrays). Then it's really just a matter of tying in functions with whatever behavior you want.

The case I want to do is:

I want to change the string which is scrolled over the matrix inside the loop(). Right now I have to set the scrolling string outside the loop with

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

I want to have it that way inside the loop().

char text[] = { " Hello World" };

In the far future I want to send a string over serial interface which can scroll over the matrix. With the given code I need to know the scrolling text and the lenght of the text before compiling.

Right, so you're not making new patterns. You're just handling what order the blocks get called. I don't see the problem. Maybe you should look into using ledcontrol or the parola libraries, that level of simple function layout may make more sense for you to handle. They are straightforward for that far future goal of yours.

Thanks INTP, I will check that out.