Uploading a sketch from a binary file

Is it possible to upload a samd based arduino a sketch from a binary file? If so, how?


Do this:

File > Preferences

Check the box next to "Show verbose output during: upload".

Click the "OK" button.

Upload a sketch to your Arduino board.

After the upload finishes, examine the contents of the black console window at the bottom of the Arduino IDE window. You will need to scroll up to see it all. There you will find the upload command the Arduino IDE generated. It might look something like this:

C:\Users\per\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.7.0-arduino3/bossac.exe -i -d --port=COM11 -U true -i -e -w -v C:\Users\per\AppData\Local\Temp\arduino_build_693683/Blink.ino.bin -R

Copy and paste that command to a text editor. Change the filename of the .bin file to the file you want to upload. If the paths contain spaces, wrap them in quotes.

Press release the reset button on your Arduino board quickly twice. You should now see the onboard LED pulsing to indicate it's in bootloader mode.

Open a command prompt.

Run the modified command from the command prompt. The .bin file should be successfully uploaded.

1 Like

Is there a way to upload the binary without manually resetting the arduino board? How is the board entering bootloader mode when normally uploading a code using the IDE?

Thanks again!

There is some special code that runs in the background of your sketch. When the board’s CDC serial port is opened at 1200 baud this is a signal to that code to reset the board and activate the bootloader. So when the upload process starts, the Arduino IDE opens the port you have selected from the Tools > Port menu at 1200 baud. When the bootloader runs, the operating system enumerates the port, so the IDE has to wait for that to happen before starting the upload. It also can’t assume that the bootloader’s port will be the same as the sketch’s port, so what it does is watches for a new port to appear, and assumes that is the port of the board’s bootloader. You can see this happen in the upload output in the IDE:

Forcing reset using 1200bps open/close on port COM8
PORTS {COM1, COM3, COM8, COM254, COM255, } / {COM1, COM3, COM254, COM255, } => {}
PORTS {COM1, COM3, COM254, COM255, } / {COM1, COM3, COM68, COM254, COM255, } => {COM68, }
Found upload port: COM68
C:\Users\per\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.7.0-arduino3/bossac.exe -i -d --port=COM68 -U true -i -e -w -v C:\Users\per\AppData\Local\Temp\arduino_build_876873/sketch_feb24a.ino.bin -R

So you could run a command that replicates the IDE’s behavior, but it seems much more simple to me just to manually activate the bootloader.