Here's the code:
#include <SoftwareSerial.h>
#define RX 6
#define TX 5
String AP = "...";
String PASS = "...";
SoftwareSerial esp8266(RX,TX);
void setup() {
Serial.begin(9600);
Serial.println("Setup started");
esp8266.begin(115200); // Change this to the factory baudrate used by ESP8266
delay(1000);
Serial.println("Setting BAUDRATE to 9600");
esp8266.println("AT+IPR=9600");
esp8266.begin(9600);
delay(500);
Serial.println("Setup finished");
reset();
connectWifi();
}
//reset the esp8266 module
void reset() {
Serial.println("Resetting...");
esp8266.println("AT+RST");
delay(3000);
if (esp8266.find("OK"))
Serial.println("Module Reset");
else
Serial.println("Module Reset Failed!!!");
}
//connect to your wifi network
void connectWifi() {
Serial.println("Connecting to Wifi...");
String cmd = String("AT+CWJAP=\"") + AP + "\",\"" + PASS + "\"";
esp8266.println(cmd);
delay(4000);
Serial.println("Checking Wifi...");
int ctr=0;
while(!(esp8266.find("OK"))) {
if(esp8266.find("ERROR")) {
Serial.println("Cannot connect to wifi...");
break;
}
delay(50);
++ctr;
if(ctr>10){
Serial.println("Cannot connect to wifi...");
break;
}
}
Serial.println("ConnectWifi finished");
}
The ESP8266-01S wires are as follows:
- GND to arduino ground
- 3v3 to arduino 3v3
- RX to arduino pin 5
- TX to arduino pin 6
- EN to arduino 3v3
The thing worked for one time, and when I re-compiled and sent it again without any changes or even button presses, it stopped working. Furthermore, if I connect ESP module directly through arduino rx and tx and connect arduino reset to ground, I still don't get anything. The led on the esp is blinking during data transfers, but everything else doesn't change and I get no response at all.
1 Answer 1
You need to re-flash your AI Thinker firmware. AT+IPR kills certain versions of the firmware.
Install the latest version of the firmware and use AT+UART_DEF=9600,8,1,0,0
and AT+UART=9600,8,1,0,0
. (The former sets the default baud rate, the latter the current baud rate).
You can read more here.
-
After resetting everything works through direct connection to PC, but when using a SoftwareSerial I get: Setting BAUDRATE to 9600 Response Received: Q⸮⸮E}⸮ʂb⸮b⸮,F⸮⸮⸮P%U⸮IT=N⸮⸮⸮L0 Qi⸮C!⸮CC⸮ ============ Command Sent: AT Response Received: ⸮⸮⸮⸮mcmikecreations– mcmikecreations2018年10月09日 23:46:08 +00:00Commented Oct 9, 2018 at 23:46
-
Here's my setup:
void setup() {
Serial.begin(9600);
ESP8266.begin(115200);
delay(1000);
Serial.println("Setting BAUDRATE to 9600");
ESP8266.println("AT+UART_DEF=9600,8,1,0,0");
ESP8266.println("AT+UART=9600,8,1,0,0");
ESP8266.begin(9600);
} `mcmikecreations– mcmikecreations2018年10月09日 23:47:20 +00:00Commented Oct 9, 2018 at 23:47 -
Welcome to the wonderful world of dodgy at firmware. I would suggest you program the esp8266 to perform the task you require of it and not rely on the awful at firmware.Majenko– Majenko2018年10月10日 00:56:00 +00:00Commented Oct 10, 2018 at 0:56