Trouble Programming ESP8266 12 from Mega 2560

I am trying to program an ESP8266 12E (or possibly 12F) with my Arduino Mega 2560 with "ESP8266_LED_Control" Sketch found widely on the internet. I believe I have all the settings correct, but keep getting the following errors:

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

Settings:
Board: Generic ESP8266
Flashmode: DIO
Flash Frequency: 40
CPU Frequency: 80
Flash Size 1M (512 Spiffs)
Debug Port: Disabled
Debug Level: None
Reset Method: CK
Upload Speed 115200
Port: COM3

Arduino TX LED flashes as does the ESP LED. For about 8 times, then upload fails.
I believe I have correctly set the ESP into programming mode and all connections are correct.

Any help will be appreciated.

How do you have the Mega connected to the ESP8266? Typically when someone connects a standard Arduino board to an ESP8266 they are running the sketch on the Arduino and only using the ESP8266 for WiFi communication controlled over serial with the AT firmware. You are trying to program the ESP8266 directly. Are you only using the Mega as a USB to serial adapter? I'm sure that could be done but I've never heard of it. Please post a link to the instructions you're following.

mrarduinoman:
"ESP8266_LED_Control" Sketch found widely on the internet.

Please post a link to it. We shouldn't have to go hunting all over the internet and try to figure out if it's the same sketch just to try to help you.

Here is the link I've based my work on.

Here is the ebay link to the ESP board I am using.

http://www.ebay.com/itm/1PCS-ESP8266-10A-220V-Network-Relay-WIFI-Module-NEW-/201618918381?hash=item2ef16c8bed:g:FFUAAOSwRQlXfj9o

Step 7 talks about how to set up the Arduino as a serial programmer.

  • I have the proper RX/TX and ground connections. I'm powering the ESP from a separate power supply. I ground GPIO0 and power up the ESP (Since I don't have a reset button).
    -The only thing in this step I am unclear about is the SoftwareSerial include file. I don't really know what that is, or where to get it.

I have Arduino IDE settings as described in the next few steps.

I have to believe the factory sketch is not on the ESP, since it already has the Chinese program on it for light control. And it does not respond to AT commands.

Step 16 has the LED_Control sketch that I'm using. Modified for my own SSID/PW.

Step 17... the blue LED on the ESP flashes about once per second for 6-8 times (as does the TX on the Arduino). But then the error messages and failed flash.

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

I never got to steps 18-20.

Thanks for helping.

UPDATE:
With serial monitor running, when I power up the ESP in programming mode I get a bunch of garbage text... I assume it is the initialization.

In Run Mode I get after the garbage text:

add if0
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
add if1
bcn 100
S > create socket: 0
S > bind port: 80
S > listen ok
S > wait client

So it seems the Arduino is communicating with the ESP.

Also realized what the SoftwareSerial include library is and put that in the sketch.

mrarduinoman:
when I power up the ESP in programming mode I get a bunch of garbage text... I assume it is the initialization.

That's a very frustrating thing to me. Apparently the bootloader runs at 74880 baud(which is the cause of that garbage text) but then there's other output after a crash at 115200 so I get gibberish either way I set the baud rate. Maybe there's a way to change it that I haven't found yet. You might have a look with the serial monitor at 74880 just to see what the bootloader is saying.

I'll give the lower baud rate a try tomorrow and report back. I can't get to it today. Thanks.

I ran a quick serial monitor test at 74880.

In program mode it reads the following:

ets Jan 8 2013,rst cause:1, boot mode:(1,7)

In run mode it reads:

ets Jan 8 2013,rst cause:1, boot mode:(3,7)

load 0x40100000, len 26044, room 16
tail 12
chksum 0x6d
ho 0 tail 12 room 4
load 0x3ffe8000, len 4744, room 12
tail 12
chksum 0x3a
ho 0 tail 12 room 4
load 0x3ffe9290, len 1880, room 12
tail 12
chksum 0xde
csum 0xde
OS SDK ver: 1.4.0(c599790) compiled @ Mar 1 2016 17:25:17
phy vèoÈ

followed by some garbage text.

Not sure what that means, or if it helps... Thanks.

I have no real experience with the arduino. Is there a way to program the sketch to start uploading at 74880 then switch to 115200? Essentially overriding the setting in the menu?

There's a Tools > Upload Speed menu but I have mine set to 921600 so that doesn't seem to have anything to do with the 74880 baud of the bootloader output.

mradruinboman:
I have no real experience with the arduino. Is there a way to program the sketch to start uploading at 74880 then switch to 115200? Essentially overriding the setting in the menu?

Have you tried upload NodeMCU firmware to that esp8266?

If not, should try. After uploading successfully, your esp8266 will be set to 115200 as default and you can upload your new Arduino sketch following the tutorial which you are referring.

You can do upload firmware as the article: Flashing Nodemcu firmware on ESP8266 using Windows Lua firmware

After finished uploading, the upload tool (nodemcu-flasher) should be look like:

Good luck and have fun.

Hi,

had the same issue, same errors.
Found to try this:

ESP8266 - Arduino NANO (reset to GND permanently on NANO, my nano is converted to 3.3V!)

TX - TX
RX - RX
VCC - VCC
GND - GND
RST - VCC
EN (CH_PD) - VCC
GPIO0 - GND
GPIO15 - GND

Then i was able to connect and upload code with no problems.