i want to communicate between two esp8266 i have made serial connections but output is not what i am expecting
there are lot of Garbage values and serial monitor prints old values even after printing new value once
how do i reset serial.available and how to eliminate garbage values
#include <SoftwareSerial.h>
#define rxPin D1
#define txPin D2
String input;
String input1;
SoftwareSerial mySerial = SoftwareSerial(rxPin,txPin);
void setup(){
pinMode(rxPin,INPUT);
pinMode(txPin,OUTPUT);
mySerial.begin(9600);
Serial.begin(9600);
}
void loop() {
if (mySerial.available() > 0) { //wait for data at software serial
input=mySerial.readString(); //Send data recived from software serial to hardware serial
Serial.print(input);
}
if (Serial.available() > 0) { //wait for data at hardware serial
input1=Serial.readString();//send data recived from hardware serial to software serial
mySerial.print(input1);
}}
void loop() {
if (mySerial.available() > 0) { //wait for data at software serial
Serial.write(mySerial.read());
}
if (Serial.available() > 0) { //wait for data at hardware serial
mySerial.write(Serial.read());
}
}
just like it is done in the SerialPassThrough example.