Sparkfun SerLCD scrolling

Hi guys,

First post! I'm new to the world of Arduino; just got one along with a Sparkfun 16x2 SerLCD, an ethernet shield and some other bits and bobs a few days ago. I've been playing with the LCD the most, as I'm looking at building the usual "hello world" sort of application with these components: an RSS weather displayer.

I can handle the ethernet stuff and the RSS parsing fine, but I'm running into problems with the LCD. The basic stuff is no problem (I'm using the excellent SparkSoftLCD library posted on the board a few weeks ago (can't post link as it's my first post!), but I'm having headaches trying to get the top line to scroll while the bottom line remains static.

What happens is, the scrolling seems to "erase" the bottom line, from right to left! So if I start with:

ABCDEFGHIJKLMNOP
abcdefghijklmnop

after two one-character leftward scrolls I get this:

CDEFGHIJKLMNOPQR
abcdefghijklmn

I've been googling like a bat outta hell but can't find anything that explains this specific problem. I'm sure it's a cursor issue but just can't get my head around it! Can anybody help?? Relevant bits of code are below.

Cheers,

-- Tim

void loop()
{
  LCD.clear();
  scrollText("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26, "abcdefghijklmnop", LCD);

}

void scrollText(char *textstring, int textlength, char *bottomtext, SparkSoftLCD target) {
  
  int i;
  
  // print the first 16 chars straight away
  for(i = 0; i < 16; i++) {
    target.print(textstring[i]); 
  }
  
  target.cursorTo(2,1);
  target.print(bottomtext);
  
  //pause before scrolling
  delay(3000);
  
  // then scroll one char to the left for each remaining char, rewriting the 
  //bottom line each time so it appears static
  for(i; i < textlength; i++) {
   target.cursorTo(1,i+1);
   target.print(textstring[i]); 
   target.cursorTo(2,i-14);
   target.print(bottomtext);    
   target.scroll(false);
   delay(500);

  }
  delay(3000);
}

Hi Maple,

I haven't had that issue - but I also haven't tried to do exactly what you're doing =) When I get home tonight, I'll check it out and see what I can come up with! I think it may simply be that the driver on the lcd doesn't like being used that way (i.e. overwriting the part of the buffer, and attempting to re-create it back with no changes).

!c

Great! Thanks drone. I'm in no way attached to this code whatsoever, so if you can come up with any alternative way to scroll the top line whilst keeping the bottom line static then I'll take it! I'm sure it must be possible, but it's totally eluding me...

Cheers,

-- T

Ok, I found the problem -- it seems related to printing characters past the "documented" positions supported by the sparkfun serial LCD. You can work around it, but it requires telling it to go to a position that's on a different line =)

For example, if you look at page 3 on the datasheet (http://www.sparkfun.com/datasheets/LCD/SerLCD_V2_5.PDF), you can see that valid column positions for rows 1 and 2 are between 0-15 and 64-79. The layout for the rows is: 1-3, 2-4 (x,y). So when you go past position 16, you're in the 3rd row's territory. When you overrun the current line's positions (apparently my 16-char lcd is setup as a 20-char), it only prints the fraction of the string that would normally fit on the line.

This only seems to happen when multiple characters are printed in a row without calling cursorTo() between them -- such as when calling lcd.print(char *str). It can be worked around for now, by calling cursorTo() between each character printed when you know you're printing in a position that isn't supported.

The following code, for example, works: (but try uncommenting print(bottomtext) instead)

#include "SparkSoftLCD.h"

#define LCD_PIN 2

char text1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char bottomtext[] = "abcdefghijklmnop";

SparkSoftLCD LCD = SparkSoftLCD(LCD_PIN, 16);

void setup() 
{
  
  pinMode(LCD_PIN, OUTPUT);

  LCD.begin(9600);
  LCD.clear();
}

void loop()
{
  LCD.clear();

  LCD.cursorTo(1,1);
  for(byte i = 0; i < 16; i++) {
    LCD.print(text1[i]);
  }

  LCD.cursorTo(2,1);
  LCD.print(bottomtext);
  
  delay(1000);
  
  for(byte i = 17; i <= 26; i++) {
    LCD.scroll(false);
    LCD.cursorTo(1,i);
    LCD.print(text1[i-1]);

  
    // does not work:
    // LCD.print(bottomtext)  
    
    for( byte p = 0; p < (sizeof(bottomtext) / sizeof(bottomtext[0])); p++) {
      LCD.cursorTo(2, 2+(i-17)+p);
      LCD.print(bottomtext[p]);
    }

    delay(500);

  }

  delay(2000);
}

It seems that there's a state change or sanity check that is sometimes getting overwritten in the firmware, related to the current cursor position.

!c