With Serial.readString(), it doesn't display anything, but when I stop simulation it display the above attached image (uknown characters).
I am using Arduino Mega. The LCD works pefectly with other codes.
The corrected code :
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x3F for a 16 chars and 2 line display
int foundValue = 0;
int cursor = 0;
void setup() {
lcd.init();
lcd.clear();
lcd.backlight(); // Make sure backlight is on
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
String rc;
rc = Serial.readString();
lcd.setCursor(cursor, 0); //Set cursor to character 2 on line 0
cursor += lcd.print(rc); //print serial value to LCD
cursor += lcd.print(" ");
}
delay(1000); //Wait for 1s
if (cursor >= 16) {
lcd.clear();
cursor = 0;
}
}```

