RX TX communication between two esp8266

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);
  }}

https://circuits4you.com/2016/12/14/software-serial-esp8266/

Kindly refer to the above link for further help. Care should be taken to make sure the right RX and TX pins are used on ESP8266.

Also, while using the serial monitor make sure the baud rates mentioned in the code and on the serial monitor are same.

You seem to be using pins 1 & 2 for Software Serial, but pin 1 is already being used by the hardware serial?

image

Also I believe the 8266 has 2 hardware serial ports... you would be better off using those rather than Software Serial.

Este es el foro en español, por favor, abstenerse de hablar en ingles.

Actually... no it isn't. I think you are lost.

GPIO 1 is for tx i have used D1 which is different from gpio

how about you try it like this.

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.

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