Sketch examples of scrolling text on 8x8 LED matrix w/ MAX72xx

Does anyone have a link to simple code examples (been googling for 2 days with no success) of getting text to scroll on 2 or more 8x8 LED matrices via MAX7219 chip (i.e using LEDControl library). I went thru all the basic tutorials on MAX72xx and LEDControl, and successfully got 2 of the matrices working, just not sure how to do the animation code... :cold_sweat:

Hi Brattan,

I just realised that these two code examples do not use Ledcontrol library so when I get home from work I will see what else I have found online and post the link or code for them. But in the meantime -

Scrolltest2 .ino, by Riva on this forum, is attached to the fourth post in this thread Max72XX scrolling text code - #12 by Pedro147 - LEDs and Multiplexing - Arduino Forum

And Nick Gammon also on this forum has this excellent code using –

Pedro. 8)

Brattan,

Here are two codes that use the Ledcontrol library for Max7219.

This code by JoeN on this forum. It is attached to the sixth post of this thread http://arduino.cc/forum/index.php/topic,115559.0.html. It is a .ino.txt file for some reason, so I just renamed it as a .ino and opened it with Arduino IDE.

Also this code by John Boxall on the Tronixstuff site

http://tronixstuff.wordpress.com/2010/07/09/review-maxim-max7219-led-display-driver-ic/

Have fun with them,Pedro 8)

just not sure how to do the animation code

Create a buffer (8-byte) to store the bitmap, and once you have written to that bit map, you can write it to the display chip.

Pedro, thank you SOOOOOOOOOOOOOOOOOOOOOOOOO much!!!!! This is just what I was looking for, I don't know how I missed that thread (115559), it's basically what I'm trying to do, it's perfect! :slight_smile:
I'm digging into the code now, can't wait to go home and try it out!!! :smiley:

dhenry, that's a good tip. I wanted even more basic information tho, how actual scrolling would work? I thought about it and it seems that I need to shift each column of bits to the side. So if top of the letter A is "00111100", I'll need to make it into "01111000", and then "11110000". Then it will start to wrap around " "01110001". So how would I do this "byte shifting" programatically with for loops, etc.? At this point I have no idea, but hopefully I can figure out it from the examples that Pedro showed me.

how actual scrolling would work?

It depends on your arrangement, but the general concept is the same.

Say that your image is arranged in columns. So display_buffer[0] contains the left most column, and display_buffer[7] contains the right most column. In each column, bit 0 is the top dot and bit 7 is the bottom dot.

//left shift image by 1 column
//colomn 0 -> colomn 7
//column 1 -> column 0
//..
//column 7 -> column 6
void shift_left(unsigned char * buffer) {
  unsigned char i;
  unsigned char tmp = buffer[0]; //save the left most column

  for (i=0; i<7; i++) buffer[i] = buffer[i+1];
  buffer[7]=tmp;
}

//shift column right
void shift_right(unsigned char * buffer) {
  //similarly
}

//shift rows up
//bit 0 -> bit 1
//bit 1 -> bit 2
//..
//bit 7 -> bit 0
void shift_up(unsigned char * buffer) {
  unsigned char i;

  for (i=0; i<8; i++) buffer[i]=(buffer[i]<<1) | ((buffer[i]&0x80)?0x01:0x00);
}

//shift rows down
void shift_down(unsigned char * buffer) {
  //similarly to shift_up()
}

From there, you can write combination shifts: up + right, down + left, etc.

Excuse me Mr dhenry 8), I am also trying to learn the basic concepts of scrolling characters etc on Arduino and although there is a lot of information around I am still finding it a "hard road" as there is a lot of jargon involved… it's like trying to join a secret society of ninja warriors. So am I correct in assuming that a buffer is an array containing columns of zero's and one's which form the character or symbol you wish to display and scroll. Do you then maybe use a for loop to move through this buffer array? There seem to be numerous methods of scrolling but for someone trying to learn from basic principles upwards, it's a battle. Any help would be appreciated as there does not seem to be any tutorials available anywhere.

Thank you for your time Pedro.

So am I correct in assuming that a buffer is an array containing columns of zero's and one's which form the character or symbol you wish to display and scroll. Do you then maybe use a for loop to move through this buffer array?

There are two basic types of displays:

  1. write-only displays: they are either dumb (controller-less. as segment lcd / led), or they cannot be read back (many low-end graphics leds are like that). For those displays, you can either write-over what's on the screen, or keep a copy of the screen in your memory and process it before sending the data over to the screen. If you need anything fancier, you need to keep a local copy of the screen. Thus a buffer.
  2. read/writable displays: you don't have to keep a local copy of the screen, as you can always read it back from the screen. However, that reading back / forth can take more time so for speed reasons, you may see people using buffers as well.

