20x4 LCD Screen Printing Problems

Iv'e been using the Hitachi 20x4 screen for a while now and I'm constantly noticing that the integer variables I am printing are not as they should be. Last night I setup a few lines: temp, humidity, light, IR motion. The one that keeps playing up the most is the Light sensor and IR motion, it keeps adding digits, especially zeros, and does not always look the same as the serial monitor version. I've tried added "DEC" within the print brackets to stop any values from 0 to 9 being single to stop each line from reshuffling, but that didn't do anything to help.

My code so far:

lcd.setCursor(0,2);
  lcd.print("PC: ");
  lcd.print(lightVal);

lcd.setCursor(8,2);
  lcd.print("IR: ");
  lcd.print(irVal);

It always seems to be the the prints that start later on the line i.e. lcd.cursor(8,2), etc.

Could you post a picture?

In your example sketch: are you sure the two values: (lightVal) (irVal) are integers?

Seems like one line is overflowing to the next line.

Maybe, I’m over simplifying.

At the time this was taken, the PC: was 2 in the Serial Monitor, and the IR: was 0.

Good news bad news...
Bad news I'm a newbie too.

Can you add a "clear display" line of code and add a delay that is long enough for you to see what is happening? I've had similar problem that something gets written to the display; is PARTIALLY over written; yet some confusing remnants remain.

It writes so fast it's difficult to see in real time.

Some other experts will soon chime in!

I agree with CarlW. I have a function that I add to any sketch using LCD.

void lcdClrLine(byte line) {
     lcd.setCursor(0, line);
     lcd.print("                    ");  //number of spaces as characters per line
     lcd.setCursor(0, line);
}

call this before print to erase what is there and reset to start of line.

Thanks guys, that makes sense, I know I do something similar on the lcd.setCursor(0,0) to erase each line when sending SD card debugging strings. Never thought of making a function for it :slight_smile:

Will give that method a try next time I fire up the sketch :slight_smile:

lcd.setCursor(x,x) does not clear the line! It only moves the cursor.

Sorry, yes I know that, I just forgot to mention that I normally apply this:

lcd.setCursor(0,0);
lcd.print(" ");

thank you.Will give that method a try next time I fire up the sketch