(Resolved) Weird Characters following Proper Text on 1602 LCD

Hello! I have built a device that will take data from the serial monitor and display it on a 1602 LCD that is connected in the same way as the attached circuit depicts. It should be displaying what I've entered, and while it does, two sets of three horizontal lines are at the end of each string. I'm not sure as to why it does this, maybe something to do with the serial buffer, but any suggestions are appreciated. Thanks!

Code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

String serialIn;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  lcd.begin(16, 2);
  Serial.println("ENTER TEXT ABOVE");
  Serial.println("clear   - CLEAR TEXT\n\n");
  lcd.print("ENTER SERIAL");
  delay(2000);
  lcd.clear();
}

void loop() {
  // put your main code here, to run repeatedly:
  serialIn = Serial.readString();

  if (serialIn == "clear"){
    lcd.clear();
    Serial.println("LCD: TEXT ERASED");
    Serial.flush();
  }
  if (serialIn != "" && serialIn != "clear")
  {
    lcd.println(serialIn);
    Serial.print("CURRENT: ");
    Serial.println(serialIn);
    Serial.flush();
  }
}

The "weird characters" are Carriage Return and Line Feed.


Do not - repeat, do not ever - use "lcd.println()". It has no purpose.

1 Like

Do you know of any way to remove said characters?

Yep. Do not use "lcd.println()".

You just missed my edit. :grinning:

Thanks. Now the problem is gone! :slight_smile:

Hey please help me out
i did the the same with a nokia 5110 display

If you have the same problem then the same answer will apply. If you have a different problem then you really should start a new thread. Note that this thread is marked (Resolved). Some of the people who normally solve problems may not even look at a resolved thread.

The original problem is due to a characteristic of the LCD controller used with the '1602' type displays. We would need a link to the controller for your display to see if the cause is similar.

Don

Paul__B:
The "weird characters" are Carriage Return and Line Feed.


Do not - repeat, do not ever - use "lcd.println()". It has no purpose.

It actually depends on the library.
The problem with the vast majority (all but one i've seen so far) of hd44780 libraries, is that they don't implement end of line processing.
I have seen one library that does support end of line processing and line wrap.
But the ones that don't, usually blindly send the end of line characters to the hd44780 display as normal characters.
The display interprets them as characters down in the custom character space and so if end of line processing was desired, the result of displaying custom characters, which often have not been defined and create "garbage" characters on the display, isn't the result that was expected.

A good alternative approach for a hd44780 library that inherits the Print class but does not implement end of line processing used by println() is to swallow and disregard and characters.

--- bill