ESP01 only works with hardware UART

Hello,
I have a few ESP01 board and they work fine when attached to my nan0 TX1 and RX0 pins. I can type AT commands in the serial monitor and it responds and connects to my wifi network.
However, in my real application, I am using SoftwareSerial using 2 digital lines and it fails to respond. I can see the blue light on the ESP when it receives something from the nano but no reply. Any thoughts? I have tried multiple combinations of pins and baud rates. No change. I have also tried the voltage divider from the nano tx line but that had no effect and doesn't appear needed as all works well using the built-in serial interface. My sketch is here:

#include <SoftwareSerial.h>

SoftwareSerial wifi(5,6);   

void setup()
{
int commandDelay = 2000;
String cmd;

  pinMode(5,INPUT);
  pinMode(6,OUTPUT);

  Serial.begin(9600);

 wifi.begin(9600);

  cmd = "AT+RST";
  Serial.println(cmd);
  wifi.println(cmd);
  delay(commandDelay);
  readAndPrintResponse();


  cmd = "AT+CWMODE=3";
  Serial.println(cmd);
  wifi.println(cmd);
  delay(commandDelay);
  readAndPrintResponse();

... send other commands here...
}

void readAndPrintResponse()
{

  while ( wifi.available() > 0 )
  {
    char c = wifi.read();
    Serial.print(c);
  }
  Serial.print("END\r\n");
  
}

Not clear enough to me, sorry. As far as I can see, you have a Nano connected to an ESP01 (which one exactly? ESP01-S?) to be used as a "Wifi shield", right?
First, are you sure you're crossing the signals (e.g. connecting TX to RX and RX to TX), and GND in common?
Then why don't you as first try a simple test sketch like this one and see what happens?

#include <SoftwareSerial.h>

#define rxPin 5
#define txPin 6

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

void setup()  {
  // Define pin modes for TX and RX
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
    
  mySerial.begin(9600);
  delay(1000);
  mySerial.println("AT+CWMODE=3");
  delay(100);
}

void loop() {
  if (mySerial.available() > 0) {
    Serial.print(mySerial.read());
  }
}

Lastly, why using the ESP-01 as a WiFi "shield" for an Arduino instead of using it directly? ESP01 is a good microcontroller (ok, to be able to program it you need an USB-serial adapter like this one but it's not so complicated, and you can still use the same IDE). Or, better, just use another ESP-based board that has WiFi on it to begin with, e.g. like WeMos D1 R2 or Mini boards?

1 Like

Thanks alot for reply. I am using an ESP-01 (no dash S) and I am using a nano because it will be doing alot of other things besides interfacing with wifi and I need alot of IO, etc. Plus, I wasn't exactly sure that the ESP01 could even be programmed that way...

In any case, your sketch did help and I figured out that I simply needed to delay a little longer after each command is sent before I start reading back the response. I was waiting 2000 ms and that didn't work but when I changed to 3000 it works fine. Very strange.
Thanks again for your help.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.