The opposite of uploading ??

Is it possible to get the compiled code out of an arduino, and run it through a compare utility ? It it even possible to see the compiled code ? It must be there somewhere .....

I have made two versions of a project, one for a restaurant, and one for a gin bar next door, and one of them has an unusual fault in that the PT2314 audio module ~sometimes~ fails to recognise a command code. PCBs and component values are the same on both.

Of course I have no idea which of these projects got uploaded first, and they did differ in some respects, so the core code may have got changed, it was too long ago to be certain.

Anyway, I have access to both machines, and was wondering if there was a way to verify what code is in the "faulty" one.

Which Arduino boards are the programs on?

Arduino Nano boards ...

OK, here are the instructions for "downloading" the compiled binary from the Nanos:

First, we’re going to do a dummy upload in the Arduino IDE in order to get it to help us generate the avrdude command used to read the program from the Arduino board:

Plug your Arduino board into your computer.

Select your board from the Arduino IDE’s Tools > Board menu.

Select your board’s port from the Tools > Port menu.

VERY IMPORTANT: Unplug your board from your computer.

File > Preferences

Check the box next to “Show verbose output during > upload”.

Click “OK”.

Sketch > Upload

Wait for the upload to fail.

Scroll up the black console window at the bottom of the Arduino IDE window until you see the avrdude command that was generated for the upload. It will look something like this:

E:\Arduino\hardware\tools\avr\avrdude -CE:\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM17 -b115200 -D -Uflash:w:C:\Users\per\AppData\Local\Temp\arduino_build_91864/sketch_jan22b.ino.hex:i

Select the full text of the upload command.

Press Ctrl + C. This will copy the upload command to the clipboard.

Next, you need to modify the upload command to read the hex file out of your Arduino board:

Start a text editor program.

In the text editor window, press Ctrl + V. This will paste the command into the text editor. The end of the command will look something like this:

-D -Uflash:w:C:\Users\per\AppData\Local\Temp\arduino_build_91864/sketch_jan22b.ino.hex:i

That is the part of the command that tells it to write.

Replace that part of the command with the command that tells AVRDUDE to read:


That will cause the read file to be named “readfile.hex”, which will be saved to whichever folder you run the command from. So now the full command looks something like this:

E:\Arduino\hardware\tools\avr\avrdude -CE:\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM17 -b115200 -D -Uflash:r:readfile.hex:i

If the paths in the command contain spaces, wrap the paths in quotes.

Plug your Arduino board into your computer.

Copy and paste the command from the text editor to the command line

Run the command.

Wait for the command to finish successfully. You should now see the file created by the read command, which contains the binary that was read from the Nano.

It's also possible to write that file back to an Arduino board. It doesn't sound like that's your goal, but if you decide you want to do that, I'm happy to provide instructions.

Thank you pert, your detailed instructions are exactly what I am looking for.

Firstly it gives me the detail on how to find a potential “upload” hex file generated by the compiler.

And secondly, it gives me the detail how to reverse the operation and “download” the hex file from the arduino to the PC.

Although the terms “upload” and “download” seem to be reversed to me, coming from a background programming PLCs (Programmable Logic Controllers), where “download” is generally transferring the object file TO the PLC. At least that is how it is with Allen-Bradley PLCs, other manufacturers differ.

Taking off the “load” you are left with “Up” and “Down”, neither of which defines the data transfer direction.

You can “Upload to…”, or you can “Upload from…”, in the same way you can “Download to…”, or “Download from…”.

It is not an argument worth getting into, so long as we know what data transfer direction is involved with any particular platform, but it does cause confusions…

Anyway, your response can give me hex files that I can compare to determine which .ino file generated the code in the target board.

Thank you pert, your detailed instructions are exactly what I am looking for.

You're welcome. I'm glad if I was able to be of assistance.

Although the terms "upload" and "download" seem to be reversed to me, coming from a background programming

Yeah, I've noticed the meaning of the terms can be opposite depending on the framework. This is the reason I put the quotes around "download" in my previous reply. I've only ever used these terms for computers uploading to and downloading from the Internet (or maybe BBSs back in the day, I can't remember though) and "uploading" to Arduino boards, so it seems intuitive to me, but that's just because my introduction to embedded systems was Arduino.

Although the "D" and "U" in AVRDUDE stand for "downloader" and "uploader", I haven't actually found anywhere that they provide a definition of the terms. Instead, the UI uses "read" and "write".

but it does cause confusions

I think it would be a good idea for the documentation to provide a clear definition of what Arduino means by the term "upload". I recently did that in the relevant section of the developer targeted technical documentation:

Arduino uses the term "upload" for the process of transferring a program to the Arduino board.

but I see that you sort of have to read between the lines to get the meaning from the relevant section of the user-targeted documentation: