ESP8266 Not communicating with Arduino Mega

I made the following circuit and I am just trying to send some basic AT commands to the ESP

This is my code:

#define esp8266 Serial2
#define CH_PD 4 
#define speed8266 115200 // This is the speed that worked with my ESP8266
#define DEBUG true


void setup() {
  esp8266.begin(speed8266); 
  Serial.begin(speed8266);
  reset8266();

}

void loop() {
  //Serial.print("");
  sendData("AT", 2000, DEBUG); //Connect network
  delay(1000);
}


 // Send AT commands to module
String sendData(String command, const int timeout, boolean debug)
{
  String response = "";
  esp8266.print(command);
  long int time = millis();
  while ( (time + timeout) > millis())
  {
    while (esp8266.available())
    {
      // The esp has data so display its output to the serial window
      char c = esp8266.read(); // read the next character.
      response += c;
    }
  }
  if (debug)
  {
    Serial.print(response+"\r\n");
  }
  return response;
}

void reset8266 ()
{
  pinMode(CH_PD, OUTPUT);
  digitalWrite(CH_PD, LOW);
  delay(300);
  digitalWrite(CH_PD, HIGH);
}

This is the output from serial monitor:

Please help me I don't know what to do...

If I connect
ESP Tx-> Arduino TX0
ESP Rx-> Arduino RX0
Arduino Reset->GND
ESP CH_PD-> 3.3V

I can easily send commands over the Serial Monitor and it works properly

so you level shift RX TX but wire 5 V to EN pin?

Yes.. At least I made it work in the last half hour.. I suppose it is not that great.. Any idea on how I could rewire it better with what I have there?

wire the EN pin to 3.3 V. you can reset the esp8266 with AT+RST.

If you can update the AT firmware in the esp-01 to 1.7+, you could use my WiFiEspAT library. It would handle the AT commands for you and provide the standard Arduino WiFi API so you can use many existing examples and libraries.

https://github.com/jandrassy/WiFiEspAT

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