Trying to get a SparkFun serLCD 2x16 to work (display). There are many references in the Arduino Forums regarding SparkFun issues… tried all that appeared to apply to my situation but to no avail.
There’s nothing complicated in my sketch… simply trying to write a line on row 0 and then row 1…
row 0 looks ok, but row 1 does not display properly. Welcome any advice…???
#include <SoftwareSerial.h>
#define txPin 2
SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin
const int LCDdelay=10; // conservative, 2 actually works
// wbp: goto with row & column
void lcdPosition(int row, int col) {
LCD.write(0xFE); //command flag
LCD.write((col + row*64 + 128)); //position
delay(LCDdelay);
}
void clearLCD(){
LCD.write(0xFE); //command flag
LCD.write(0x01); //clear command.
delay(LCDdelay);
}
void backlightOn() { //turns on the backlight
LCD.write(0x7C); //command flag for backlight stuff
LCD.write(157); //light level.
delay(LCDdelay);
}
void backlightOff(){ //turns off the backlight
LCD.write(0x7C); //command flag for backlight stuff
LCD.write(128); //light level for off.
delay(LCDdelay);
}
void serCommand(){ //a general function to call the command flag for issuing all other commands
LCD.write(0xFE);
}
void selectLineOne(){ //puts the cursor at line 0 char 0.
Serial.write(0xFE); //command flag
Serial.write(128); //position
delay(LCDdelay);
}
void selectLineTwo(){ //puts the cursor at line 1 char 0.
Serial.write(0xFE); //command flag
Serial.write(192); //position
delay(LCDdelay);
}
void setup()
{
pinMode(txPin, OUTPUT);
LCD.begin(9600);
clearLCD();
lcdPosition(0,0);
LCD.print("Hello world!");
delay(2000);
}
void loop()
{
clearLCD();
delay(1000);
lcdPosition(0,0);
delay(50);
LCD.print("+++ Line 1 +++");
delay(1000);
lcdPosition(1,0);
delay(50);
LCD.print("*** Line 2 ***");
delay(1000);
clearLCD();
selectLineOne();
LCD.print("+++ Line 1 +++");
selectLineTwo();
LCD.print("*** Line 2 ***");
delay(1000);
}