Could someone help me with some suggestions please? Using ESP8266 and MEGA2560 on UART interface i want to display the message received on the mega serial to the LCD connected to it on i2c. The problem is that the LCD shows some strange unknown character and the serial monitor corresponding to mega shows this :
LED on LED OFF LED on LED OFF LED on LED OFF LED on LED OFF LED on LED OFF LED on LED OFF LED on LED OFF LED on LED OFF LED on LED OFF LED on
when it should display this:
LED on
LED OFF
LED on
LED OFF
LED on
LED OFF
LED on
LED OFF
LED on
LED OFF
LED on
LED OFF
LED on
LED OFF
LED on
LED OFF
LED on
LED OFF
the code for ESP is this:
int pinLed = 16;
void setup()
{
Serial.begin(115200);
Serial.begin(115200);
pinMode(16,OUTPUT);
delay(500);
}
void loop()
{
digitalWrite(16,HIGH);
Serial.print("LED on\n");
delay(5000);
digitalWrite(16,LOW);
Serial.print("LED OFF\n");
delay(5000);
}
the code for mega is this:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include<SoftwareSerial.h>
LiquidCrystal_I2C lcd(0x3F,20,4);
void setup()
{
Serial.begin(115200);
lcd.init();
lcd.backlight();
while (!Serial)
{
Serial.print("Attempting to connect! ");
Serial.print("Trying again...");
}
}
void loop()
{
if (Serial.available()>0)
{
char c = Serial.write(Serial.read());
Serial.print(c);
lcd.print(c);
}
}