I am trying to read string send from esp8266 esp01 to Arduino mega. When I use normal Rx and Tx ports, it works properly but when i am initializing new serial port using SoftwareSerial then nothing is being shown on the serial monitor.
Please help me as i have been stuck and trying to solve this for weeks now. Below are the code for esp8266 and Arduino mega
Code for ARDUINO MEGA
#include<SoftwareSerial.h>
SoftwareSerial myS(4,5);
String data="true";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
myS.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(myS.available()){
data=myS.readString();
}
Serial.println(data);
//Serial.write(data);
delay(2000);
}
Code for ESP8266
void setup() {
Serial.begin(9600); // Initialize the Serial interface with baud rate of 9600
}
// the loop function runs over and over again forever
void loop() {
if(Serial.available()>0) //Checks is there any data in buffer
{
Serial.print("We got:");
Serial.print(char(Serial.read())); //Read serial data byte and send back to serial monitor
}
else
{
Serial.println("Hello World..."); //Print Hello word every one second
delay(1000); // Wait for a second
}
}
Moreover, i have tried read() as well instead of readString(), but it does not work either. I have also tried switching Rx and TX pins meaning connecting Rx->Tx, Tx->Rx and vice versa i.e. Rx->Rx and Tx->Tx, but it does not work in any of the case. Any help or suggestion will be appreciated. Thanks