Buffers are nothing but a dedicated area in the mcu's ram that keeps track of what's being displayed. Each dot is represented by a bit (in an on/off only screen), or a gray / color scale.

In the case of MAx72xx, since you need to scroll the image, you have to have a buffer.

Once you have a buffer, you can process every bit / led based on your desired actions. The code I provided earlier shows some of the more generic ways for you to do that. You can actually speed it up significantly if you use memory copy. It serves as a starting point.

Thanks for that concise explanation. If I may ask, how did you / and guys/girls on this forum learn about coding to scroll etc. I try to look at different examples and work out how they are doing it but good information on the subject is hard to find. I know that quite a few of you have a solid background in computing but for me its only what I can find online and from help by the generosity of people on this forum. Thanks again for your help

Pedro.

Emdedded programming is hard as it combines both software and hardware, analog and digital.

In this case, you will need to figure out how the hardware is arranged: whether the image is row based or column based, etc. Once you have that set, all you need to do is to figure out how to move the image to get your desired effect and how to code to move that image.

What I found important is to be able to modulize your tasks and figure out a way to easily integrate them back into a workable project. Many of the code pieces out there have all the tasks co-mingled and that makes them useless for your project.

Once you have modulized your code, you can use them in future projects, speeding up the development cycle.

So the more you code, the less you code (incrementally).

Thanks so much for that simple statement "embedded programming" It is the first time during all my internet research into learning to code (specifically Arduino scrolling text) that it has been given a name pointing me to an specific sub genre of programming. All I seem to have read is how easy it all is and it is starting to give me a complex thinking that "I am a bit slow on the uptake" :blush: After googling enbedded prog I am at least finding specific information so thanks again Pedro.

I've made some progress. Example program "LCDemoMatrix" that came with LedControl library had a very clear structure so I can understand it easy (not so much luck with other examples). I realized that characters were stored "sideways" i.e. letter "A" is defined as:

byte a[8]={B00000000,B01111111,B10001000,B10001000,B10001000,B10001000,B01111111,B00000000};

Well I made it bigger and 8x8. So it's very easy to scroll by just moving starting row. So as dhenry mentioned it depends how your text stored (column vs. row) and I think how your LED matrix arranged physically (at which side they touch). So I think in the LedControl they use column-wise text, and other examples on this forum used "row-wise" fonts.
Anyway, I had to do this from scratch so I came up with this way to scroll it on a single matrix:

void text_scroll(int screen){
  
  // Define "A" Character columnwise orientation
  byte a[8]={B00000000,B01111111,B10001000,B10001000,B10001000,B10001000,B01111111,B00000000};
  
  for(int j=pos;j<8;j++){ // This first for loop will shift position of the row
     for(int i=0;i<8;i++) { // This second loop will display character
        lc.setRow(screen,i+j,a[i]); // Display character
    }
    delay(100); // speed of animation
    } 
    pos = -8; // From this point character will advance from "beyond" screen
}

"pos" variable is initially set to 0, so character will start from the middle of the matrix, but then it will always "flow" from the side. Screen specifies which matrix device to address. Don't forget you need to initialize and define them in the beginning (see orignal LCDemoMatrix example).
I'm not quite sure why it works, and how library handles negative rows, but it works :slight_smile:
Of course this is very rough code, and animation doesn't wrap around or continues smoothly to the next screen, but I think I can figure it out. Oh and I didn't use buffer at all yet....
I'll keep this thread updated if anyone find it interesting.

You do have a buffer, in a[].

My approach is to maintain the buffer and always starts at column 0 and finish at column 7 of that buffer. Your approach is is to start with a column, and then wrap around back to it.

My approach involves a lot of data moving around, but is otherwise more flexible - coding a combination move is fairly easy. Your approach involves no data movement, but can be tough to code complex movements.

As to how your code work, think of it having two pieces:

  1. Remember the start column in your image buffer (a[] in this case), in col_start;
  2. for each frame, display columns from col_start to 7; and then display columns from 0 to col_start - 1;
  3. advance col_start.

dhenry:
You do have a buffer, in a[].

Ah I see, I was thinking of it as a font, i.e. something that's constant.

Anyway, I made a lot of progress, now my letter is scrolling seamlessly between 2 LED matrices and even wraps around! :smiley: I think I can adapt it to any number of LED matrices in the chain...

