Skip to content

Manually Deploy

Compile the Sketch

The entire sketch folder (YOUR_SKETCH_NAME).ino that contains all the source code must be compiled into a single .hex file using the compile command.

arduino-cli compile -b arduino:avr:uno testSketch.ino -v
Flag Description
-b Defines the fully qualified board name of the attached microcontroller.
-v Enables verbose output. (Required)

Documentation for the compile command

Finding the Binary

You will need to scan the verbose output for the name of the generated destination folder containing the compiled testSketch.ino.hex file. The path will look like: /tmp/arduino/sketches/(SOME_ARBITRARY_HASH)/testSketch.ino.hex

Compiled .hex File Found in Verbose Output

Flash the Arduino

Most guides online will suggest using arduino-cli to flash the Arduino (arduino-cli just calls AVRDUDE under the hood after all). However, this is apt to fail because arduino-cli times out very quickly. To avoid this, just call AVRDUDE yourself.

Command line parameter flags are case-sensitive and the same character is often re-used for unrelated functions. For example the AVRDUDE -c and -C flags.

avrdude -e -F -c arduino -p m328p -U flash:w:(YOUR_PATH_HERE)/testSketch.ino.hex
Flag Description
-e Chip memory is erased prior to flashing.
-F Skips a device signiture verification
-c Sets the programmer-id
-p Sets the part number
-U Memory operation

The -e flag ensures that the chip memory is erased prior to flashing. Not every microcontroller requires this but explicitly erasing the memory will also side-step complications related to a previously botched flash attempt.

The -F flag skips a device signiture verification step. This parameter may be optional for you but I found it necessary.

The -c flag sets the programmer-id to be used. This is board-dependant.

The -p flag defines the part number of the destination board.

The -U flag defines what memory operation is to be performed by AVRDUDE. The format of this value must be:
MEMORY_TYPE:OPERATION:FILENAME

Our MEMORY_TYPE is flash, OPERATION is w for write, and FILENAME is the path to your .hex file. The resulting string is:
flash:w:(YOUR_PATH_HERE)

Config File Error

You might get this command to work as described but I have found that, for now, an additional config file argument must also be passed. Otherwise the following error occurs:

avrdude: can't open config file […]

Missing avrdude.conf File Error

I believe this is error with either the current AVRDUDE or arduino-cli package that will eventually be fixed. For now, you'll need to download this file yourself and reference it in your call to AVRDUDE. The file can be found on the official Arduino GitHub repository for arduino-flash-tools. I've also provided a (possibly deprecated) copy in the remote-arduino-deployment GitHub repo. If needed, add the config-file paramter -C with the path to avrdude.conf.

avrdude -c arduino -p m328p -U flash:w:(YOUR_PATH_HERE)/testSketch.ino.hex -C ~/avrdude.conf

Port Error

If you run into the error, avrdude: ser_open(): can't open device, you need to specify your desired port with the -P argument.

Connection Port
GPIO Pins /dev/ttyACM0
USB /dev/ttyS0
avrdude -c arduino -p m328p -U flash:w:(YOUR_PATH_HERE)/testSketch.ino.hex -C ~/avrdude.conf -P /dev/ttyACM0

Sync Error

Expected error

This failure is expected. For the Arduino's boot loader to accept an upload, it must be physically reset. You can hold down the Arduino’s reset button, submit the command in the terminal and immediately release the reset button to achieve this manually.

Success!

You have to get the timing right because the boot loader only accepts uploads for a short duration after a reset.

Now that we've proven everything works, we can automate this process.