0

I want to use a ESP8266 (ESP12) to receive data from a counter at 9600 baud via SotwareSerial. But my program does not receive any data. I broke it down to the code i attach here. I tried it using different libraries (Arduino SoftwareSerial and also espsoftwareserial) i found. I connected and tested RX and TX in different combinations of the available pins 4/5/12/13/14. But no combination is receiving data at all. I only can send data - checked by oscilloscope. Running my test program attached i connected the RX and TX pin together so i should loop back the data from tx.

I hopefully find somebody in the community who can give me a helpful hint. Thank you in advance!

#include <SoftwareSerial.h>
SoftwareSerial mySerial1(14, 12, false, 256);  // RX, TX

void setup() {
mySerial1.begin(9600);   //  Kommunikation mit Zähler
mySerial1.setTimeout(5000);
mySerial1.listen();
//delay(100);
//mySerial1.listen();

Serial.begin(9600);
delay(1000);
Serial.print(__DATE__);Serial.print(" ");Serial.println(__TIME__);

char ch;
while(1){
  wdt_reset();
  Serial.println("\nSoftware serial test started");
  Serial.print("Data sent: ");
  for (byte i = 32; i < 128; i++) { mySerial1.write(i);             
  Serial.print(char(i)); }
  Serial.println();
  mySerial1.println();
  ESP.wdtFeed();
  delay(100);
  Serial.print("Data recv: ");
  if(mySerial1.available()) {
    while(mySerial1.available()){
      ch = mySerial1.read();
      Serial.print(ch);
    }
    Serial.println("_");
  }
  delay(400);
}
}

void loop() {}
  • Dear @fhpa, before answering, I suggest you to remove while(1) from setup() function and move content of while(1) inside loop() function. Loop() function, as suggested by its name, loops consecutively. arduino.cc/en/Reference/Loop?setlang=en – leoc7 Jan 2 at 18:42
  • Please, be more precise, provide the schematic. Are you sure that connection are correct? – leoc7 Jan 2 at 18:56
  • Thank you commenting. Yes, the connections have been correct. In the meantime my question was answered and the problem is solved: SoftwareSerial cannot send and receive at the same time. – fhpa Jan 2 at 22:57
2

If the ESP8266's software serial is anything like the Arduino's software serial, it cannot receive data while it's transmitting. It's strictly half-duplex.

To test your system you will need to test the transmission and reception completely separately, and that means having some external device sending data for you to attempt to receive.

  • Thank you Majenko for your answer solving the problem. You are right saying the SoftwareSerial is working strictly half duplex. I tested it with a second esp only sending data and receiving with the second ESP. BTW i only need to receive data. I think you saved me a lot of my time! – fhpa Jan 2 at 23:01

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.