Uploading sketches to ESP8266 via Arduino Mega

Hello everybody,

I can't figure out how to upload sketches to my ESP12-e via the Arduino Mega. I don't have a separate TTL-to-USB controller.

I was able to connect to the ESP via Serial2, send AT commands and receive answers in the serial monitor, however I want to use the ESP without an Arduino, i.e. I have to upload sketches directly to it. I know that for using the AduinoUNO as TTL-to-USB controller you have to connect Reset to GND, so I did this with the Mega as well.

My questions: 1. Generally is it possible to use the solely the Mega + Arduino IDE? 2. Is it important which Serial I use? (So far I tried Serial2 and Serial) 3. If I want to upload I usually have to select the COM port. Do I select ArduinoMega in this case? (I don't see anything else anyway...)

The sketch I want to upload is the ArduinoOTA from github so that later I can upload sketches via Wifi.

https://github.com/esp8266-examples/ota-basic

suschi: Hello everybody,

I can't figure out how to upload sketches to my ESP12-e via the Arduino Mega. I don't have a separate TTL-to-USB controller.

I was able to connect to the ESP via Serial2, send AT commands and receive answers in the serial monitor, however I want to use the ESP without an Arduino, i.e. I have to upload sketches directly to it. I know that for using the AduinoUNO as TTL-to-USB controller you have to connect Reset to GND, so I did this with the Mega as well.

My questions: 1. Generally is it possible to use the solely the Mega + Arduino IDE? 2. Is it important which Serial I use? (So far I tried Serial2 and Serial) 3. If I want to upload I usually have to select the COM port. Do I select ArduinoMega in this case? (I don't see anything else anyway...)

The sketch I want to upload is the ArduinoOTA from github so that later I can upload sketches via Wifi.

https://github.com/esp8266-examples/ota-basic

I'm assuming you want to use the Mega board as just a programmer?

If so, you are not actually using the Mega, Grounding Reset, removes the Mega from interacting with the PC.

What you are actually doing is using the atmega16U as a USB -> serial interface. So you need to reverse the TX, and RX. You have been connecting the TX of the ESP to the RX of the Mega. Now you want the ESP to talk to the 16U, So you need to connect the TX of the ESP to the TX0 pin of the Mega, The RX pin of the ESP to the RX0 pin of the MEGA. With Reset Held Low, the MEGA is asleep, and you should have connection from the PC -> 16U -> ESP.

Try that.

Chuck.

You need to get the ESP8266 boards for the IDE. There are several out there, pick whichever you run into first.

Then it uploads like any other Arduino board.

chucktodd: I'm assuming you want to use the Mega board as just a programmer?

Yes, because I don't have an USB-to-Serial board, e.g. the Sparkfun FTDI.

chucktodd: If so, you are not actually using the Mega, Grounding Reset, removes the Mega from interacting with the PC.

What you are actually doing is using the atmega16U as a USB -> serial interface. So you need to reverse the TX, and RX. You have been connecting the TX of the ESP to the RX of the Mega. Now you want the ESP to talk to the 16U, So you need to connect the TX of the ESP to the TX0 pin of the Mega, The RX pin of the ESP to the RX0 pin of the MEGA. With Reset Held Low, the MEGA is asleep, and you should have connection from the PC -> 16U -> ESP.

I connected everything as you suggested. TX to TX0, RX to RX0, connected the Reset pin directlty to ground. The arduino IDE still shows that the Mega is connected to the COM port, is this correct or should I see something different here?

I tried uploading the sketch, but get the following errors:

warning: espcomm_sync failed error: espcomm_open failed error: espcomm_upload_mem failed error: espcomm_upload_mem failed

You need to get the ESP8266 boards for the IDE. There are several out there, pick whichever you run into first.

I downloaded the additional ESP via the board manager and tried different boards: "generic ESP8266", "NodeMCU ESP-12E Module" etc. None of them works

Thanks for the help already.

suschi: Yes, because I don't have an USB-to-Serial board, e.g. the Sparkfun FTDI. I connected everything as you suggested. TX to TX0, RX to RX0, connected the Reset pin directlty to ground. The arduino IDE still shows that the Mega is connected to the COM port, is this correct or should I see something different here?

Yes, the identification is between the PC and the 16U

suschi: I tried uploading the sketch, but get the following errors:

warning: espcomm_sync failed error: espcomm_open failed error: espcomm_upload_mem failed error: espcomm_upload_mem failed

I downloaded the additional ESP via the board manager and tried different boards: "generic ESP8266", "NodeMCU ESP-12E Module" etc. None of them works

Thanks for the help already.

Open up the Arduino environment. Open the Serial Monitor. Set the baud rate to 115200. Powercycle the ESP

you should see a line of garbage characters in the Serial Monitor window

type:

AT {then press enter}

you should see

OK

type:

AT+RST {then press enter}

You should see:

OK [System Ready, Vendor:www.ai-thinker.com]

If you cannot get manual communication with the ESP, there is no way the Arduino Environment can. So you will have to validate the connections,

Chuck.

I still didn't manage to get a connection via the serial monitor.

Here is how everything is connected (taken from http://www.instructables.com/id/Getting-Started-with-the-ESP8266-ESP-12/step3/Make-the-connections/):

[u]ESP[/u] GND --> Ground GPIO15 --> Ground Vcc --> 3.3V CH-PD --> 3.3V GPIO2 --> 3.3V GPIO0 --> 3.3V (HIGH for AT mode), for flashing, i.e. uploading a sketch I'd put it ground TX --> LD1117V33 --> TX0 (Arduino) RX --> RX0 (Arduino)

[u]Arduino[/u] RESET --> Ground

I use an external power supply (8V, 1A) to power both arduino and ESP. The ESP is connected to voltage regulator (LD1117V33).

When using a baud rate of 74880 it shows:

Fatal exception (0): epc1=0x40100002, epc2=0x00000000, epc3=0x00000000, epcvaddr=0x00000000, depc=0x00000000

After a quick search, I figured out that my ESP might be broken :( . I have a few more of these so I'd like to try it again. I wonder: Is anything I described fundamentally wrong? Might be that I broke it before though.

TX   --> LD1117V33  --> TX0 (Arduino)
RX         --> RX0 (Arduino)

Arduino
RESET    --> Ground

Looks like a serial download is being attempted?
In which case, Arduino only needs a pulse to Gnd to kickoff the bootloader; not holding it low continuously.

CrossRoads: Looks like a serial download is being attempted? In which case, Arduino only needs a pulse to Gnd to kickoff the bootloader; not holding it low continuously.

I tried to give it pulse but it didn't work. However, I managed to bring my ESP back to live. After multiple resets it works again. I can now communicate with it via the serial monitor,i.e. it responds to AT commands.

Finally after adding some pullup resistors and reseting the ESP before uploading the sketch I was able to upload my sketch.

Thank you very much for your help.

Which pull-up resistors did you add and where? I'm stucked exactly in the same part as you, what pin configuration did you use to get the ESP to upload sketches?