I can successfully communicate with my ESP8266-01 using AT commands with an FTDI 3v3 Flasher. I can also successfully communicate with the ESP-01 using the AT command set using the Arduino serial monitor interface via USB with a 'blank' sketch uploaded to the Nano. The baud rate set is 115,200 and this has been confirmed when interrogating the ESP using the Espressif Flasher and works fine with both approaches above. So far things are good. But, when I attempt to issue AT commands via a basic sketch using the Software.serial library I can't get any response to any AT command.
I have included the sketch below which is my baseline and is essentially courtesy the 'AllAboutEE' website. This seemed an excellent starting point for the WiFi solution before integrating the data logging part of my project - which is working. I included 'DEBUG' statements at various points in the code. TX and Rx have been interchanged to eliminate this as the cause and the baud rate set according to earlier successful comm attempts. The hardware setup which has worked for the 'blank sketch' approach is also unchanged.
'DEBUG1' which monitors ESP8266.available status always appears to report 'False' state. 'DEBUG2' correctly displays AT commands issued to the ESP via the Serial Monitor and 'DEBUG3' does not provide evidence of output from the ESP to the Arduino. The Serial monitor is set to append AT commands with '\r\n' - CR and NL.
Can anyone suggest any changes to the Sketch to allow me to investigate the problem in more detail because as I see it I have a working ESP and hardware setup?
Many thanks in anticipation.
Mike
//GPIO: HIGH via external pullup
//CH_PD: HIGH via external pullup
//Tx ESP > Rx Arduino Nano
//Rx ESP >Tx ESP
//ESP Vcc > 3v3 Supply decoupled via 70 uF Capacitor
//ESP Gnd >> Arduino Gnd
#include <SoftwareSerial.h>
boolean x;
SoftwareSerial esp8266(3,2); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.
// This means that you need to connect the TX line from the esp to the Arduino's pin 2
// and the RX line from the esp to the Arduino's pin 3
void setup()
{
Serial.begin(115200);
esp8266.begin(115200); // Successfull baudrate for flashing device and comm via FTDI
}
void loop()
{
x= esp8266.available();
Serial.print("DEBUG1: ") + Serial.println(x);
delay(300);
if(esp8266.available()) // check if the esp is sending a message
{
while(esp8266.available())
{
// The esp has data so display its output to the serial window
char c = esp8266.read(); // read the next character.
Serial.write(c);
Serial.print("DEBUG3: ") + Serial.println(c);
}
}
if(Serial.available())
{
// the following delay is required because otherwise the arduino will read the first letter of the command but not the rest
// In other words without the delay if you use AT+RST, for example, the Arduino will read the letter A send it, then read the rest and send it
// but we want to send everything at the same time.
delay(1000);
String command="";
while(Serial.available()) // read the command character by character
{
// read one character
command+=(char)Serial.read();
}
esp8266.println(command); // send the read character to the esp8266
Serial.print("DEBUG2: ") + Serial.println(command); //Debug
}
}