1

I have a sketch for an Arduino Nano. I'm compiling it on my build server and get these 3 files:

  • project.bin.elf
  • project.bin.hex
  • project.bin.with_bootloader.hex

Now I need to be able to upload/flash them onto the board (connected via a serial interface) without arduino-cli. Mainly because I can't install it via apt-get which means I'd have to start jumping through loops to be able to use it (stuff like keeping it up to date, installing, etc. on hundreds of devices).
So I was wondering if there are any tools in the debian repositories I can use to upload the compiled sketch and if so how.

I've been looking for a solution and came across several answers and topic but strangely enough all either use arduino-cli, other specialized tools or link to dead pages or pages that no longer contain the answer.

Examples:

BrainStone
  • 113
  • 6
  • 1
    `avrdude` is your friend. – Kwasmich Feb 05 '20 at 08:50
  • 1
    upload Blink to Nano from IDE and then copy the avrdude command from IDE console and modify it to upload the project.bin.hex file – Juraj Feb 05 '20 at 09:14
  • @Juraj do I see this command on the Windows version too? Alternatively could I get ``arduino-cli`` to output the command? Because I have test boards available I can install anything on. (I just can't get it on every board) – BrainStone Feb 05 '20 at 10:04
  • turn on verbose mode – Juraj Feb 05 '20 at 12:51

1 Answers1

3

Use avrdude.

The command format is simple, assuming you have installed it from the Linux repositories:

avrdude -carduino -patmega328p -P/dev/ttyUSB0 -b115200 -Uflash:w:/path/to/project.bin.hex:i

Depending on what bootloader is installed in your nano you may need to change the baud rate (-b115200) to 57600. Also, of course, the USB device should be set to what your board actually identifies as.

The breakdown of the command is:

-c<programmer type>
-p<part name>
-P<port>
-b<baud rate>
-U<instruction>

The programmer type, part name and baud rate can all be gleaned from the boards.txt file in the AVR core files. For example, for the Nano:

nano.upload.protocol=arduino
nano.menu.cpu.atmega328.upload.speed=115200
nano.menu.cpu.atmega328.build.mcu=atmega328p

relate to -c -b and -p respectively. The instruction will always be the same, and means "Write to flash the following file in IHEX8 format". "flash" is the destination memory, "w" is the write command, and ":i" at the end defines the expected file format.

On a Linux computer with avrdude installed you can find much more information with man avrdude.

Majenko
  • 103,876
  • 5
  • 75
  • 133
  • That answers my question, but since SE is meant as an enciclopedia of sorts, I think it would be beneficial to explain how you figure out that command line call for other boards. (And also because I managed to find a similar call after some playing around and watching the processes in ``htop`` while trying to flash with ``arduino-cli``) – BrainStone Feb 05 '20 at 10:18
  • @BrainStone Like that? – Majenko Feb 05 '20 at 10:22
  • Excellent. Thank you very much – BrainStone Feb 05 '20 at 10:26
  • if you are unsure of the settings that you should use, then you can use the Arduino IDE to determine them .... in settings, turn on `show verbose output during upload` .... then upload any sketch .... in the status panel in the Arduino IDE you will see the correct `avrdude` command line .... something like `E:\arduino-nightly\hardware\tools\avr/bin/avrdude -CE:\arduino-nightly\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM4 -b115200 -D -Uflash:w:C:\Users\xxxxx\AppData\Local\Temp\build3bb8345d83cedc585b1cb6c2216554cb3.tmp/BasicSerial.ino.hex:i` – jsotola Feb 05 '20 at 19:26