0
votes

Can anyone help me with communication between Arduino Uno and ESP8266-05?

I've this simple code only for testing response:

#include <SoftwareSerial.h>

SoftwareSerial esp8266(12, 13);

void setup () {
    esp8266.begin(19200);
    Serial.begin(115200);
}

void loop () {
    char buffer[50];
    esp8266.write("AT\r\n");
    esp8266.readBytes(buffer, sizeof(buffer));
    Serial.println(buffer);
    delay(1000);
}

But the response is some junk (in Serial monitor on my PC):

1_Q¨ (X1JXþUÉÁEóAñ¡5%¥4¡1!!1%%¡5%¡4¡1¡!!G-]5

This behaviour is the same if I'm using a simple resistor voltage divider or level shifter (http://www.banggood.com/5-Pcs-3_3V-5V-TTL-Bi-directional-Logic-Level-Converter-For-Arduino-p-951182.html).

Connection:
Arduino - esp
pin 12 - pin Tx
pin 13 - resistor divider 10k/20k - pin Rx

OR
Arduino - (HV) level shifter (LV) - esp
pin 12 - TxO - TxI - pin Tx
pin 13 - RxI - RxO - pin Rx

ESP reset pin - not connected

I don't know what's wrong, because when I turn on the Arduino and ESP module, I see on my notebook a new wifi network called AI-THINKER_012568 and I can connect to this network.

I supposed, when I turn on the ESP module, I should get a 'ready' response, but I get only some junk data. So, for the 'AT' command, I should get an 'OK' response...

I searched a lot for troubles with character set (ASCII vs UTF), but without any results.

I've tried a lot of combinations with reading (read()) and writing (write(), print(), println()) data from one serial port to another, but only with some junk response or without any response... I've tried various baud rates too.

Bonus question: when I searched for some manuals, I've only found manuals with ESP8266-01, so, is ESP8266-05 worse than the first version or is there something wrong?

Edit:

When I've simple code for arduino, which only sends data from one serial port to the second port:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(12, 13); // RX, TX

void setup () {
    Serial.begin(9600);
    while (!Serial) {}
    Serial.println("€");

    mySerial.begin(9600);
}

void loop () {
    mySerial.listen();
    int i = 0;
    while (mySerial.available()) {
        char c = mySerial.read();
        Serial.write(c);
        i++;
    }
    if (i > 0) {
        Serial.println();
    }        


    int j = 0;
    while (Serial.available()) {
        char c = Serial.read();
        mySerial.write(c);
        Serial.print(c);
        j++;
    }
    if (j > 0) {
        Serial.println();
        mySerial.println();
    }
}

And when I upload code and turn on ESP microchip, I got something like this:

â-¬

ÿ
q·$aã
Å% ð´
D9$kvKþµ¿`ÈÛ¯h:¤ó[Y \B¡H$èðÍÝ׸Jø
å
ü+¡
ð

First line is for '€' character, only for test. Next lines are initial response from ESP microchip. As I read in ESP documentation, when ESP microchip starts, I should got some data about version and ready word. Means these lines, that ESP microchip is death or only there is something wrong with reading this response?

Then when I sent 'AT' command, I got no response :(

1
Did you try other baud rates on software serial?gre_gor
Same problem here. I can confirm this also for ESP8266-01.lbedogni
To gre_gor: yes, I tried all baud rates, which are defined in Serial monitor drop down. I tried these baud rates for connection Arduino <-> ESP.Jakub Maňas Moravec
Did you tried to reflash the esp?Fruchtzwerg
You wrote all baud rates but some esp's have a weird baud rate which is non-standart. It is somewhere close to 74880 or 74560 did you also try that?Mert Gülsoy

1 Answers

0
votes

This is a sign of a fried board. If the board ever received 5 V or was running from the 3.3 V pin on the arduino for an extended period of time, chances are, the board is dead.

From a programming point of view, I have seen String line = mySerial.readStringUntil("\n"); work quite well. You can then use and if statement to check if the line is OK or ERROR. If this implementation is still returning garbage at a baud rate of 9600, then the board is dead.

Software serial doesn't work at a baud rate of 115200, so don't even try it. Make sure the baud rate of the board is changed to 9600 (something I see you already did) and keep it there! That isn't the issue.

These boards are very sensitive as to their power input. Giving 5 V or too little current at 3.3 V will destroy them. Trust me, I've ruined 4 of them by simply connecting them to the 3.3 V power pin on the arduino without realizing what was happening.

The code I gave you should work; I've used it in a project flawlessly...

Hope this helps :)