I bought a ESP 8266 & I am able to send AT commands and receive response via serial monitor when I upload a empty sketch. I changed the baud rate from 115200 to 9600 by using AT+CIOBAUD=9600
and am able to run AT commands at 9600 baud rate.
Empty Sketch:
void setup()
{
}
void loop()
{
}
Problem
The problem is when I create a custom sketch to run AT commands it doesn't work. Here is how my sketch looks:
#include <SoftwareSerial.h>
SoftwareSerial esp8266(0,1); //RX,TX
void setup()
{
Serial.begin(9600);
esp8266.begin(9600);
Serial.println("Run AT Command");
esp8266.print("AT\r\n");
}
void loop(){
String response = "";
while(esp8266.available()) {
char c = esp8266.read();
response+=c;
Serial.print(c);
}
if(response != ""){
Serial.println(response);
}
}
ESP8266 is receiving 3.3V but I have read TX and RX sends 5V, and they also need to be 3.3V. Don't know if thats what is causing it, but I am able to run AT commands on empty sketch, so this is a bit weird.
UPDATE:
My sketch is:
#include <SoftwareSerial.h>
SoftwareSerial esp8266(2, 3); //RX,TX
void setup()
{
Serial.begin(9600);
esp8266.begin(9600);
esp8266.print("AT\r\n");
}
void loop() {
String response = "";
while (esp8266.available()) {
char c = esp8266.read();
response += c;
}
if (response != "") {
Serial.println("Response: " + response);
}
}
Serial Monitor shows this:
Response: A
Response: T
OK
Response:
OUTPUT when I run AT+CIFSR command:
Response: A
Response: T+CIFSR
Response:
+CIFSR:APIP
Response: ,"192.168.4.1
Response: "
+CIFSR:APMA
Response: C,"5e:cf:7f:80
Response: :f7:74"
OK
Question now is: How do I store the string being returned from the esp8266. I thought my response string was suppose to store the "OK" but that did not happen.