esp8266 garbage out only when using SoftwareSerial
I'm trying to operate the esp8266. When I connect RX+TX pins to pins 1+2 on the Arduino, everything works fine. but when I'm trying to use software serial all hell breaks loose and the recieved data is garbadeged (It seems like everything is ok but I can't read the output data... more interesting, the output is not consistent!
example: I'm using a predefined function to send the data, and sending a simple AT command (again, using RXTX conncted to Arduino RXTX everything works well and I get OK).
bool sendCommand(const String& cmd,uint64_t timeout,bool vrbs = false,String* responseP = 0)
{
String strCntnr;
String& response = responseP? *responseP: strCntnr;
response = "";
if(vrbs)
Serial.print("RX: "+cmd+ "...");
esp8266.print(cmd+"\r\n"); // send the read character to the esp8266
for(uint64_t time = millis();(time+timeout) > millis();)
for(;esp8266.available();response+=(char)esp8266.read());
bool ok = response.length()>0;
response.replace("\r\n"," ");
if(vrbs)
Serial.println(ok? "OK ("+response+")":"ERROR");
return ok;
}
Setup function:
SoftwareSerial esp8266(3, 2); // RX, TX
void setup() {
esp8266.begin(115200 );
Serial.begin(115200 );
sendCommand("AT",2000,true);
...
}
And output:
AT...OK (AR CטjμLר)
or:
AT...OK (AjCH ́Dטk×ばつHר)
or:
RX: AT...OK (AR CטjμD�)
,or any other random string...
- 101
- 1
- 5