I don’t really understand the part where you said that you’ve flashed new AT firmware to your ESP-01 using the Arduino IDE. As far as I’m aware, that’s not possible.
I also don’t understand this part…
It sounds like you are trying to upload the sketch to the ESP-01, rather than the Mega.