What sketch is loaded onto my UNO?

I have many versions of the same sketch, each slightly different from each other. I don’t remember which one Iv’e loaded onto my UNO. Is there a way to find out?

No simple way. Some people have the program print a version number and/or compilation date when it starts up.

4 Likes

You can download the code (bin) FROM your UNO to your PC, then try to

  • compare it with code(bin) of every your version, if it matches - problem is Arduino IDE probabely alredy deleted the codes(bin) and making new one may be little different
  • disassemble the code(bin) (into asm) and find some important parts there (does it work because I added or subtracted those two variables? like)
  • disassemble the code and disassemble codes(bin) of your versions and compare that - you may find more similarities and you will see, what differs and if that is important or not (just some debug prints? Near enought ..)
  • disassemble it and rewrite/convert it to ASM, C, C++, INO which you will use from now

So ways exists, but not so extra easy (but doable).

Anyway good idea is to include version number/identifier inside each version of code(both ino and bin), so it can be found later (and print it to Serial if possible, ideally near begin of startup()

Also good idea is to use some version controll - I prefere GIT, but there are also others.

BTW: Disassembler for ATmega2560 (Arduino Mega R3) here is disassembler AND emulator, so you can even try to step over the downloaded code and see how it works :)

Any changes to any libraries, board packages, the compiler, Arduino IDE, etc, would result in slightly different compiled code that would not match the code on the UNO. If the various versions of your sketch only differ slightly that would make the task almost impossible.

On the other hand, if you compiled all the sketches with a fairly current version of the Arduino IDE (after version 2.0), cached copies of the sketch and compiled code are saved and not deleted automatically, so you could possibly locate the cache and compare with what is stored on the UNO.

Yes, exactly.

But many people make a lot of similar version in fast streak (and then realise, that some of them probably was not as bad as the last, but which one?), so there is good chance, that some cached versions are still there, or at least that nothing important was reinstaled in between, so compiling may be the same (or similar, if date/time was somehow included (maybe by macros __ DATE __ or _TIME_) or something like that)

And if it fails, disassembly can show everything … it is “just” matter of time and work and study …

Hi, @RobertHB
If you do this in setup.

Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);

When ever you boot your code the code will send the filename out the serial monitor.
Everytime you make another version the newer file name will be sent on boot.

Tom.... :smiley: :+1: :coffee: :australia:

2 Likes

It may help in next builds, but this one, which is loaded alredy to the UNO does not have it.
It will help if he change the filename for each version (like test007.ino, test008.ino, test_final_001.ino) along with the directory, where it is saved.

If he just archive the old C-code somewhere and then fix it in place, the next compilation will use the same filename (I am using deleteme.ino as scratchpad this way). Also the C-code will contain just this macro _FILE_ , not its value.

It is better than nothing anyway.

Thanks very much to everyone who is trying to help me with my problem. As you can tell, I am an extreme newbie to the Arduino.

I fear I may not be explaining my problem correctly. I have one basic sketch that I have altered slightly six times. Each time I saved it with a different “name”, such as version one, version two version three, etc..

Now, it’s many months later, and I want to know which sketch “name” is loaded onto the Uno.

Is there a simple way to find out what sketch “name” is loaded onto my Uno?

Thanks again !

Basically, no.

At a minimum, you would need to read the machine code off the Arduino onto your computer, usually done using avrdude at the command-line level.

The simplest approach might be to get a 2nd UNO, load each of the sketches onto that UNO, and compare the operation of the two UNO's to see if there is any noticeable difference. Without knowing what the sketch does, or what you changed between the versions, that might or might not help.

2 Likes

The best bet may to simply take the latest version (using the OS file time and date) for the file. Then test it. If it does not work correctly it may be faster to just correct the code and be sure to print (FILE) in the setup. I also use the copy command and copy the .ino file to filexx.txt where xx is a number and save it in the sketch file. That allows me to go back if I mess up.

1 Like

If each code performs differently, and you have copies, then load each code and try it.

Tom.... :smiley: :+1: :coffee: :australia:

Arduino IDE provides no means to read the program in AVR MCU's. (At least I don't know any.)
But: when compiling/uploading a sketch, Arduino IDE saves a number of files. Even if you wiped your original files it's possible those are still available.
Take a look at:
C:\Users\USERNAME\AppData\Local\arduino\sketches\HEXNUMBER\sketch\SKETCHNAME.
ino.cpp
Logically, the most recent one is the good one. (Else you would have continued changing.)

I tried this and get gibberish at the end of the path:
17:59:46.762 -> /home/opalko/Arduino/Sketc�

Is the folder /Sketch book or /Sketchbook?

C:\Users\USERNAME\Documents\Arduino\

What does the rest of the code look like? Suddenly stopping in the middle of printed text is usually a sign of either a processor reset or some serious error in the code.

Looks like he is using linux, /home/username/Arduino/ would be the default sketch folder

Sorry, I did not intend to imply "root" by not including the dot. I should have written
./Sketch(space)book or ./Sketchbook (sorry... not ./Spacebook not thinking again)

Have you got the IDE set to 115200 baud?

Tom.... :smiley: :+1: :coffee: :australia:

Once again, thank you to everyone who is trying to help me with my problem.

Since I have several UNO’s , at this point, for me, I think I will try David’s suggestion.

Thanks, again.