Pages: [1] 2 3   Go Down
Author Topic: Sketch examples of scrolling text on 8x8 LED matrix w/ MAX72xx  (Read 14566 times)
0 Members and 1 Guest are viewing this topic.
New York
Offline Offline
Sr. Member
****
Karma: 4
Posts: 380
xronosclock.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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...  smiley-roll-sweat
Logged

Xronos Clock - A talking arduino based alarm clock is now available. Check out xronosclock.com for pictures, source code, schematics, and purchasing info smiley

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 http://arduino.cc/forum/index.php/topic,123787.msg939503.html#msg939503

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

http://www.gammon.com.au/forum/?id=11516

Pedro.   smiley-cool
 
Logged


Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-cool


« Last Edit: October 12, 2012, 04:30:54 am by Pedro147 » Logged


Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

New York
Offline Offline
Sr. Member
****
Karma: 4
Posts: 380
xronosclock.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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! smiley
I'm digging into the code now, can't wait to go home and try it out!!!  smiley-grin

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.
« Last Edit: October 12, 2012, 03:23:34 pm by bratan » Logged

Xronos Clock - A talking arduino based alarm clock is now available. Check out xronosclock.com for pictures, source code, schematics, and purchasing info smiley

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Code:
//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.

Logged

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Excuse me Mr dhenry  smiley-cool, 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.

Logged


Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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"   smiley-red After googling enbedded prog I am at least finding specific information so thanks again Pedro.
Logged


New York
Offline Offline
Sr. Member
****
Karma: 4
Posts: 380
xronosclock.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
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:
Code:
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 smiley
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.
Logged

Xronos Clock - A talking arduino based alarm clock is now available. Check out xronosclock.com for pictures, source code, schematics, and purchasing info smiley

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

New York
Offline Offline
Sr. Member
****
Karma: 4
Posts: 380
xronosclock.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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-grin  I think I can adapt it to any number of LED matrices in the chain...
Code:
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 - downloaded 83 times.)
Logged

Xronos Clock - A talking arduino based alarm clock is now available. Check out xronosclock.com for pictures, source code, schematics, and purchasing info smiley

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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"  smiley-cool  smiley-cool Now I cannot wait to get home after work and look at your discoveries,

Pedro.
Logged


Pages: [1] 2 3   Go Up
Jump to: