Pages: [1] 2   Go Down
Author Topic: help with maxmatrix library, 8x64 matrix max7219.  (Read 2353 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi, im really new to arduino programing.
i try to make a 8x64 scrolling text using led matrix using max7219. The displayed text  will be send via serial from php. and as the server i'm using raspberry. i have done the php and the raspberry pi configuration. and   able to send the serial data. but at arduino side, i'm really clueless about the programing. i'm using maxmatrix library,

this is the sketch look like :

Code:
#include <MaxMatrix.h>
#include <avr/pgmspace.h>

PROGMEM prog_uchar 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, // \ backslash
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 = 11;
int load = 12; 
int clock = 13;

int maxInUse = 4; 
MaxMatrix m(data, load, clock, maxInUse);
byte buffer[10];

char string1[32] = "test 1234567890  ";

void setup(){
  m.init();
  m.setIntensity(8);
  Serial.begin(9600);
}

void loop(){ 
  while (Serial.available()>0){
  char string[32] = {Serial.read()};
  printStringWithShift(string, 100); 
  }
}

void printCharWithShift(char c, int shift_speed){
  if (c < 32) return;
  c -= 32;
  memcpy_P(buffer, CH + 7*c, 7);
  m.writeSprite(32, 0, buffer);
  m.setColumn(32 + 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++;
  }
}

using the sketh above, the data would shitft to left, without scrolling. if i put "char string[32] = {Serial.read()};" outside the void loop, the led matrix will not displayed any text that i sent.

if i use the data from the skecth "string1". the message would scroll nicely.
Code:
void loop(){ 
  while (Serial.available()>0){
   printStringWithShift(string1, 100); 
  }
}
but the serial.data wont be display at all coz i know there is no serial.read. it just confuse me, why if the data from serial.read, it will result a very different result.

so i would really apreciate if someone could help me on this, i have working on this for about 2 month, i made by my self the 8x8 led matrix .  now i have finish the led wiring , configuring php and raspberry pi, but i'm stuck with arduino coding.  So please i really need help here.
Logged

Offline Offline
Sr. Member
****
Karma: 12
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, I don't understand your problem.

You said
Quote
using the sketch above, the data would shitft to left, without scrolling.

I do not understand what this means. Characters shifting to the left is scrolling. Could you please explain more fully what is actually happening that is not correct, and what you want it to do.

Quote
if i put "char string[32] = {Serial.read()};" outside the void loop, the led matrix will not displayed any text that i sent.

That would be correct. The loop is the part in the arduino code that is called continuously. If you put the serial read outside the loop, it would only get called once at startup and never again, so while you were typing, it would not be reading the serial port. You must have the serial read somewhere inside your loop.
Logged

Do not IM me. I will not respond. Ask questions in the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i'm sorry for my bad english. i mean using the first sketch, the text will display moving to the left, but when the last character reach most left coloumn it will stop, no looping of shifting.

thank you.
Logged

Offline Offline
Sr. Member
****
Karma: 12
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If I understand correctly, I think I know what is happening.

When you use:

Code:
char string1[32] = "test 1234567890  ";

void loop(){  
  while (Serial.available()>0){
   printStringWithShift(string1, 100);  
  }
}

Any character entered on the serial port will cause the "test" string to scroll once. We then look for another character, and scroll the entire text string again (the while loop causes this).

In the case of

Code:
void loop(){  
  while (Serial.available()>0){
    char string[32] = {Serial.read()};
    printStringWithShift(string, 100);  
  }
}

At the end of the print/move left, we loop in the while loop and start with an empty buffer, looking only for new characters from the serial port.

I suggest you put in some Serial.print() statements so you can debug your code.

I'm not sure exactly what you want to do, but you may have to do something more like:

Code:
char string[32];

void loop(){  
   if (Serial.available()>0){
      memset(string,0,sizeof(string));
      string = Serial.read();
   }

   if (string) {
      printStringWithShift(string, 100);
   }
}

This will scroll whatever string we have each time we enter the loop().
« Last Edit: October 24, 2013, 12:53:59 pm by arduinodlb » Logged

Do not IM me. I will not respond. Ask questions in the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi, thank you for your sugestion. i'll give a try.
i change the part

Code:
void loop(){  
  while (Serial.available()>0){
   printStringWithShift(string1, 100);  
  }
}

to this.
Code:
void loop(){  
char string[32] ={Serial.read()};
 printStringWithShift(string, 100);  
}

the result it the text is still displayed with shifting, but unable to scroling/ do looping. can anybody explain to me why i can't use serial data to make the text scolling? it will only shifting and when it reach the last character, the movement will stop.
but if use the data from char string , to like this :

to this.
Code:
char string1 [32]=" test 1234567890";
]void loop(){  
 printStringWithShift(string1, 100);  
}
then the text of string1 will result a scrolling text, it not stop when the text rach the last character.

