It seems that I have a conflict between SoftwareSerial and the delay
function on my Arduino (GeekCreit bought on Banggood). I am trying to use SoftwareSerial to send AT commands to an ESP-01.
When I perform:
#include <SoftwareSerial.h>;
SoftwareSerial esp8266(8,9);
void setup() {
Serial.begin(9600);
while (!Serial) ;
esp8266.begin(9600);
esp8266.println("AT");
}
void loop() {
if(esp8266.available()) {
while(esp8266.available()) {
Serial.print(esp8266.read());
}
}
}
Everything works well, the AT command is sent and I receive the response from my ESP.
But when I add a delay before sending the AT command, nothing happens: no command sent, no answer from the ESP.
#include <SoftwareSerial.h>;
SoftwareSerial esp8266(8,9);
void setup() {
Serial.begin(9600);
while (!Serial) ;
esp8266.begin(9600);
delay(2000);
esp8266.println("AT");
}
void loop() {
if(esp8266.available()) {
while(esp8266.available()) {
Serial.print(esp8266.read());
}
}
}
Am I doing something wrong, has someone experienced the same problem?
I have tried to use AltSoftSerial instead but I have the same issue with it.