Mega + WiFi R3 ATmega2560 + ESP8266 (8 Mb mémoire)

After I try many week, now it works. Follow this if you have the same to my cases:

  1. programm to the ESP(upload sketch) for wifi connection by configure the DIP to 5:on,6:on,7:on and other off.

  2. program to mega(upload sketch) in case you want to send communication to each other by configure Dip to 3:on,4:on, and other off.

  3. switch two RX0/TX0(in my case I use Serial.print() and Serial.readString() for communicate between Esp and Mega)

  4. after you already upload sketch to both Modules you can test communication between them by configure DIP to: 1:on,2:on,3:on,4:on. and then press Reset Button to restart the boards.

  5. In ESP you can get the string from Mega by if(Serial.available()) Serial.readString(); and In mega you can get data from ESP by : if(Serial.available())Serial.readString().

  6. After you got a string so you can split or do anything whatever you want.

  7. If you want send data to Firebase you must use the Firebase Library at the Esp side, in Mega it not support.

*** This work for me, I hope it can help you. Good luck.