Reputation: 27
My problem is when I input the string in the serial monitor it shows like this:
LCD Arduino Error The setCursor dont work and also there is another weird character created before the actual output.
This is my sample code:
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
lcd.print("hello, world!");
}
void loop() {
String readString;
String Q;
while (Serial.available()) {
delay(1);
if (Serial.available()>0) {
char c = Serial.read();
if(isControl(c)){
break;
}
readString += c;
}
}
Q = readString;
if (Q == "1"){
lcd.setCursor(0,1);
lcd.print("Hello");
}
if (Q == "2"){
lcd.setCursor(0,1);
lcd.print("World");
}
}
Upvotes: 0
Views: 1518
Reputation: 2989
First of all you should understand the LCD lib functions.
To set the cursorto theFirst row you need
lcd.setCursor(0,0); // row index starts with 0
if you only set the cursor back without clearing the screen there might be weird chars,sodo a
lcd.clear(); //clears the whole screen
OR define an empty String:
String lineClear =" "; // should be 16 spaces for a 16x2 display
and do as a clearing sequence (e.g. for the top line)
lcd.setCursor(0,0);
lcd.print(lineClear);
lcd.print("Hello");
Remember the syntax is
lcd.setCursor(col, row)
// index for 16x2 is col 0-15,row 0-1
// index for 20x4 is col 0-19,row 0-3
and in setup alwas do a
lcd.clear();
after initializing the lcd, to remove possible artefacts from the buffer
Upvotes: 0