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
-
I guess, it is the newline character. What line end is Serial Monitor set to send?Juraj– Juraj ♦2018年11月25日 08:44:02 +00:00Commented 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.aaa– aaa2018年11月25日 09:40:53 +00:00Commented Nov 25, 2018 at 9:40
-
yes it works perfectlyGyan_mishra– Gyan_mishra2018年11月25日 10:42:24 +00:00Commented 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.aaa– aaa2018年11月25日 11:07:58 +00:00Commented Nov 25, 2018 at 11:07
-
thanks for help @Paul .... the problem was exactly the same...Gyan_mishra– Gyan_mishra2018年11月26日 07:52:47 +00:00Commented Nov 26, 2018 at 7:52
1 Answer 1
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);
-
could you tell me, how to filter out invalid characters before attempting to displayGyan_mishra– Gyan_mishra2018年11月26日 07:56:31 +00:00Commented 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.Jeff Wahaus– Jeff Wahaus2018年11月26日 22:21:23 +00:00Commented Nov 26, 2018 at 22:21
-
thank you @jeff, for providing me such an excellent example of filtering.. it workedGyan_mishra– Gyan_mishra2018年11月27日 07:04:18 +00:00Commented Nov 27, 2018 at 7:04