Lcd printing 2 glitched letters

Hi, im trying to print a random phrase on a display via bluetooth using a Arduino mega, hc-05, a display 16x2 attached with a PCF8574 microcontroller. But everytime time i try to send a phrase, the lcd prints 2 extra glitched letters. On serial monitor it is printing the phrase normally. Here is my code

#include <LiquidCrystal_PCF8574.h>
#include <Wire.h>
#include <SoftwareSerial.h>

SoftwareSerial bluetooth(18, 19);
LiquidCrystal_PCF8574 lcd(0x27);
char b;
String a;

void setup() {
  Serial.begin(9600); 
  Serial1.begin(9600);
  bluetooth.begin(9600);
  Wire.begin();
  Wire.beginTransmission(0x27);
  lcd.begin(16, 2);
}

void loop() {
 
   lcd.setBacklight(255);
   while (Serial1.available()) {
   b = Serial1.read();
   a += b;
   }
   lcd.print(a);
   Serial.print(a);
   delay(5000);
   lcd.clear();
}

@johnnykujo Why do users choose to ignore the advice on posting code ?

The easier you make it to read and copy your code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here to make it easier to read and copy for examination

If you get errors when compiling please copy them from the IDE using the "Copy error messages" button and paste the clipboard here in code tags

1 Like

What have you got Line ending set to in the Serial monitor ? Is it "Both LN & CR" by any chance ?

1 Like

Exactly right. This is very likely to be a CR LF issue.
char are just numbers, so you could filter our decimal values or 10 and 13 (cr and lf) or simply anything below 32.

The serial monitor showed "abcd" normally, i make some research and i found that the Serial monitor uses CR and LF normally, but the lcd doesn't have such configuration. But still i don't know how to add this do the lcd

Hello
Take a view here.

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.