esp8266 the definition of insanity

So i bought 5 esp8266-01 from Amazon and I have been trying to connect them to my Mega for days. I have scoured the web and read tons of help posts. Nothing I do has been able to get the Mega to talk to the ESP. All I want to do is get it to respond to an AT command.

I have a very simply script that I am trying to use (after trying many different ones) and I have tried changing the baud rate as well as trying different pins and swapping rx and tx. Still nothing works. Her is the script:

void setup()
{
Serial1.begin(9600);
Serial.begin(9600);
Serial.println(“SoftSerial to ESP8266 AT commands test …”);
delay(100);
}

void loop()
{

if (Serial1.available())
{
Serial.write(Serial1.read());
}

if (Serial.available())
{
char command=Serial.read();
Serial1.write(command);

}
}

I have also attached my wiring Fritzing. Any help would be greatly appreciated.

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you’re using the Arduino Web Editor you will not have access to this useful tool. I recommend you to use the standard IDE instead.

The AT firmware runs at 115200 baud by default so you need to change:

Serial1.begin(9600);

to:

Serial1.begin(115200);

115200 with CR+LF

For me, I leave GPIO0, GPIO2, and RESET unconnected to anything, and CH_PD connected directly to 3.3V (I do not have a pull-up resistor on this pin).

I have five of these modules, and all of them have worked.

OK - I disconnected GPIO0, GPIO2 and Reset changed the code to Serial1.begin(115200). still does return anything from the esp.

Did you set the menu at the bottom of the Serial Monitor window to "Both NL & CR"?

Yep. Nothing I do seems to change the outcome. Still nothing is returned from the AT command. My code now is this:

void setup() 
{
Serial1.begin(115200); 
Serial.begin(9600);
Serial.println("SoftSerial to ESP8266 AT commands test ...");
delay(100);
}

void loop() 
{

if (Serial1.available()) 
{ 
Serial.write(Serial1.read()); 
}

if (Serial.available()) 
{ 
char command=Serial.read(); 
Serial1.write(command); 

}
}

and the new wiring diagram is attached.

I'm not too sure about this, but doesn't your code say that if data is received from the esp, then write it to the serial of the arduino? Don't you need somewhere in your code to read received data from the Serial of the arduino (so in the if (Serial.available()) {} block) and to have something like you already have, but changed Serial1.write to Serial.write()? I hope that makes sense

a well-written tutorial http://www.martyncurrey.com/arduino-to-esp8266-serial-commincation/

Thanks - I read that tutorial and ran the script posted - same results. Nothing back from the esp. Any other ideas?

Nothing worse than Fritzing diagrams. Are you applying a 5V output to a 3.3V input without using a level shifter?

No - I have a voltage divider to bring the Arduinos 5V down to 3.3v as shown in my Fritzing diagram. So I think I have the wiring right. It is the same setup as is in the tutorial.

OK - So I bought another esp8266 and hooked it to my arduino mega 2560 R3 and I get the same results - nothing when I send the AT command. Is there something I am missing with the arduino setup or in the script?
I really would like to get this to work so I can move on with my project.
I have tried both of these scripts.

#include <SoftwareSerial.h>
SoftwareSerial ESPserial(19, 18); // RX | TX
 
void setup() 
{
    Serial.begin(9600);     // communication with the host computer
    //while (!Serial)   { ; }
 
    // Start the software serial for communication with the ESP8266
    ESPserial.begin(9600);  
 
    Serial.println("");
    Serial.println("Remember to to set Both NL & CR in the serial monitor.");
    Serial.println("Ready");
    Serial.println("");    
}
 
void loop() 
{
    // listen for communication from the ESP8266 and then write it to the serial monitor
    if ( ESPserial.available() )   {  Serial.write( ESPserial.read() );  }
 
    // listen for user input and send it to the ESP8266
    if ( Serial.available() )       {  ESPserial.write( Serial.read() );  }
}

and

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  while(Serial1.available()){
      Serial.write(Serial1.read());
  }
  while(Serial1.available()){
      Serial1.write(Serial.read());
  }
}

and my wiring diagram is attached.

PLEASE HELP!

https://www.ebay.com/p/Ft232rl-FTDI-USB-to-TTL-Serial-Adapter-Module-for-Arduino-Mini-Port-3-3v-5-5v/1742242301

I do have a separate 3.3 v power supply (as shown in my fitzing) for the esp. Power is [u]no[/u]t coming off the arduino 3.3 pin.

Take the Mega out of the equation and just buy a USB-TTL adapter.

I'd take the level converter out by using a 3.3V Arduino such as a Teensy or Due.

How do you know what software is loaded on the ESP8266? Do they all come from the factory with firmware that will respond to AT commands? Is it possible that these ones have some other firmware?