3

Is it possible to burn arduino code programmatically?

I was thinking of one way and that is to download hex file from my online server. Store contents of the hex file in a string, and write that string to arduino flash, restart arduino and it should run new code in flash.

Can this be done? If not than please suggest me any other way to burn the code using C++ instructions.

  • You mean like create.arduino.cc/editor ? – jose can u c Jan 25 '18 at 18:46
  • 2
    it should be possible. ... store the new sketch on an external eeprom ... modify the bootloader so that it checks for the existence of the new program and loads it – jsotola Jan 25 '18 at 19:17
5

First, the Arduino Uno has 32 KB of flash, but only 1 KB of RAM. So, to be able to store the new program in a string means your new program can only be, at most, 1kb.

Secondly, only the bootloader can write to flash. So you could write a new bootloader that downloads the new program (in parts) and writes it to the flash. You would however need quite a big bootloader, leaving less space for actual code. Also the main program still needs to access the server to see if it needs to "reboot" so the bootloader can run the update process.

An example of an OTA bootloader can be found at https://www.rotwang.co.uk/projects/bootloader.html which might be a good starting point. Similar idea https://ncrmnt.org/2014/02/27/rf24boot-a-universal-over-the-air-bootloader-for-all-those-ucs/

Another option is to write the new firmware to an external EEPROM. Then your modified bootloader only has to read the new firmware from EEPROM, making it a lot simpler and smaller. There is some useful info in the question OTA updates for Arduino using nRF24L01+

MySensors.org already made such a bootloader: https://www.mysensors.org/about/bootloader

I know there exists another bootloader that does just that, but I can't seem to find it.

  • Does arduino uno have internal (built-in) EEPROM? If yes, then can we use this internal EEPROM instead of using the external? – Muzahir Hussain Jan 27 '18 at 10:09
  • 1
    Internal EEPROM is only 1kb if I remember correctly. So too small to be of use. – Gerben Jan 27 '18 at 10:38
  • Which EEPROM would you suggest me? – Muzahir Hussain Jan 27 '18 at 10:44
  • 1
    There are only two options. SPI or I2C. The choice depends on which bootloader you use/write. And maybe which other devices you have attached to the Arduino. – Gerben Jan 27 '18 at 10:46
  • 1
    The guys at phoenard.com wrote a bootloader that loads compiled code from the SD card. – dda Jan 30 '18 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.