thank you.
regards, riko.
« Last Edit: October 25, 2013, 03:43:30 am by rikok30 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Code:
char string[32];

void loop(){  
   if (Serial.available()>0){
      memset(string,0,sizeof(string));
      string = Serial.read();
   }

   if (string) {
      printStringWithShift(string, 100);
   }
}

This will scroll whatever string we have each time we enter the loop().

hi , thank for your help. but it seem using this way, i'm not able to get the data form serial, but yes it will scroll when i used data from "char string1[32]="test 1234567890". and it will scroll even when i dont send any serial to arduino.

please , i need your sugestion mate. thank you
Logged

Offline Offline
Sr. Member
****
Karma: 12
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this statement

Quote
the result it the text is still displayed with shifting, but unable to scroling/ do looping. can anybody explain to me why i can't use serial data to make the text scolling? it will only shifting and when it reach the last character, the movement will stop.
but if use the data from char string

is not correct. You are misunderstanding the symptom.

The scrolling is working fine for both string and string1. The problem is getting characters into string from the serial port. If you print the variable string out of the serial port for debugging you will understand the problem better.

Your "printStringWithShift" function finishes with the string to the left, and is a long delay (a few seconds probably) where nothing else can happen. Also, when you read in serial characters, the way it is written, it overwrites any previous serial characters, instead of appending them. This is probably not what you want to do.

I don't really understand what you are trying to do, but I think your concept has problems at the moment. Maybe you want to do something like this (untested)

Code:
char string[32];
int hasReturn = 0;

void loop(){ 
   if (Serial.available()>0){
      if (hasReturn) {
        // we're starting a new serial transmission. Clear out the old one.
        memset(string,0,sizeof(string));
        hasReturn = 0;
      }

      // add any new characters
      strcat(string, Serial.read());

      // look for a carriage return and if found, mark this as a completed string
      if (string && (string[strlen(string) - 1] == 0x0D)) {
          hasReturn = 1;
      }
   }

   // if we have a complete string, scroll it out until someone changes it
   if (string && hasReturn) {
      printStringWithShift(string, 100);
   }
}

As I say, print the string variable out the serial port so you more fully understand what is happening and hopefully that will help you in the right direction.

« Last Edit: October 25, 2013, 12:30:53 pm by arduinodlb » Logged

Do not IM me. I will not respond. Ask questions in the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi, this is what the serial monitor output like.

using the the sketch that you given


using this sketch :
Code:
void loop() {
  if (Serial.available()>0){
 char string[32] ={Serial.read()};
 printStringWithShift(string, 100);
Serial.println (string);  }}

the result is


i change the void loop to this :
Code:
void loop() {
 char string[32] ={Serial.read()};
 printStringWithShift(string, 100);
Serial.println (string);  }

and the serial monitor output is :


and this the working sketch, it will shift over and over (scrolling text)
Code:
string1[32]="Test 1234567890";
void loop() {
 printStringWithShift(string1, 100);
Serial.println (string1);  }

the serial monitor will output something like this.


it write to output after the text finish the shifting to most left colom.

the other three sketch, it shifting to, but after it reach the last character, it will stop. same thing happen using your sketch.

so what should i do to make serial data to be output like 4th sketch. it will output the text as one line after the looping done, and repeat the looping again. what methode should i use to store the serial data,
Logged

Offline Offline
Sr. Member
****
Karma: 12
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As I say, I don't understand what you are trying to do.

The last code I sent you was designed to scroll the text only after you send a Carriage Return/Enter character on the serial port. The idea would be you type some text you want displayed, then hit enter. I don't think you tried that code and sent a carriage return. For example, "testing<CR>" where <CR> is the carriage return/enter key.

You are still misunderstanding the symptom. When you say "when it gets to the left, it stops", what is actually happening is it returns from the call to printStringWithShift, then re-enters the loop() function. At this point, string reads the serial port again, and if there are no characters, the new "string" variable is empty. In other words, you keep emptying the string variable. It's not that the print is not looping, it's that your code keeps clearing out the string variable. That is why it works with string1. String 1 never changes, so the printing works with every loop. In the case of string, it gets cleared every time you come into loop. That's the difference.

However, because the print takes so long, I don't know that you want to just read the serial port in again after the shift has finished. That's why I added the "wait for the enter character before displaying the string". But, maybe that's not what you want to do. I'm not sure.

maybe

Code:
char string[32] ;

void loop() {
   if (Serial.available()>0){
      // add any new characters
      strcat(string, Serial.read());
   }

  if (string) {
    Serial.println (string);  // what we are about to shift through the LCD screen
    printStringWithShift(string, 100);
  }
}

But, if you do that, I don't know how you're going to clear the string. Maybe a special character?
« Last Edit: October 26, 2013, 05:06:32 am by arduinodlb » Logged

Do not IM me. I will not respond. Ask questions in the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what i want to do is to make a 8x64 scrolling led matrix using max7219. the text that i want to display is came from serial data.
ah ic, so that is why the if i use data from serial the looping is stop, coz there is no data to read after the last character.
so how could i store the serial data so the printstringwithshift would read it as a static data?

thank you for your help friend. i'm really new with arduino.
Logged

Offline Offline
Sr. Member
****
Karma: 12
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK. I think you understand the problem now.

So, you need to decide how you want it to work.

Let's assume for now that it takes 5 seconds to scroll the text once. During that 5 seconds, you cannot read the serial port, and the text will not change. At the end of that 5 seconds, we come back into the loop to read more characters.

1. Do you want it to replace the existing characters, or do you want it to add the new characters to the end of the existing text?
2. If you decide that you want it to just add the characters to the end, the last code I posted will do that, and keep looping the string since the string is stored. But, you will then need to work out how you want to clear the string and start again.
3. If you decide you only want to display the string each time a line is complete, the previous code I wrote will do that. WIth that code, the string is stored and looped. When a new character is entered, the looping stops and the core waits for the next "enter" key. It then displays and loops the new text.
Logged

Do not IM me. I will not respond. Ask questions in the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi, now i'm able to loop the text from serial using the last sketch. here is what the serial monitor output.


the problem is, that it will displayed the text one by one until it reach the full text  and keep looping.
it display t->te->tes-test->test->test ->test 1->test 12->test 123->test 1234->test 1234-> and so on.

how can i display the whole text, without need to loop it one by one first. what method should i use to wait until the serial finish send the data, and strcat the full data/text, so it would display the whole text at time.

i'm sorry if my english is hard to understand. thank you.
Logged

Offline Offline
Sr. Member
****
Karma: 12
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good. We're getting closer.

The big question is: how is the Arduino supposed to know you have finished sending characters on the serial port?

There are really only two answers to this:
1) Use a special character to indicate the end of the text message. Normally, you would use the enter character for this (ASCII character 0x0D).
2) If a character is not sent for some predefined time. For example, 3 seconds. The problem with this approach is that when you finish sending text, the scrolling won't start for that same 3 seconds.

You must choose one of these approaches. If you choose the first, my previous code should work (the one with the 0x0D check). If you choose the second, more work is required.
Logged

Do not IM me. I will not respond. Ask questions in the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi, the first method is what i want it to be. but using the sketch with hasReturn, doesnt give me anything at the output printwithShift function, i put serial.println  under strcat command, the ouput is



about how to change the displayed text, when using php, everytime it send new serial,look like  the connection was reset, and then create new connection and send new data to arduino. coz i can see something has interupt the connection looking how the led matrix blinking when i run the php script to send new data (same thing happen when i close or open serial monitor), and it will clear the matrix from old text. then display new text from php or serial monitor.

using strcat, look like it been that close to what i want to achive. assuming my text is "test 1234", i need it to display the complete text without need to loop it one by one first.

thank you friend.
Logged

Offline Offline
Sr. Member
****
Karma: 12
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, but how does the Arduino know if you're going to type "test1234" or "test123456789"? How does it know when it can start printing the text on your LCD?

Normally, this is done by sending "test1234" followed by the carriage return character (ASCII 0x0D). Do you know what I mean by the carriage return character? That is very important. It's like "test1234\r" in the C++ language. You could even use "test1234\n" if you wanted and test for the ASCII Newline character (0x0A). Do you know what I mean here? It's like hitting "Enter" on your keyboard. It tells the computer that that is the end of the text line.

Try this: Use my earlier code which has the "0x0D" things in it. In the serial port connection, type the letters "test1234" and hit enter. Don't use your PHP code. Just use a serial port and a communications program, and type the characters in by hand. When you hit "enter", the text should start to scroll. Then when you start typing a new line on your serial port, the text will stop until you hit enter again. Hopefully doing that will help you understand what you need to do.

Or possibly use my "0x0D" code and change your PHP code so that instead of just outputting "test1234" it outputs "test1234\r" (where \r is the C/C++/PHP escape sequence for the ASCII character 0x0D)
« Last Edit: October 27, 2013, 06:47:22 am by arduinodlb » Logged

Do not IM me. I will not respond. Ask questions in the forum.

Pages: [1] 2   Go Up
Jump to: