Use IDE to flash a pre-compiled binary/HEX?

Use IDE to flash a pre-compiled binary/HEX?

I'm thinking about distributing a pre-compiled sketch (binary/HEX) to other users, some have limited computer skills. I want to distribute the binary/HEX to make it simple for them. They can install the Arduino IDE (pretty simple), and then they only need to flash their board with the file I provide, they don't need to recompile and worry about configuring the IDE with all the proper libraries, etc.

I've seen the tutorials that describe how to get the binary/HEX file from the IDE, and to grab and modify the command lines to feed the AVRdude, but that's fairly involved.

(like this: No-IDE Arduino Programming! Hex/Bin File upload from Command Line - AVR/ESP8266/ESP32 - YouTube ),

Is there a way to just tell the Arduino IDE to flash a previously compiled binary/HEX, instead of compiling the sketch and uploading the resultant binary?

Hi @NTL2009.

This is not supported. There are some 3rd party standalone tools that do this though.

Which Arduino board or boards are you targeting?

Keep in mind that none of that is necessary when you provide the binary. In this case, you can provide the command line for the user to run. The only work they need to do to the command is set the port of their Arduino board. It is still a bit challenging for those who are not proficient in working with command line tools, but less so than the case where a user has to extract the upload command from the Arduino IDE verbose upload output.

I like to add to the previous answer that you can add the command to a batch file or shell script; the only thing the user basically has to do is double click it.

OK, thanks. I'll play around with that. I can write scripts, but I'm not very fluent, I suspect I'll have to do something to find the comm port that is on the user's machine, store it in a variable, and then use that in the command. And I suspect those scripts will be different between Win/Mac/Linux? I guess that's why I think it would be nice if it was an option in the IDE, just skip the compile step, go to an existing binary file, and upload it.

I forgot to answer this: Currently, I'm using NodeMCU when I need a WiFi connection, and ProMicro for some other projects that didn't need WiFi, but a generic tool would be best, I may add to the boards I use at some point.

You might find Arduino CLI to be a useful tool for doing this in a cross-platform manner.

The following command will print all the ports on the user's computer in a machine readable JSON format:

arduino-cli board list --format json

Documentation here:

https://arduino.github.io/arduino-cli/latest/commands/arduino-cli_board_list/

Yeah, this does present a challenge. It is possible to run a script of any common language (shell, PowerShell, Python, etc.) on any platform, but there is no platform that has all the interpreters installed by default. The more common approach is to provide a shell script for Linux and macOS users and a batch file for Windows users.

In this case where there isn't a single uploader tool for all the targets (i.e., you can't use AVRDUDE/AVRDUDESS/Xloader to upload to the "NodeMCU" board), you might consider Arduino CLI. Arduino CLI will use AVRDUDE when uploading to the Pro Micro and esptool when uploading to the NodeMCU so it provides a unified interface for uploading to any Arduino board. It also handles the "1200 bps touch" that is necessary to upload to the Pro Micro and similar, which AVRDUDE does not (I don't know whether the other AVR uploader tools do that).

Unlike Arduino IDE, Arduino CLI does allow you to upload a binary at the path specified by the --input-file flag. Documentation here:

https://arduino.github.io/arduino-cli/latest/commands/arduino-cli_upload/

You should note that, in addition to installing the Arduino CLI tool itself. You also need to install the platform (AKA "core") of the target board to provide Arduino CLI with the uploader tool and uploader tool command pattern it needs to perform the upload. You can do that using the arduino-cli core install command. Documentation here:

https://arduino.github.io/arduino-cli/latest/commands/arduino-cli_core_install/

Thanks so much to @sterretje and @ptillisch for this info. At this point, I'm really starting to think it's just easier to have the user compile the source code. My only reasons for wanting to distribute the compiled code was to avoid the less technical users from having to deal with loading the proper libraries, etc. for the IDE. But, those things are not really difficult, they are point and click, and are well documented . It seems these other approaches would require explanations from me, and details specific to the user's OS, and vary with the board type (which the IDE would account for).

I sure wish there was a widely supported, pre-loaded bootloader that could flash the compiled code by just plugging in an SD Card, but this is likely beyond the scope of what can be done with a micro-controller of these sorts. But that would make it a bit easier to get these tools into the hands of people who are intimidated by the idea of 'programming'.