void letter_scroll(){
  // Define "A" Character columnwise orientation
  byte a[8]={B00000000,B01111111,B10001000,B10001000,B10001000,B10001000,B01111111,B00000000};
  int matrix_rows=8; // Specify number of LEDs in a row of the matrix 
  int screen_res=lc.getDeviceCount()*matrix_rows; // Define Screen resolution (lengh) by getting number of devices connected and rows in each matrix (i.e. 2x8=16)
  int row=0; // Var will only be used on first screen to do wrap around function
  for(int j=0;j<screen_res;j++){ // This will shift position of the row creating movement
     for(int i=0;i<8;i++) { // Render Character on Screen 1
       if (j>8){ //we beyond first screen
          if (j>matrix_rows){ // Time to wrap around
            row=j-screen_res; // Modify start position so it goesn't go beyond screen
            lc.setRow(0,i+row,a[i]); // Render Letter
          }
        }
        else{ // We are on the 1st screen
             lc.setRow(0,i+j,a[i]); // Render Letter
         }
     }
     for(int i=0;i<8;i++) { // Render Character on second screen
        if (j>0){ // Are we scrolling off the prev. screen?
          lc.setRow(1,i+j-8,a[i]);  // Render Character on second screen
        }
     }
    delay(100); // speed of animation
    } 
}

LEDScrollTest1.ino (2.32 KB)

bratan:
I'll keep this thread updated if anyone find it interesting.

Hi Bratan,
thanks for sharing your progress, I for one would appreciate you sharing any and all of your forays into "Arduino Scroll World" 8) 8) Now I cannot wait to get home after work and look at your discoveries,

Pedro.

now my letter is scrolling seamlessly

The prior routine suffers from setRow() not wrapping around - if you see its source code, it simply returns when the "row" index is greater than 7 / less than 0. Makes sense for what it does but not for what you want to do.

Your code has two for loops and it can be time consuming. How about this:

  static unsigned char col_starting=0; //starting column
  spiTransfer(addr, 0, a[(col_starting + 0) & 0x07]);
  spiTransfer(addr, 1, a[(col_starting + 1) & 0x07]);
  spiTransfer(addr, 2, a[(col_starting + 2) & 0x07]);
  ...
  spiTransfer(addr, 7, a[(col_starting + 7) & 0x07]);
  col_starting = (col_starting==7)?0:(col_starting+1); //increment index

no loop but 8 transfers. you can modify it for your requirement.

dhenry:
Your code has two for loops and it can be time consuming. How about this:

  static unsigned char col_starting=0; //starting column

spiTransfer(addr, 0, a[(col_starting + 0) & 0x07]);
  spiTransfer(addr, 1, a[(col_starting + 1) & 0x07]);
  spiTransfer(addr, 2, a[(col_starting + 2) & 0x07]);
  ...
  spiTransfer(addr, 7, a[(col_starting + 7) & 0x07]);
  col_starting = (col_starting==7)?0:(col_starting+1); //increment index




no loop but 8 transfers. you can modify it for your requirement.

:astonished: Thanks! Honestly I don't really understand any of it (it's a little too advance for me at this stage), but I will try! :slight_smile: I need to read some more about SPI...

Pedro147:
Hi Brattan,

I just realised that these two code examples do not use Ledcontrol library so when I get home from work I will see what else I have found online and post the link or code for them. But in the meantime -

Scrolltest2 .ino, by Riva on this forum, is attached to the fourth post in this thread Max72XX scrolling text code - #12 by Pedro147 - LEDs and Multiplexing - Arduino Forum

The MAX7219 library I use in Scrolltest2.ino is just a subset of the LedControl library that I hacked to reduce size as original project ran on a ATmega8 and I was running out of space. If you replace the MAX7219 references with LedControl then it should still work okay.
#include <MAX7219.h> becomes
#include <LedControl.h>
and
MAX7219 lc=MAX7219(DIN,CLK,LOAD,numDevices); becomes
LedControl lc=LedControl (DIN,CLK,LOAD,numDevices);

EDIT: I have attached the latest test version of my scrolling code that does kerning that has been modified for the MAX7219 from the Rainbowduino it used to work on. It compiled okay but I don't have a matrix to test it on so beware. Maybe some kind soul will test it and confirm it works okay.

ScrollTest4MAX.ino (14.2 KB)

Riva:
It compiled okay but I don't have a matrix to test it on so beware. Maybe some kind soul will test it and confirm it works okay.[/color]

Thanks Riva, I will give it a try tonight! I soldered 2 matricies with MAX7219 chips and will see it runs on it.
I'm still trying to come up with my own code, but due to lack of programming knowledge, it's hard but fun :slight_smile: