Go Down

Topic: Scrolling LCD logic with serial input (Read 437 times) previous topic - next topic

jointtech

I have a sketch that grabs a string of data from serial input.
Since im a lame noob I "tricked" the LCD and just added a bunch of spaces in the string to make it format nicely on the LCD in 2 lines.
Code: [Select]
$  Air Temp: 70F  CO2:450 Hum:50#

Well now I want to display the above on 2 lines and then scroll it offscreen to another similar string.
Adding some simple code like
Code: [Select]
  for (int x=0; x<31; x++) {
    led.scrollLeft();
    delay(500);
  }

or something to that effect.  ive only started playing with the LCD today.

But then I got to thinking.  Once ive scrolled to the next screen im not sure how or where to loop it so it keeps going between the pages.  The main issue is my checkserial function to parse the start and stop bits is what loops and then calls the LCD once at the end. Since I only call the UpdateLCD script ever few minutes the LCD would only display the loop once and then be stuck on whatever the last screen is for the next few minutes.

Code: [Select]
#include <SoftwareSerial.h>
#include <SparkFunSerLCD.h>
SparkFunSerLCD led(2,2,16); // desired pin, rows, cols
char string[66];
int curWritePos;

void setup () {
Serial.begin(9600);
  led.setup();
  delay(1000);
  led.off();
  delay(1000);
  led.on();
// led.at(2,7,"m:");
  led.cursorOff();
   curWritePos=0;
    string[curWritePos]=0;
}

void loop () {
    int availableBytes = Serial.available();
    if (availableBytes > 0)
    {
        for(int i=0; i<availableBytes; i++)
        {
           int ch = Serial.read();
           switch(ch)
           {
               case '#':
                 //  Serial.println(string);
                   displaycrap();
                   curWritePos=0;
                   string[curWritePos]=0;
                   break;
               case '$':
                   curWritePos=0;
                   string[curWritePos]=0;
                   break;
               case '@':
         
               default:
                   if (curWritePos < sizeof(string)-1)
                   {
                       string[curWritePos++]=ch;
                       string[curWritePos]=0;
                   }
                   else
                   {
               //        Serial.println("Overflow\n");
                   }
                   break;
           }
        }
    }
}



void displaycrap() {

//////////  GET DATA FROM PHP
led.empty();
led.at(1,1,string);
  for (int x=0; x<31; x++) {
    led.scrollRight();
    delay(500);
  }
  for (int x=0; x<31; x++) {
    led.scrollLeft();
    delay(500);
  }
led.cursorOff();   

}

jointtech

#1
Apr 01, 2011, 03:18 am Last Edit: Apr 01, 2011, 03:52 am by jointtech Reason: 1
Well it looks like the LCD has only a 32 character buffer.  So I cant put 64 char in and scroll it back and forth :(
time for plan b.   send a long string and explode it on some break point.

*edit*  it says it has an 80 char buffer.  http://www.sparkfun.com/datasheets/LCD/SerLCD_V2_5.PDF

floresta

Quote
Well it looks like the LCD has only a 32 character buffer...
If it uses an HD44780 or similar controller then it has a memory capable of holding 80 characters arranged in two lines of 40 characters each.  You can store 64 characters but not all on one line.  If you have a 4 line display then things get a bit more complicated.

If you want a complete description of the LCD memory and how it relates to the display screen then check out the LCD Addressing link at
http://web.alfredstate.edu/weimandn.

Don

jointtech

Well I was able to get my screen to scroll properly by breaking it up into a few variables.  well an array really. 

But I've havent come up with a way to continue the looping of the info.

Code: [Select]
#include <SoftwareSerial.h>
#include <SparkFunSerLCD.h>
SparkFunSerLCD led(2,2,16); // desired pin, rows, cols
char string[4][66];
int curWritePos;
int id=-1;;

void setup () {
Serial.begin(9600);
  led.setup();
  delay(1000);
  led.off();
  delay(1000);
  led.on();
// led.at(2,7,"m:");
  led.cursorOff();
   curWritePos=0;
    string[id][curWritePos]=0;
}

void loop () {
  int availableBytes = Serial.available();
    if (availableBytes > 0)
    {
        for(int i=0; i<availableBytes; i++)
        {
           int ch = Serial.read();
           switch(ch)
           {
               case '#':
                 //  Serial.println(string);
                   displaycrap();
                   curWritePos=0;
                   string[id][curWritePos]=0;
                   break;
               case '$':
               case '|':
                ++id;
                curWritePos=0; 
                string[id][curWritePos]=0; 
                break; 


                     
               default:
                   if (curWritePos < sizeof(string)-1)
                   {
                    string[id][curWritePos++]=ch; 
                    string[id][curWritePos]=0; 

                   }
                   else
                   {
               //        Serial.println("Overflow\n");
                   }
                   break;
           }
        }
    }
}



void displaycrap() {

//////////  GET DATA FROM PHP
led.empty();
led.at(1,1,string[0]);
led.at(2,1,string[1]);
delay(5000);
led.empty();
led.at(1,1,string[2]);
led.at(2,1,string[3]);
delay(5000);
led.empty();
led.at(1,1,string[0]);
led.at(2,1,string[1]);
delay(5000);
led.empty();
led.at(1,1,string[2]);
led.at(2,1,string[3]);
delay(5000); 
led.cursorOff();   

}

Go Up