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 :(
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