Software Serial not working with ESP8266-01

Hi,

I am trying to use the ESP-01 as a cheap Wi-Fi shield for my Arduino Mega. For one of my projects, I need to use numerous digital pins and control some signals wirelessly. To do this, I thought to use serial communication between the ESP and the Arduino to give the Arduino some Wi-Fi capabilities.

The ESP works perfectly well and can connect to my Wi-Fi. However, when I try using the software serial in the ESP, it stops working.

Here is the basic test code I have:

#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>

const char* ssid = "*******7";
const char* pass = "**********t";    

SoftwareSerial arduinoSerial(0, 1);   // Rx, Tx

void setup() {

  Serial.begin(115200);
  arduinoSerial.begin(9600);

  // Connect to WiFi
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED){
    delay(500);
    Serial.println("Connecting to Wi-Fi...");
  }
  Serial.println("Connected to Wi-Fi");
}

void loop() {
  arduinoSerial.print(1);
  Serial.println("Sent 1");
  delay(2000);

  arduinoSerial.print(0);
  Serial.println("Sent 0");
  delay(2000);
}

This code flashes normally onto the ESP, however, when powered, the ESP does nothing. When I remove the software serial lines from this code, eg. arduinoSerial.begin(9600), arduinoSerial.print(1), etc, the code functions fine.

Is there something I am missing or doing incorrectly?

Any suggestions would be appreciated.

Thanks.

Change pins, GPIO1 is a Tx pin of the hardware serial you are using for debugging.

why are you using SoftwareSerial on the ESP-01 - just use Serial

have a look at post arduino-mega-esp8266-esp-01s which gives some example code for connecting a Mega and ESP-01

In fact the easiest solution is to use hwSerial 0 (Serial) for communication this is GPIO 3 (Rx) & GPIO 1 (TX) , You can use Serial1 which is TX only (available that is, there is RX, but it is used internally) on GPIO 2 for debugging purposes. swSerial on an ESP is usually not such a good idea, but regardless, after you start you current swSerial object, hwTX is disabled, a pin on an ESP if used for a special function can not be used for anything else, and keeps it's last defined function.