0

I'm trying to read all the available access points nearby with an ESP8266 module.

Whenever I try to read all the available data from the ESP module and write it to the Monitor Serial it truncates text. Text often also a bit messed up.

I'm using an Arduino Uno with the following scheme (I'm using pins 2 & 3 NOT 1 & 0):

enter image description here

#include <SoftwareSerial.h>

SoftwareSerial esp8266(2, 3);

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);

  esp8266.begin(115200);
}

void loop() {
  while(esp8266.available()) {
     Serial.write(esp8266.read());
  }

  while(Serial.available()) {
    esp8266.write(Serial.read());
  }
}

The code prints something like the following:

AT+CWLAP

+CWLAP:(3,#SBanaan",-73,"4c:09:d4:d5:d6:f2",1,,2,0)
+CWLAP:(3,"UPC24923"CH7"0,L5-:d6Ai0:,
,,f5
44"f"CZ7f1
4-"6:0:4-95
,5-3d0

3 Answers 3

1

As @JoseCanUC has mentioned SoftwareSerial is not reliable at 115200 baud. This is because the bytes are sometimes too close together for the Arduino to start receiving a new one when the start bit arrives, and so the byte starts being received part way through, thus corrupting it.

You should investigate setting the baud rate of the ESP8266 to 9600, although this itself comes with its own set of pitfalls. You should be prepared to re-flash the AT firmware to reset the baud rate if it all goes wrong. I would seriously suggest investing in one of the many cheap USB programming adaptors for the ESP-01 on eBay, since it makes working with these devices so much simpler. It also opens up the possibility of creating and installing your own firmware for the ESP8266 instead of using the somewhat clunky AT firmware interface.

3
  • Even better might be to look at the Wemos D1 mini or NodeMCU products, which break out a lot more GPIO pins from the ESP8266, and have an on-board USB-TTL converter. Dec 19, 2017 at 16:48
  • Indeed - though they are physically bigger. If you want to get into programming them then yes those are far more convenient. However if all you want is a small WiFi interface for an Arduino or similar board then the small size of the ESP-01 is quite convenient - just hard to program without an adaptor.
    – Majenko
    Dec 19, 2017 at 16:50
  • Thanks for the detailed explanation and suggestions, it helped a lot! The following command did the trick including changing the baud rate in code ass well: AT+UART_DEF=9600,8,1,0,0
    – Jamie
    Dec 19, 2017 at 17:48
2

For SoftwareSerial, at 115200 bps data rate is not going to be reliable. Try 9600 bps.

1

I'm a bit confused by your diagram showing no ATmega chip on the Uno board, but you posted Uno code that should properly communicate with your ESP (except for the baud rate being too high for SoftwareSerial).

See my answer to another ESP question for how to change the ESP's baud rate, especially the code fragment at the bottom of that answer.

Changing the ESPs parameters is not difficult as long as its AT firmware is intact (which it will be if you haven't attempted to re-flash the device). Changing baud rate is only slightly tricky, in that once the Uno has told the ESP to change its baud rate, the Uno must also change its baud rate to match before you can re-establish communication with it.

1
  • You are right, everything worked except the baud rate. That was the problem. Setting it to 9600 worked.
    – Jamie
    Dec 19, 2017 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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