ESP8266 12e with Mega2560 Communication

I have the Mega2560, and am trying to send an email through the ESP8266 12e, however it seems that the two boards are not connecting with each other.

I have the RX and TX of the ESP8266 connected to RX1 and TX1, and EN and VCC connected to the 3.3V pin of the Mega2560.

I then run the below code, and when I send "AT" I get no responses.

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

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

I have tried changing the baud rate and nothing seems to work.

I appreciate the help!

Although the ESP8266 has 2 serial ports only the first one has both TX and RX available. Serial1 is Tx only. Serial is used for the USB connection....

This drove me nuts when I first got an ESP8266, then I discovered:

  Serial.swap();    //GPIO15 > Tx, GPIO 13 < Rx

Which moves serial onto the pins as noted above.

Oh, and ++Karma; for posting your code correctly on your first post :slight_smile:

OK, so I am a muppet for not downloading your schematic before commenting! :confused:

My original comment stands.

Your code uses serial1, you have connected to serial0.

You have connected Tx to Tx and Rx to Rx, not sure how you think that's going to work.

You have not connected the ground between the ESP and the controller.

Your text says ESP8266, your schematic says ESP12E, which is correct?

Thank you so much for your help (and the karma!)

Hopefully it is readable, but I went ahead and did the connections myself on the attached image (not professional grade though) The original was one from a components101.com website.

Sorry, I am using the ESP12E, I thought that it the 12E was the version of the ESP8266.

As for TX to TX and RX to RX, what I read online said that for this board you were supposed to do them this way, however, as I did my testing, I would always swap them each time just in case (though nothing would work), I'll switch them though, thanks for the heads up!

As for my code, I think I am getting which serial is for which confused, I am fairly new to Arduino. If I want to send commands over the Arduino IDE terminal to test for connection (such as the "AT" command) how should I setup the code? When I tried using the "Serial.swap();" I got "'class HardwareSerial' has no member named 'swap'" is there something else I need to add, such as including a library?

To clarify, when I do the swap function, I should have the ESP12E GPIO15 and 13 be connected to the Mega2560 TX1 and RX1, correct?

your sketch is a SerialPassthrough sketch. so the commands from Serial Monitor are copied in Mega to esp8266. the wiring RX to RX is used if the ATmega MCU is not used and the esp8266 is connected to the USB chip of the board over the common RX/TX pins.

the first comment by PerryBebbington is not applicable here. it is about esp8266 sketches. you have AT firmware in the esp8266.

so wire the esp8266 to RX1, TX1 of the Mega crossed RX to TX. do not forget to wire the ground together.

and don't forget in Serial Monitor to set the line ending to 'both'

Juraj:
and don't forget in Serial Monitor to set the line ending to 'both'

To set the line ending tab at what option of the following:

  1. No line ending
  2. Newline
  3. Carriage return
  4. Both NL & CR

GolamMostafa:
To set the line ending tab at what option of the following:

  1. No line ending
  2. Newline
  3. Carriage return
  4. Both NL & CR

to 'both'

Juraj:
to 'both'

There is no option such as both.

GolamMostafa:
There is no option such as both.

4 is Both

Juraj:
4 is Both

Now, I understand that Both is the short-cut for 'Both NL & CR'. :slight_smile:

GolamMostafa:
Now, I understand that Both is the short-cut for 'Both NL & CR'. :slight_smile:

2 is NL, 3 is CR, 4 is both

Juraj:
2 is NL, 3 is CR, 4 is both

There is something RONG that is going on among you, I, and this Thread!

GolamMostafa:
There is something RONG that is going on among you, I, and this Thread!

I don't know what is RONG, but I think if someone understands the line ending characters problematic, then the meaning of 'both' is clear. you can use no line ending, one of the two possible line ending characters or both line ending characters .

It is like if someone asks with hands behind the back. "In which hand I have a candy?"

I said Newline is in 2. (2. Newline).

You are saying '2 is NL'; '3 is CR'; '4 is both'; whereas, a while ago you agreed that it is not both but Both.

GolamMostafa:
I said Newline is in 2. (2. Newline).

You are saying '2 is NL'; '3 is CR'; '4 is both'; whereas, a while ago you agreed that it is not both but Both.

I say "both (line ending characters)", like the answer to the candy question could be "both (hands)"

Juraj:
I say "both (line ending characters)", like the answer to the candy question could be "both (hands)"

Now, it is coming to closer: Both (line ending characters -- the NL & CR).

This is a perfect example of why taking a few extra seconds to be very specific in your forum writings, documentation, tutorials, etc. can end up saving so much time and confusion in the end.

To have written:

Select "Both NL & CR" from the line ending menu at the bottom of the Serial Monitor window".

would take so little extra time for anyone with a reasonable WPM typing rate and leaves no room for misinterpretation.

I usually do this for the sake of the confused beginners because I know from personal experience how incredibly frustrating it can be trying to follow instructions when the author left out things that were obvious to them. When everything is going wrong, it is a great comfort to have extremely explicit instructions that don't assume anything.