automatic uploading of hex file from micro sd card at power up on Arduino Yun

Hello All:

Is there a way of uploading a precompiled sketch to an Arduino YUN by just inserting a micro sd card with the sketch .HEX file on it and powering up the yun?

I imagine the linux side has to have some sort of autoexecutable script that will look for the hex file on the sd card at boot time and if present, transfer it to the arduino side and then rename or delete the hex file so it is done only once. But, I am completely new to yun.

Any help will be greatly apreciated!


Sincerely Rod Magnus

Create /mnt/sda1/ which upload sketch.

nano /etc/rc.local
if [ ! -f runoncelock ]; then
    #echo "File not found!"
/bin/touch runoncelock

Thank you!

I will try it.

Sorry about the delay.

I did not see the answer previously.

Have a great day!


Hi to all,

I tried the solution on this thread. I was able to create the directory "". I was also able to edit the contents of the "rc.local" Prompted 22lines wrote.

My question is, inside the is the place where you will put the *.hex?

Best Regards, Leo

nano /mnt/sda1/
/usr/bin/run-avrdude  /www/sda1/bridge.cpp.hex
chmod 755 /mnt/sda1/

Test Run:


The run-avrdude command will load a pre-compiled sketch into the '32U4 processor. But it doesn't go through the bootloader, it replaces the entire memory contents. Therefore, the bootloader needs to be included into the sketch image before programming it. This command will do it:

/usr/bin/merge-sketch-with-bootloader.lua /www/sda1/bridge.cpp.hex

The key is that this should only be done once and only once to the file. If you try to upload the file more than once, you should make sure not to repeat that merge.

Can I safely run without the bootloader?

Flash bootloader only, in case we need USB flash again.

"Change the efuse value from FB to CB" might be no longer needed.

sonnyyu: Can I safely run without the bootloader?

OK, so appending the bootloader may be optional if you don't want to later use the USB port to upload code. But that should probably be explicitly stated so that the user can decide if they want the bootloader or not, and is aware that the programming over the USB port will no longer work if the bootloader isn't added to the hex file.

Otherwise, the person that does it will be back soon complaining that they can't load sketches over the USB port, and it will be very hard to debug the problem because the user won't realize that they had inadvertently deleted the bootloader.

I think the safest bet is to always include the bootloader, unless the user specifically decides that they don't want it, as in the first thread you linked.