Upload Same Sketch to Multiple Different Microcontollers via USB?

I'm attempting to figure out how to mass-upload a single Arduino INO sketch file to several different microcontrollers on a Windows 10 system.


It was understanding that, every time that the Arduino IDE compiles & uploads an INO sketch, it essentially calls the avrdude.exe executable in the installed Arduino directory. Therefore, I assumed it would be possible to create some sort of a Windows batch script that manually executes that file, and uploads the sketch to a given COM port connected to my Windows 10 system. In fact, an answer to a simillar Arduino Forums post some time ago has provided a potential solution in the following batch script:

@echo off
SET FILE_TO_UPLOAD=%1

SET ARDUINO_DIR="C:\Program Files (x86)\arduino"

@echo off
for /f "tokens=*" %%a in (ports2.txt) do (
echo Com Port for Arduino device is detected as %comport%.
echo --------------------------------------- & echo Uploading to: %%a & "C:\Program Files (x86)\arduino\hardware\tools\avr\bin\avrdude.exe" -C "C:\Program Files (x86)\arduino\hardware\tools\avr\etc\avrdude.conf" -p atmega328p -c arduino -P %%a -b 115200 -D -V -U flash:w:%FILE_TO_UPLOAD%:i
)
pause

However, it appears that the latest verions of the Arduino IDE (v2.3.3 in my case) does not store it's data in "C:\Program Files (x86)\arduino" anymore. I saw in other simillar examples that the avrdude.exe path is referenced as "Applications\Arduino\", yet that path does not exist on my Arduino IDE version either. The installation path for my Arduino IDE instance appears to be "C:\Users\*user*\AppData\Local\Programs\Arduino IDE\", and in that directory there is no trace of avrdude.exe.

I'm therefore assuming that the latest versions of the Arduino IDE have a different method of compiling & uploading sketches without avrdude.exe, so I'm assuming that the batch sketch uploading method using avrdude.exe referenced in the previous post answer does not work anymore with the latest versions of the Arduino IDE.

Moreover, this specific example appears to always specify specifically what type of boards to upload to (atmega328p in the specific example above), and what I'm looking for is a method of uploading to several different types of microcontrollers.


A different StackExchange answer provided a method of uploading a sketch to several Arduinos connected in series. However, what I'm looking for is a method of mass-uploading to several microcontrollers in parallel, all connected to separate COM ports.


Another Arduino Forums post showcases a method of mass-uploading via a custom-made circuit that uses another Arduino NANO to "forward" the code to several Arduino NANOs. However, this method relies on an intermediary microcontroller for "forwarding" the code to the remainder of the connected microcontrollers through a custom circuit, yet what I'm looking for is just uploading to a bunch of microcontrollers connected in parallel via several USB connections to COM ports on my Windows system.


Is it possible to mass-upload a single Arduino INO sketch to several different microcontrollers via some sort of batch script on a Windows 10 system? What kind of a Windows batch script, if any, would achieve such a goal?

Thanks for reading my post, any guidance is appreciated.

Hi @Svarun123.

That is incorrect. AVRDUDE is still used to upload sketches to boards that have an AVR microcontroller, just as always.

However, AVRDUDE is no longer bundled with the Arduino IDE installation, so you need to look in the right place for it.

Do this:

  1. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Uncheck the box next to Show verbose output during: compile in the "Preferences" dialog.
  3. Check the box next to Show verbose output during: ☐ upload.
  4. Click the "OK" button.
    The "Preferences" dialog will close.
  5. Upload a sketch to your Arduino board.
  6. Wait for the upload to finish.

Now examine the content of the black "Output" panel at the bottom of the Arduino IDE window. There you will see the avrdude command Arduino IDE ran to perform the upload. You can run that command from a terminal.

The sketch must be compiled for the specific target microcontroller. For example, if you compile a sketch for the UNO R3 and then upload that binary to a Mega 2560 board, it isn't going to work.

You also must adjust the avrdude command for the specific board you are targeting. You can upload a sketch to the board with the verbose output preference enabled, as I described above, to learn the appropriate form for the avrdude command.

Yes. Instead of trying to use AVRDUDE directly, my recommendation would be to use a tool named Arduino CLI for this project:

https://arduino.github.io/arduino-cli/

Arduino CLI is an official command line tool for compiling and uploading sketches. It is very well suited for use in a script.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.