I had a hard time figuring this out, took me over three hours of scavenging the internet. Hope this helps somebody.
Why do I want to use AVRDUDE
If you are at this page you already know about the arduino…
I want to use the Arduino Nano in a LED light controller circuit I have built. I want to program color led’s that are attached to clothing (dance costumes) to operate in millisecond level sync. For more look at https://lytesync.com
This requires that the led sequence is flashed to the Arduino Nano. That means that I have to release the source code of my application for anybody else to program their own sequence.
I have a cloud service that lets you create a LED light/color sequence, and as part of building the sequence I compile the Arduino program with the sequence embedded in the code space. Compiling it generates a HEX file.
I want the end user to be able to program the hex file they download onto their Arduino Nano.
Get to the point…
You came here looking for a solution, not to wade through my notes on how I went about solving it. So here goes:
avrdude -c arduino -p m328p -P /dev/cu.usbserial-1110 -b 57600 -v -U flash:w:bl.hex
Key items:
I’m on a Mac, so replace the /dev/cu.usbserial-1110 with the link to your USB device (Arduino nano).
The reason I am writing this post is the serial port speed to flash the Arduino nano with the old bootloader. Setting the speed to 57600 was the key to solving this.
bl.hex is the output of compiling the arduino .ino file.
In case you are looking for a command line to compile your arduino .ino file to a hex file. Output will go to your build directory. Note i’m using the Mac you may need to tweak the command line.
/Applications/Arduino.app/Contents/MacOS/Arduino lytesync_arduino.ino --board arduino:avr:nano:cpu=atmega328old --verify --pref build.path=./build
Things to remember
I am talking about the $3 Arduino that I bought on Amazon. This one uses the “old bootloader”
If you want to read other internet links that talk about this. I got here because of them.
Relevant links and notes
https://forum.arduino.cc/t/how-to-select-atmega328p-old-bootloader-for-uploading-avr-c-code/1149365
The above link was the clue that solved it for me.
https://openev.freshdesk.com/support/discussions/topics/6000012812
avrdude -c arduino -p m328p -P /dev/cu.usbserial-1110 -b 57600 -v -U flash:w:bl.hex
Created bl.hex to use with bootloader. This was from the blink sample.
Key item was 57600
avrdude -c arduino -p m328p -P /dev/cu.usbserial-1110 -b 57600 -v -U flash:w:bl.hex:i
Avrdude version 8.0
Copyright see https://github.com/avrdudes/avrdude/blob/main/AUTHORS
System wide configuration file is /opt/homebrew/etc/avrdude.conf
User configuration file /Users/toolbunch/.avrduderc does not exist
Using port : /dev/cu.usbserial-1110
Using programmer : arduino
Setting baud rate : 57600
AVR part : ATmega328P
Programming modes : SPM, ISP, HVPP, debugWIRE
Programmer type : Arduino
Description : Arduino bootloader using STK500 v1 protocol
HW Version : 2
FW Version : 1.16
AVR device initialized and ready to accept instructions
Device signature = 1E 95 0F (ATmega328P, ATA6614Q, LGT8F328P)
Auto-erasing chip as flash memory needs programming (-U flash:w:…)
specify the -D option to disable this feature
Erased chip
Reading 924 bytes for flash from input file bl.hex
in 1 section [0, 0x39b]: 8 pages and 100 pad bytes
Writing 924 bytes to flash
Writing | ################################################## | 100% 0.35 s
Reading | ################################################## | 100% 0.23 s
924 bytes of flash verified
Avrdude done. Thank you.