Connect MEGA2560 to ESP8226 Module

Hello,

I have connected a ESP8226 to a MEGA2560 module. Here are the connections

ESP8226 TX connects to RX2 pin of MEGA2560 (Pin 17)
ESP8226 RX connects to TX2 pin of MEGA2560 (pin 16)
ESP8226 GND to MEGA2560 GND
ESP8226 5V to MEGA2560 5V.

The ESP8226 is going to be an independent module from the MEGA2560. It will receive commands from
WiFi connection and sends it to MEGA2560 via RX2/TX2 lines.

The ESP8226 is already programmed and loaded with a simple Web Page. There is a button
on the Web page. When the button is pushed the LED located on the ESP8226 module turns
on and off telling me that there is a good connection.

At the same time, the ESP send out a message like "Cabinlights_on" using the
Serial.print("Cabinlights_on\n"); or

Serial.print("Cabinlights_off\n"); depending on the state of the button pressed.

I verify the message by opening the Serial Monitor on the Ardunio environment. The serial port sees the
messages and they match the status of the LED.

Now I connect the MEGA2560 with its own program to receive the data from the ESP8226 using serial port 2.

I open the Serial Monitor to see if I receive anything.

Every time I push the button on the HTML web page, I see the LED on the ESP8226 turns on or off.
So I know the ESP8226 side is OK.
But I do not see anything on the MEGA2560. Nothing shows on the Serial Monitor.

I have tried a few examples reading the serial port. But I can not make the MEGA2560 get anything.
Is there a special way that ESP8226 needs to send out data to MEGA2560.

Thank You for your time.

Bobby

The ESP8266 is a 3.3V device. Connecting it to the Mega's 5V power supply and I/O pins will likely damage it. If not immediately, then eventually.

Hello,

This is a ESP8226 module made by Adafruit (HUZZAH). It says on the board that it operates
between 3.5 to 6VDC. I also checked the input voltage when it was connected to the USB
port of the computer. The voltage reading was +5VDC.

Thanks

Bobby

That's OK assuming your 5V is going into the 5V side of the voltage regulator on the Huzzah and not the 3.3V side.

But the 5V GPIO outputs from the Mega will damage the 3.3V GPIO inputs of the ESP. And, the 3.3V GPIO logic outputs of the ESP will have lower noise margin when read by the Mega's 5V GPIO inputs.

Hello,

There is no connections between the GPIO lines of the ESP8226 to the MEGA2560. The LED
is on the ESP8226 module and not the MEGA2560. The LED is used to make sure that the
ESP8226 receives commands from the HTML web page.

The only connection between the ESP and the MEGA2560 is the power, GND, and TX/RX lines.

My problem is that I do not receive any data on the MEGA2560 module via the TX/RX lines.

Thanks

Bobby

TX and RX are 5V logic levels too. Anyway, my last post on the subject. I've tried, forge ahead if you wish.

Check baud rates are compatible , and also whether you should connect Tx to Tx or to Rx .

Hello,

The ESP8226 is made by Adafruit. The specification says that it comes with a level shifter and
using 5VDC is OK. Here is the link to the board,

Adafruit HUZZAH ESP8266 Breakout : ID 2471 : $9.95 : Adafruit Industries, Unique & fun DIY electronics and kits.

I can buy a level shifter to try if you think that is the problem.

Regarding the Baud rate. Yes I made sure that they both match.

Attached are my programs on both sides. The SerialEvent is just one of the examples I found on Ardunio.
and the WiFi_CMS is my program loaded into the ESP8226. I did not include the Web Pages.

In the WiFi_CMS program Looking at the handleForm() function, you can see that under the

if (t_state=="LED")
{

I send out "CabinLights_on" or "Cabinlights_off" strings.

That is where the MEGA2560 should see the data coming in.

Thanks

Bobby

SerialEvent.ino (1.67 KB)

WiFi_CMS.ino (7.62 KB)