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() {}
leoc7
6034 silver badges12 bronze badges
asked Jan 2, 2019 at 18:02
3
  • 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 Commented Jan 2, 2019 at 18:42
  • Please, be more precise, provide the schematic. Are you sure that connection are correct? Commented Jan 2, 2019 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. Commented Jan 2, 2019 at 22:57

1 Answer 1

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.

answered Jan 2, 2019 at 20:04
1
  • 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! Commented Jan 2, 2019 at 23:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.