When ESP8266 is connected to Mega via TX/RX - cannot upload new sketches

I have attached an ESP8266 to a mega via Serial (TX/RX).

When the ESP8266 gets an HTML command it can pass instructions to the Mega. This all works fine. What I realized is when the two devices are connected over TX/RX I cannot upload fresh sketches to either device. I have to disconnect them.

Anyone know a way around this? This devices will be in a project box in a hard to reach place when they go into "Production" and it will be a terrible inconvenience to disconnect them in the event I have to change sketches.

Thanks!

That's to be expected. Those pins are also used for uploads so the ESP8266 interferes. Luckily you have 3 more hardware serial ports on your Mega, just connect the ESP8266 to a different one and update your code accordingly.

Like Pert suggested use another serial port. Do not use the rx/tx used for usb on the Mega.

For the ESP you have two options.

  1. Either use Software serial and use other pins on your ESP.
  2. Implement the 'Webupdater' sketch from the ESP8266 library in your code. This way you can upload new firmware through a webpage.