0

I am using the following codes to print characters on LCD display....

#include <LiquidCrystal.h>
const int rs = 8, en = 9, d0 = 4, d1 = 5, d2 = 6, d3 = 7;
LiquidCrystal lcd(rs, en, d0, d1, d2, d3);
void setup() {
 lcd.begin(16, 2);
 Serial.begin(9600);
}
void loop() {
 if (Serial.available()) {
 delay(100);
 lcd.clear();
 while (Serial.available() > 0) {
 lcd.write(Serial.read());
 }
 }
}

but in the end it is generating an unwanted character also.. enter image description here

kindly help me with the problem

per1234
4,2782 gold badges23 silver badges43 bronze badges
asked Nov 25, 2018 at 6:27
5
  • I guess, it is the newline character. What line end is Serial Monitor set to send? Commented Nov 25, 2018 at 8:44
  • Does 'lcd.write("Hello");' work? You should check if the problem is on the serial or on the LCD. Commented Nov 25, 2018 at 9:40
  • yes it works perfectly Commented Nov 25, 2018 at 10:42
  • @Gyan_mishra in that case, it doesn't appear to be a problem on the display's side. Is the same character generated when you do: "lcd.write("\r\n");"? Or choose "No line ending" in the Arduino serial monitor. Commented Nov 25, 2018 at 11:07
  • thanks for help @Paul .... the problem was exactly the same... Commented Nov 26, 2018 at 7:52

1 Answer 1

2

The character to the right of the 'A' on your LCD display does not correspond to any of the built-in character bitmap definitions (either on a EU or Chinese display). This random pattern is likely one of the 8 programmable character bitmaps supported by the LCD that has not been defined yet (ASCII codes 0 to 7).

So, you're likely sending the LCD a character with a value between 0 and 7. It's probably a good idea to filter out invalid characters before attempting to display them on your LCD.

Filtering Example:

char c = Serial.read();
if ((c >= 32) && (c <= 128))
 lcd.write(c);
answered Nov 25, 2018 at 13:50
3
  • could you tell me, how to filter out invalid characters before attempting to display Commented Nov 26, 2018 at 7:56
  • I've updated the answer to illustrate a simple filtering example. Take a look at an ASCII table to understand why the numbers I chose are significant. Commented Nov 26, 2018 at 22:21
  • thank you @jeff, for providing me such an excellent example of filtering.. it worked Commented Nov 27, 2018 at 7:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.