Reading response from AT commands

Trying to read the responses from AT commands

I have a Nano connected to ESP8266-01 through pins 10/11, all the commands i am sending are of the format ser.println("AT+CWMODE=3\r\n"); and are working correctly, i know this as i am sending data wireless to my PC and capturing the sent data using a VB program, all this works great.

I am now trying to put some error trapping in and am struggling to read the responses from the AT commands, especially from AT+CIPSEND (Unvarnished Transmission Mode), this should return > to then send the data, when i read the response i am getting

M³aÃcåh�i}nµeú ÿI·D›:éBqTBÉ q1³
ë
ã
ŸE RãQGO—Rˆ
«
ìRÕumne 5T"o]tza÷l½:ˆ8=
v
ß
‘E²R×RýOÝS“

This almost looks like a BAUD issue but i cannot see why? the response is the same each time it loops, i think this suggests that its not just junk in the buffer?
I have tried BAUD 9600 and 115200, flushing the buffer before sending a command, putting in a delay after sending the command.

If i connect the Serial leads to RX/TX on the Nano and use the Arduino interface i can send commands directly to the ESP and get the correct response > so i know it all works but it seems to get lost in translation.

If you look at the response there is a > in there but there are also lots of other characters in there so it could just be coincidental?

This is the code that checks the response

ser.flush();
ser.println("AT+CIPSEND\r\n");
delay(500);
  char response[200];
for(int i = 0 ; ser.available() > 0 && i<200 ; i++) {
   response[i++] = ser.read();
}
 //Serial.println(ser.read());
Serial.println(response);

Any help appreciated

Simon

It really does look like a baud issue or noise maybe? Any likely connection issues? Bad connections at the breadboard?

I have played around with the connections and they all seem ok?
If it was a connection issue would you not see errors on the other end when sending? i suppose it could just be on the Rx line?
If it was noise would you not expect the responses to differ every time?

Thanks
Simon

If it is noise, it would be different every time. It looks like what you are posting, it is. It appears to be attempting to return "ERROR" with some noise.

Got a good ground connection between the two devices? Just a thought...

Below are 4 separate replies, the bit i don't understand is if it is noise then the chars wold be different each time but there is a definite similarity

M³aÓcåh�i}nµeú ýI·D›:éCqTBÉ q1³
ê
ã
Ÿb uãsGy— ˆp«.ì.ß.m
c
%R"u]nz ÷Z½ot=avl:Ñ8²
×
ý
Ýb“u¿s¸yi p«...

M³aÓcåh�i}nµeú ýI·D›:éBqTBÉ q1³
ê
ã
Ÿb tããGy— ˆp«.ì.ß.m
c
%R"u]oz ÷T½ot=avl:Ñ8²
×
ý
Ýc“u¿s¸yi Õp«...

M³aÓcåh�i}nµeú ýI·D›:éBqTBÉ q1³
ê
ã
Ÿb uãsGy— ˆp«.ì.ß.m
c
%R"u]nz ÷T½ot=avl:Ñ8²
×
ý
Ýb“u¿s¸xi Õp«...

M³aÓcåh�i}nµeú ýI·D›:éBqTBÉ q0³
ê
ã
Ÿb uãsGy— ˆp«.ì.ß/m
c
%R"u]nz ÷T½ot=avn:Ñ8²
×
ý
Ýb“u¿s¸yi Õp«/..

Doubled up on the earths for good measure!

Are you using a logic level converter? Your Nano is 5v and the module is 3.3v. This is from the Sparkfun ESP8266 page.

The ESP8266 Module is not capable of 5-3V logic shifting and will require an external Logic Level Converter. Please do not power it directly from your 5V dev board.

 char response[200];
for(int i = 0 ; ser.available() > 0 && i<200 ; i++) {
   response[i++] = ser.read();
}

You are incrementing 'i' in two places so you are only filling in every second character in your buffer. Read every second character to see what it says.

Thanks for the feedback,
Interesting comments, ESP8266-01 I am using 5v on this after reading many comments about it can and cannot work with 5v?
I am not sure if the ESP that i have is perhaps more tolerant but it will run perfectly well on 5v (that i am aware!), have tried programming directly onto the ESP and it works great but for what i am doing i need to run it with a Nano, as previously mentioned i have actually got it all up and running and had a bit of a breakthrough last night and changed the code to

while (ser.available() > 0) {
   response = ser.read();
   Serial.print(response);
   delay(10);
}

Now i am getting reasonable responses but still getting odd chars that are incorrect, ran up a simple program to look closer at this

#include <SoftwareSerial.h>

SoftwareSerial ser(10, 11); // RX(TX on ESP8266), TX(RX on ESP8266)
void setup() {
  // put your setup code here, to run once:
   Serial.begin(115200);           // start serial for output
   ser.begin(115200);           // start serial for ESP
}

void loop() {
  // put your main code here, to run repeatedly:
sendData("AT+RST\r\n",10,true);
}

String sendData(String command, const int timeout, boolean debug)
{
    String response = "";
    
    ser.print(command); // send the read character to the esp8266
    
    long int time = millis();
    
    while( (time+timeout) > millis())
    {
      while(ser.available())
      {
        
        // The esp has data so display its output to the serial window 
        char c = ser.read(); // read the next character.
        response+=c;
        delay(100);
      }  
    }
    
    if(debug)
    {
      Serial.print(response);
    }
    
    return response;
}

This is giving me the following responses

ets Jan 8 2003,rst causd:2, bsl�WHFI CONNECTEF
WHFI GOT IP
AR%¥-U¨H¬HèjªHüWHFI DISCONNQ(UHø
ets J`n 8 2013,sst cause:2, bsl�WIFI CONNECTED
WIFI GOT IP
AR)¢ST

j­HøWIFI DISCONNECT

ets Jan 8 2013,rst aause:2, bsl�WIFH CONNECTED
WIFI GOV IP
AR)¦SRC$´Dìi«HøWIFI DIS¨ÊʪÔ(UHø
fts Jan 8 2013,rst causf:2, bsl�WIFI CONNECTED
WHFI GOT IP
AR)¦SZCH¬HèjªHüWHFI DISCONNDCT

ets Kan 8 2013,qst cause:2, bsl�WIFI COONECTED
WIFR:=Q�JA5
AR%©+U´D¨HèjªHüWIFI DISCONNECT

ets Jan 8 2013,rst cause:2, bsl�WIFI CONNDƒTED
WIFI GOT IP
AR%¥-U´D¬HèjªHüWIFI DISCONNECT

ets Jan 8 1013,rst cause:2, bsl�WIGI CONNECTED
WIFI GOT IP
AR)¢SZCH¬Hèj•DüWIFI DISCONOECT

ets Jan 8 2013,rst cause:2, bsl�WIFI CONNECTED
WIFI GOT IP

So i feel i am now a bit closer but its not possible to get code to act on the ESP responses unless the responses are consistent

I have tried running the ESP on 3.3V using a voltage divider but get exactly the same responses.
One thing i have to yet consider is that the Rx on the Nano is supposed to be 3.3V, it seems to work fine on 5v as some people have pointed out, again is this a newer version that is more tolerant? V3.0.

I will try running the ESP on 3V again and see what results i get.

Thanks again for all your pointers
Simon

Perhaps SoftwareSerial is having trouble with the high baud rate. It looks like you are getting bit flips that change the low bit of some characters. I would try at a somewhat slower baud rate like 57600.