QuickFix wrote:You actually only need to connect the TX of the ESP to the RX of the Arduino; there's no communication from Arduino to ESP, so you can leave that out.
Since the ESP outputs at 3.3V you can cut corners by directly connecting the ESP's TX to the RX of the Arduino (this can't be done directly the other way 'round though).
You're talking about a USB connection on your ESP, which means you're using a development board (NodeMCU, Wemos, ...) and not a plain ESP.
The USB to serial convertor on those boards is always connected (and powered) to the ESP, even when there's no USB cable connected to the board; this means that the convertor can (and possibly will) always influence your serial communication when using TX and RX directly from the I/O pins.
Fortunately, GPIO2 on the ESP doubles (as a special function) as a second serial TX connection and can be used for debug purposes.
Of course we can also use it for other things like, in this case, just a regular free serial output to control your Arduino.
In the ESP-Arduino core you can open this port as Serial1; don't forget to set the Baud rate your Arduino listens to.
After that you can write the commands to Serial1 that are needed to control the Arduino/switch.
Thank YOU!
Exactly! The baud rate was off......DUH!! What confused me on that was the Mega was sending clear text to the serial monitor (for debug of the Arduino Code) at 9600 , so it looked like it was good. Normally a bad baud condition gives gibberish. But the connection to the ESP which should have been 115200, was set wrong. So it kept sending 255 and 254 as the "characters" from the serial. This is what made me look in the wrong places.
Then the sending message Serialprintln('1'); confused me on the output showing in the Serial Monitor of the Arduino Mega, because it sends both a carriage return and a new line "13 and 10". The Mega is just wanting ONE thing at a time not having three things shoved at it into the switch. This would work but having two wrong things to sift through is stupid. I changed to Serialwrite('1'); and that solves the problem, no spaces no returns just the data of the char. Now when I press on the buttons on the wifi web browser it send the correct instructions and I get the right response from the PCB. This was a painful learning lesson. But I don't think I will ever NOT CHECK THE BAUD RATE again. I have a flat forehead now from slapping it so much. I heard it was a programmers condition to have a flat forehead.