Remote Program Your Arduino with ESP8266

in another thread there was interest in projects that allows remote flashing an arduino from any location in the world. that was more about flashing the esp8266 itself so im starting this to avoid hijacking.

for my methods you need an arduino with rx and reset connected to tx and an io pin on the esp8266. those are the only two signals required. therefor potentially an esp01 can flash up to 2 dfferent avrs, esp12/esp07 up to 9. for software the arduino must have a simple bootloader installed and on the esp a small lua script. at the other location a regular internet browser running on cell, tablet, or pc. this demo tested with android browser and firefox.

for long distance there must be a hot spot nearby. for local flashing like in my house no ap or router needed, cell or pc can just talk direct to esp module. attached are my original lua script and bootloader file (bonet8.hex) for atmega8/arduinoNG. ESP8266Flasher-32.exe was used to install the lua interpreter in the module and esplorer to manage scripts. the bootloader was flashed with avrdude.

simple proof of concept first:

a good idea to test bootloader by connecting the arduino to a pc comm port and running hyperterm (9600,8,n,1 no handshake). hit ‘:’ within 7 sec after reset to enter boot mode followed by ascii hex code bytes. two consecutive ff bytes will terminate. if no colon within timeout then program runs.

resetting esp8266 in run mode should show as ssid “esp”. use cell phone or pc to connect and ip 192.168.4.1 to access the modules server. a button appears to reset via gpio2. maybe check this pin with led or scope to verify operation. finally the colon and hex to be flashed (see above) are appended after the “…4.1/” in the address bar. this is done by typing it in or cut and past from a hex file.

edit: forgot to mention baud and added some one machine instruction avr led examples. schematic too.

bonet8.hex.txt (661 Bytes)

init.lua.txt (1.29 KB)

ledfff8.txt (11 Bytes)

ledfff8.txt (11 Bytes)

esp_avr_v2.JPG

if there is interest i can attach more useful files and details.

Hi John,

can you still use the ESP8266 for regular Internet access?

I have a simple weather display that uses a ESP8266 that I have to dismantle to reprogram. Programming over wifi would be great but it needs to access the internet when not being programmed.

depending on what you mean by "regular" it probably wont work if it depends on default(at) firmware. the lua interpreter overwrites that. internet access is much easier with lua but not compatible with at commands.

i was able to do remote programming using the default firmware with the attached bootloader. its doable but a bit more difficult so i switched back to the hll.

Umm - is there more to this? You said you had more?

The first file just appears to be some hex dump (maybe this is the bootloader for the Arduino?) - not particularly useful, though - without decompiling. Please post the source code.

The second (lua) file appears to be a script (for the ESP8266 I presume) that just presents a page to a browser to allow you to toggle the GPIO pin (4) on and off - my knowledge of lua on the ESP8266 isn't great - but it didn't appear to do anything else with any other pin to transmit data from the ESP8266 to the Arduino via the custom bootloader...?

Again - more human-readable source code would do wonders for understanding here.

Finally (although, without seeing the actual Arduino bootloader code, and ESP8266 uploader code - so I may be talking out my posterior), your code, if it doesn't do it already, should have some kind of error-checking and correction built in, or it should listen (via another pin, if one is available - I know some revs of the ESP8266 board have more than a couple of pins available for GPIO) for acknowledgements or something to allow for error correction and re-transmitting of the data as needed.

Needless to say, I'm interested in this project - but only if more information and explanation is provided.

cr0sh: Needless to say, I'm interested in this project - but only if more information and explanation is provided.

The bootloader hex looks very small and as you say the Lua script does not seem to do much so I have been looking at the alternative from Jeelabs. Hopefully I will prove/disprove it's working in the next couple of days but see here for more details.

cr0sh: Umm - is there more to this? You said you had more?

i have many variations of the lua script including some with auto-reset or ability to wiggle both states. also bootloader versions that work with other avr families (ie mega328) and more standard file format. files posted were for the smallest & simplest implementation and are the ones used in my own home so i started there.

this is intended as a quick start demo for those wanting to experiment with remote flashing. not so much for involved discussion of mainstream bootloader design or complexities of lua interpreter. i think the jeelabs and espressif forum projects might be a better fit but orders of magnitude more complex. i did spend some time on those but not successfully. maybe a fault in my setup or bugs that have been ironed out since. id be very interested to hear of some success stories.

cr0sh: The first file just appears to be some hex dump (maybe this is the bootloader for the Arduino?) - not particularly useful, though - without decompiling.

to make this work an m8 hex file is all thats required. unfortunately this was created back in late 90's and ive just been copying from chips last few years. however i would be glad to clear up any specific questions.

cr0sh: - but it didn't appear to do anything else with any other pin to transmit data from the ESP8266 to the Arduino via the custom bootloader...?

those more familiar with this interpreter will see that any text appended to the url is buffered and sent out tx to the avr. in addition to the io control msg for resetting this includes the actual hex data to be flashed.

cr0sh: if it doesn't do it already, should have some kind of error-checking and correction built in, or it should listen

turns out bi-directional transfer or sophisticated error correction isnt really needed to implement a practical and reliable bootloader. in this case timeout coupled with ':' requirement has proven more than adequate. im sure the opti/mega crowd will disagree but this is my conclusion. in addition any non-intel hex character will cause the loader to hang harmlessly. generally before even one block is flashed.

medical or nasa space mission apps a different story, so ymmv.

based on some offline requests i am updating first post with couple small (1 instruction) examples to turn avr led on and off. small is good here because during tests its convenient to just key in code manually from a terminal. hyperterminal 'send text' works too and is more practical for bigger files.

im also attaching a schematic for those who like pretty pictures. hard to get any more basic.

btw i did forget to mention baud rate so that is added. 9600 was chosen because its default for lua. i prefer 57k as a compromise between speed and friendliness but only on other, not quite so minimal, setups.

@john1993 Do you have the bootloader for Atmega328P ?