lcd printing some unwanted characters after message

hello guys i have a problem with a 20, 4 lcd setup that is printing the message properly but its adding two weird characters after, if i print other lines the characters move next to the last letter.

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
lcd.begin();
lcd.clear();
pinMode (A0, INPUT);
Serial.begin(9600);
}

void loop() {
String message = " Celsius";
int value = analogRead(A0);
float temperature = (value / 4.9) / 10;
Serial.print ("The temperature is ");
Serial.println(temperature + message);
lcd.setCursor(0,0);
lcd.print("The Temperature is ");
lcd.setCursor(0, 1);
lcd.println(temperature + message);
delay(500);
}

thanks in advance for the help :slight_smile:

Do not use println(). It is not supported by the LiquiCrystal library. The strange characters are the LCD controller writing the carriage return and line feed.

Just use print() and control the cursor with the serCursor() function.

thanks a lot! :smiley:

groundFungus:
The strange characters are the LCD controller writing the carriage return and line feed.

While the Arduino LiquidCrystal library is sending the and characters to the display,
technically the LCD isn’t actually writing the carriage return in line feed on the display.
Those characters land in the custom character range for the LCD.
The LCD is drawing the custom characters that the character code points for and represent.
i.e. is ascii code 0x0D or 13 and is 0x0A or 10
The hd44780 has 8 custom characters.
They are programmed/printed through code points 0x00 to 0x0F or 0 to 15
But since there are only 8, code points 0x08 to 0x0F are a repeat of code points 0x00 to 0x07

so code point 0x0A or 10 is custom character 2 and code point 0x0D or 13 is custom character 5

If you send and to the LCD display and have not programmed custom characters 2 and 5 then when the LCD prints those custom characters, you will get garbage characters.

— bill

I can't spot anything corresponding in the HD44780 datasheet, but the characters returned seem to be pretty consistent in such reports here, one of them being a multiple bar which seems to match a line feed.

all 8 unused custom characters will produce this pattern:

  for (byte i = 0; i < 16; i++)
      lcd.write(i);

Paul__B:
I can't spot anything corresponding in the HD44780 datasheet, but the characters returned seem to be pretty consistent in such reports here, one of them being a multiple bar which seems to match a line feed.

noiasca:
all 8 unused custom characters will produce this pattern:

Actually, some LCDs will show what you have shown, and some don't.
as some LCDs pre-fill each custom character with:
0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00
and some don't put in anything in CGRAM which means it is total garbage on power up and can vary on each power cycle.
I have attached some photos of an LCD that does not fill in the custom characters with and without custom characters defined. You can see the garbage with no custom characters, and you can see the code points with special small digits defined for each of the 8 code points.

I have also attached some test code so you can try it as well.
There is one sketch for LiquidCrystal and another for hd44780 using the I2Cexp i/o class.
With the hd44780 example, it will read and dump the contents of the CGRAM so you can see what it is on power up.

--- bill

CGRAMtests.zip (2.48 KB)