Linking ESP8266 with Arduino
I found it super-hard to find meaningful info on how to link a tiny little ESP8266 (ESP-01 in my case) to an Arduino and talk to it.
Schematics
Things to notice here is power regulator 1117-33 that converts 5V of Arduino board into stable 3.3V for ESP8266. We could probably use 3.3V Arduino output, but I read it’s not powerful enough for when the module is transmitting. Also I wired Arduino D11 to RXD of ESP8266 through voltage divider, so that 5V is also converted to 3.3V range. Logic level converters can be used here, but I have none handy, so divider be it.
Software
My module was initially in 115200 baud mode. When you don’t know that it may cause a lot of confusion. Arduino I have isn’t quick enough to do any useful work and catch up, so I had to find a way to switch module to a lower baud rate.
The module speaks AT-commands, and there are dangerous sequences that can brick your module that I won’t write here to save everyone from trouble. Here’s a pretty good one instead:
AT+UART_DEF=57600,8,1,0,0
It switches UART into 57600 baud mode with 8 bits, 1 stop bit, 0 for parity and 0 for flow control.
Here’s the small program that lets you talk to the module in Serial Monitor tool.
#include <SoftwareSerial.h>
SoftwareSerial wifi(10, 11); // RX, TX
void setup() {
Serial.begin(115200);
while (!Serial) { }
// wifi.begin(115200);
// wifi.println("AT+UART_DEF=57600,8,1,0,0\r\n");
wifi.begin(57600);
wifi.println("AT+GMR\r\n");
}
void loop() {
if (wifi.available()) Serial.write(wifi.read());
if (Serial.available()) wifi.write(Serial.read());
}