Can I see current revision loaded?

I’m getting back to a project I worked on a couple of years ago, an Arduino Nano using IDE 2.3.6. I’m not sure which revision is currently in the Nano, is there a way to see what code is currently loaded in? I don’t think there is but thought I would ask anyway.

Can I upload from the Nano to my laptop, can I do a comparison between the Nano and the versions I have on my laptop, can I just see the title?

Thanks

John

The Nano does not contain the source code so a direct compare is not possible.

If you did not set the protection bits in the Nano you can read its content back (hex) using avrdude. You can also export a binary from your source code (again hex) in the IDE. After that you can compare.

Notes:

  1. The two formats might be slightly different (16 data bytes per line versus 8 data bytes per line).
  2. You need to know the library versions that were used when you programmed the Nano as well as the avr-gcc version. A minor difference in those can result in differences.

Also you may download the code from arduino, disasembly it and compare with compiled and disasembled version of your source, so you may see, if the main code is (nearly) the same and differencies are only in libraries … not so easy to do as to say, but at least some way .


For next time it would be wise let the program print some version on start, if there is a way to comunicate, or at least build the version as string into the code (to read it on next download).

I put the version into my programs like here down:

Compiled: 2025.06.20 20:56:24 0.0.1-22-g986c781++ based on 986c781 - Merge remote tracking branch ‘origin/master’

(there is bug in display, where last 3 chars are dispalyed on start of next line)

The version 0.0.1 is from tag in git, the -22- means it is 22 steps after the tag and the code 986c781 is git commit, on which it is based (the rest is git comment) - I strongly recommend use git for every project/code you ever write, it is ultimate good :slight_smile:

@sterretje I am not familiar with avrdude but a quick Google and YouTube search has given me a brief understanding. That may be beyond my skills but I’ll see what I can do, thanks for that info.

@gilhad that’s a great idea to printout the version on startup. I will start doing that with all future codes.

I do have some versions of this program, I may just load one in and go from there.

Thanks for the replies.

Hi @Stumpy_L.

I'll provide instructions in case you decide to give it a try:

A. Generate model command

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

  1. Plug the USB cable of the Arduino board that contains the program you want to read into your computer.
  2. Select File > New Sketch from the Arduino IDE menus.
  3. Select your board from Arduino IDE's Tools > Board menu.
  4. Select your board's port from the Tools > Port menu.
  5. :warning: VERY IMPORTANT :warning:: Disconnect the USB cable of the Arduino board from your computer.
  6. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  7. Check the box next to "Show verbose output during: ☐ upload" in the "Preferences" dialog.
  8. Click the "OK" button.
    The "Preferences" dialog will close.
  9. Select Sketch > Upload from the Arduino IDE menus.
  10. Wait for the upload to fail.
  11. Scroll up the black "Output" panel 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:
    "C:\Users\username\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\username\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-PCOM35" -b115200 -D "-Uflash:w:C:\Users\username\AppData\Local\Temp\arduino\sketches\2550236D1AAA5295D4F743C245319248/sketch_aug7a.ino.hex:i"
    
  12. Select the full text of the upload command.
  13. Press the Ctrl+C keyboard shortcut (Command+C for macOS users).
    This will copy the selected text to the clipboard.

B. Prepare read command

Next, you need to adjust the command you obtained via the procedure above so that it will read the hex file out of your Arduino board instead of writing:

  1. Start any text editor program.
  2. In the text editor window, Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the command you copied while following the instructions above into the text editor.
  3. The end of the command will look something like this:
    "-Uflash:w:C:\Users\username\AppData\Local\Temp\arduino\sketches\2550236D1AAA5295D4F743C245319248/sketch_aug7a.ino.hex:i"
    
    This is the flag that tells AVRDUDE to write.
    Replace that flag with the flag that tells AVRDUDE to read:
    -Uflash:r:readfile.hex:i
    
    The full command should now look something like this:
    "C:\Users\username\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\username\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-PCOM35" -b115200 -D -Uflash:r:readfile.hex:i
    
  4. If the paths in the command contain spaces, make sure they are wrapped in quotes.
  5. Press the Ctrl+A keyboard shortcut (Command+A for macOS users) to select all the text of the command in the text editor.
  6. Press the Ctrl+C keyboard shortcut (Command+C for macOS users) to copy the selected text to the clipboard.

C. Run the command

Now the read command is all prepared. It's time to run it!

  1. Plug the USB cable of the Arduino board that contains the program you want to read into your computer.
  2. Open a command line terminal.
    I'll provide some links to instructions for doing that on each operating system:
  3. Press the Ctrl+Shift+V keyboard shortcut (Command+V for macOS users) in the terminal window to paste the command you copied while following the instructions above at the command line prompt.
  4. Press the Enter key.
  5. Wait for the command to finish successfully.

You should now find a file named "readfile.hex" in whichever folder you opened the command line terminal in. That is the hex file of the program read from the Arduino board.

@ptillisch Excellent, looks like fun, I’ll give it a try and let you know how I make out.

Thanks

