Problems with serial communication between two ESP8266 using SoftwareSerial.h

Class, I'm using the two codes below to transfer a simple String between an ESP01S(TX) and a NODEMCU(RX).

Connected to the TX I have a 433Mhz receiver and I have a common garage door remote control on hand. TX and RX are on the same contact array sharing the same VCC (3.3 volts) and the same GND.

RX will never send data to TX, it will only receive data, so I only have 1 wire connecting the two. I know that a button on the 433Mhz control generates the code: 140160869
Then I copy it to the codereceiver String.
And I did an IF.
If codereceiver is equal to 140160869 datatx ​​will be equal to "A" and will be sent to the RX through the SoftwareSerial link.
ERROR = DOES NOT SEND.

If I comment on the IF and just inform that datatx ​​is equal to "A", without the IF condition, then YES, IT WORKS, I receive A in the serial RX monitor.

If I comment on serial link communication, disable it in TX, and just use common Serial.print, then YES, the IF condition works in the TX itself, that is, I press the 433Mhz control button and see A on the TX serial monitor .

TX:

#include <RCSwitch.h>
#include <SoftwareSerial.h>
SoftwareSerial link(2, 3); //ESP01S

RCSwitch mySwitch = RCSwitch();

String codereceiver,dadostx;

void setup() {
  delay(2000);
//  Serial.begin(115200);
  link.begin(9600);
  mySwitch.enableReceive(2);
}

void loop() {
  
  if(mySwitch.available()) {
    //Serial.println(mySwitch.getReceivedValue());
    codereceiver = mySwitch.getReceivedValue();
    mySwitch.resetAvailable();
  }

    //Serial.print("CodeReceiver: ");Serial.println(codereceiver);
    //codereceiver = String(code).c_str();   
    //codereceiver.toCharArray(newchar, codereceiver.length() + 1);

  if(codereceiver == "140160869") {
    dadostx = "A";
    link.println(dadostx); //Send to RX using SoftwareSerial
    delay(500);
    codereceiver = "";
    dadostx = "";
  }
        
}

RX:

#include <SoftwareSerial.h>
SoftwareSerial link(4, 9); // Nodemcu12E 1.0

String codereceiver;
const int led = 5;

void setup() {
  
  Serial.begin(115200);
  link.begin(9600);

  pinMode(led, OUTPUT);

}

void loop() {
  
  if (link.available() > 0) {
    digitalWrite(led, HIGH);
    codereceiver = link.readStringUntil('\n');
    Serial.println(codereceiver);
  } else {
      digitalWrite(led, LOW);
    }  

}

Why is this 'confusion' occurring ? Anybody know ?

Thanks

Can you please post schematics for your ESP01 and NodeMCU circuits?

What doubt would your colleague like to eliminate after seeing the diagram ?

If link.print is contained within any IF within loop() there is no serial communication.

I put a link.print("test"). in setup(), and every time I restart the TX I receive test on the RX serial monitor. This indicates that the hardware is perfect.

Perhaps it is the presence of mySwitch.available() inside the loop() that is disturbing serial communication.

I don't know who you mean by "my colleague". I would like to see the schematics because I cannot understand the circuits from your description (English and other natural languages are not a good way to describe a circuit) and I am concerned you may have made an error in the circuits.

Here in BR we have a habit of calling friendly people colleagues. They are not friends, enemies, or adversaries, just... colleagues. It's almost always just an initial way of treating someone who hasn't disappointed you in some way (which is rare). Rest assured.

And you're right, it's definitely my mistake that prevents me from being successful with this problem. I'm researching the ESP01S pinout as there are two (2) in my code. Grateful.

I made a mistake here in the TX code (ESP01S), right at the beginning in SoftwareSerial(2, 3). The correct one is SoftwareSerial(1, 3).

My usual lack of attention to so many details.

Ok, I have no problem with that.

If you had said:

What doubt would you, colleague, like to eliminate after seeing the diagram

I would have immediately understood that you were referring to me as a colleague, which is nice of you.

But what you say was:

What doubt would your colleague like to eliminate after seeing the diagram

Which, here in UK, is a reference to a third person.

lol, google translate's fault. And mine too for not knowing how to speak English and having to use Google Translate. Health and peace there.

1 Like

@sergioarduino you have marked this problem as solved? Is that correct?

Are you able to connect the ESP-01 to serial monitor to verify that it receives the expected code from the garage remote?

I had declared the same pin (2) of the ESP01S for two libraries (SoftwareSerial and RCswitch). When I corrected it by putting (1, 3) in SoftwareSerial everything started to work fine.

When I say work well, I mean serving the purpose of serial communication and seeing the remote control code on the RX Serial Monitor, which is the nodemcu. It doesn't make sense to me to see the code on the TX's own serial monitor - esp01s.

Glad you got it working.

But

Why not? That maybe could have helped to diagnose any problem on the ESP-01.

You're right. But in my case it wasn't necessary.
Good luck with everything out there. See you soon.

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