SerLCD problem with 20x4 Serial LCD

Hi there,

I’m using the 20x4 serial enabled LCD from sparkfun. (It has no backpack; it’s the 2.5 version.) Here’s the link for reference:

http://www.sparkfun.com/datasheets/LCD/SerLCD_V2_5.PDF

Also, using the SerLCD library on the Arduino playground site:

http://arduino.cc/playground/Code/SerLCD

I’m having trouble setting the cursor to anything on lines 3 and 4. For some reason, setCursor() seems to ignore or drop any calls which specify lines 3 or 4. You can just dump text to it, and it’ll wrap around and fill those lines. But you can’t just jump there and start displaying. I have tried setting 20x4 mode by writing to the LCD explicitly, with no effect.

Here is the test code:

void DisplayTopMenu() {
  lcd.clear(); delay(100);
  lcd.print("Run Auto"); delay(100);
  lcd.setCursor(2,1); delay(100);
  lcd.print("Run Once Now"); delay(100);
  lcd.setCursor(3,1); delay(100);
  lcd.print("Stop"); delay(100);
  lcd.setCursor(4,1); delay(100);
  lcd.print("Setup"); delay(100);
}

And here is the [simulated] output on the display:

Run Auto
Run Once NowStopSetup

FWIW, I hacked the cpp file to default to 20x4 in this part of the SerLCD.cpp:

// Contstructor
// defaults to 16x2 display
serLCD::serLCD(int pin) : SoftwareSerial(pin, pin){
	pinMode(pin, OUTPUT);
	begin(9600);
	_numlines = LCD_4LINE;
	_numchars = LCD_20CHAR;
	_rowoffset = 0;
}

Any ideas on what I’ve done wrong?

Thanks,

NN

Nevermind - I just rolled my own.

FWIW:

void setCursor(int r, int c) { // 1-4, 1-20
  int x = 0x80;
  
  // Start with the row
  switch (r) {
    case 1: x+= 0; break;
    case 2: x+= 64; break;
    case 3: x+= 20; break;
    case 4: x+= 84; break;
    default: x+=0; 
  }
  // And now add the column
  if (c > 0 && c < 21) {
      x+= c-1;
  }
  lcd.write(0xfe); delay(5);
  lcd.write(x); delay(5);
  delay (5);
}

Looks like you just needed to set _rowoffset = 1;

// Contstructor
// defaults to 16x2 display
serLCD::serLCD(int pin) : SoftwareSerial(pin, pin){
   pinMode(pin, OUTPUT);
   begin(9600);
   _numlines = LCD_4LINE;
   _numchars = LCD_20CHAR;
   _rowoffset = 1;
}