@ptillisch I followed the instruction and did get a new folder in the “C:\user\user” folder, not much seemed to happen in the terminal. I don’t see the readfile.hex file. I ran the command a second time and got this result. Did I modify the command line to read correctly?

Powershell is not a terminal :wink:

See C.2 in post #5. I think that using the command prompt (cmd) would be the better option.

Note:
If you don't post screenshots but post the output here using code tags people might be able to analyse the exact error.

Here’s the output from Powershell

PS C:\Users\User> C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-PCOM11" -b115200 -D "-Uflash:r:readfile.hex:i"
>> C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-PCOM11" -b115200 -D "-Uflash:r:readfile.hex:i"
C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude
-CC:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -V
-patmega328p -carduino -PCOM11 -b115200 -D -Uflash:r:readfile.hex:i
C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude : The term
'C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude
-CC:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -V
-patmega328p -carduino -PCOM11 -b115200 -D -Uflash:r:readfile.hex:i
C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude' is not recognized as
the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\User\A...o17/bin/avrdude:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Users\User>

There are two problems. The first is that you must add a & prefix to the command when using PowerShell. I see that was not covered by my instructions. I apologize for any confusion this caused.

The other problem is that you didn't add a double quote character at the start of the avrdude command.

The corrected command:

&"C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-PCOM11" -b115200 -D "-Uflash:r:readfile.hex:i"

Try to use git too, then you will be able simply keep all versions of project and compare any two of them for differencies and use any older version as well for any reasons … (like, this feature worked 3 version ago and now does not work, what to do? Comper actual version with the version, where it worked and see, why it does not work, or if it is too complicated, just upload the old version for now and fix it anytime later :) )

@ptillisch I got it. I went back and cleared everything and ran it per your instructions, that were very good by the way, Now I have the readfile.hex.

What do I do with it now? Can I convert it to ASCIi or some characters so I can see the title? Do I convert the files on the laptop to hex and do a comparison?

Thanks for helping me.

the file.hex is this format:

Thanks @gilhad I understand what Hex is and where it’s used, but I don’t read hex, if I open the file it’s nothing but a string of meaningless numbers to me. How do I make it readable, or the better question is, can I convert it to something I can read? At least the line that shows the filename?

Thanks again, I appreciate all the feedback

I do not have such tool handy (as I can generate bin from source), but there should be a lot of tools, maybe this one?

there is also solution

Or you can write your own, as the format is easy to convert

The potential use for the binary was explained at the time the idea was mentioned:

So the idea is that you would now generate another .hex file by compiling the project sketch at a revision you suspect might be the one loaded on the board, then compare that against the content of the .hex file you read from the board.

If the content of the two match, then you will have identified the revision that is loaded on the board.

In the case of a mismatch between the content of the two, this may have been caused by one of two possibilities:

  • The sketch code from which you generated the .hex file is not the same revision as the code for the program loaded on the board.
  • The sketch code is the revision loaded on the board, but there has been a change in the dependencies of the sketch. For example, if your sketch uses a library, having a different version of the library installed than you did at the time you uploaded the sketch to the board will result in a different hex file content, even if the content of the code in the sketch itself is identical.

I'll provide instructions you can follow to generate a .hex file from your sketch:

  1. Open the sketch in Arduino IDE.
  2. Select the appropriate board from Arduino IDE's Tools > Board menu.
  3. Select Sketch > Export Compiled Binary from the Arduino IDE menus.
    A sketch compilation will be triggered.
  4. Wait for the compilation to finish successfully.
  5. Select Sketch > Show Sketch Folder from the Arduino IDE menus.
    The folder of the sketch will open in your file manager application.
  6. Navigate to the build/arduino.avr.nano subfolder of the sketch folder.

You will find two .hex files in that folder. You will want to compare the one with the .ino.hex file extension.

You can use a disassembler to convert the .hex file to assembly code. You can do that using a tool named avr-objdump. You already have a copy of that tool installed on your computer as part of the compiler toolchain Arduino IDE uses to compile your sketch. You can find the location of the compiler installation by examining the output from compiling the sketch with verbose output enabled:

  1. Open the sketch in Arduino IDE.
  2. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  3. Check the box next to "Show verbose output during: ☐ compile" in the "Preferences" dialog.
  4. Click the "OK" button.
    The "Preferences" dialog will close.
  5. Select Sketch > Verify/Compile from the Arduino IDE menus.
  6. Wait for the compilation to finish.

Now examine the content of the black "Output" panel at the bottom of the Arduino IDE window. There you will see the commands Arduino used to compile the sketch. You will see commands that use an executable named avr-size. If you navigate to the folder at the path shown in that command, you will see it also contains an executable named avr-objdump.

For example, I see this in my output:

"C:\\Users\\per\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-size" -A "C:\\Users\\per\\AppData\\Local\\arduino\\sketches\\08FADAE3E5A51B314AAC14A4C80469EC/3042.ino.elf"

So I know that avr-objdump is at the following path on my hard drive:

C:\Users\per\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\bin\avr-objdump\