0
\$\begingroup\$

I'm new to Arduino and spent shockingly long on an RFID code variant. Unfortunately someone then snuck into my flat and nicked my laptop. The sketch however is still on my Arduino UNO, is there a practical way to recover it in a format that would be useful? Or would my time be better spent trying to recreate it from scratch?

I've come across some references to bootloaders/HEX/temp files but I'm not sure how that would work or if it would result in anything useful at the end of the day.

Thank you for your help!

\$\endgroup\$
1
  • \$\begingroup\$ No. You can read out the compiled code (and clone it into another board) but that is very far from being useful source code. Any research of your own would have lead you to this conclusion. \$\endgroup\$ Commented Jul 27, 2020 at 13:54

2 Answers 2

1
\$\begingroup\$

You can't. I'm sorry about your laptop, and about the lost code.

You could probably download the binary program that runs on the hardware.

Downloading the binary gives you the binary, not the "sketch" (which is the source code). It's the compiled binary. There's no way to get back to the source code but to reverse-engineer it, which is probably way, way harder than re-writing it from scratch, since you know what it was doing.

Also: software developers, and especially embedded developers like you, should be in the habit of working with source version control systems. Exactly because code gets lost, and exactly because not every code version is perfect.

It's the first thing I request any student that works for me sets up: Get git, watch the git-scm videos (DO IT NOW. It's 20 minutes of time that you will get back in less than a week if you work with code that you sometimes have to "rewind" to figure out how to do something right. And I bet you had to do that a couple of times, right?), and maybe read a chapter or two into the git book. Every single of my students doesn't want to do that (especially when they are under time pressure), and then regret not doing it earlier when they really have to do it. With git, and private git repos, eg. on gitlab, github, bitbucket,... you get proper source backups, and a way to rewind, try new things without having to make copies of everything, document your progress.

\$\endgroup\$
0
\$\begingroup\$

As far as I know, unfortunately, it's not possible. However, I have read (https://forum.arduino.cc/index.php?topic=6150.0) that under certain circumstances and with great effort it may be possible to sketch the binary out of the Arduino. Unfortunately I have no real experience with this. If I may give you a hint: Rewrite the sketch and learn from it to create more secure backups (google Drive, on drive...)

Maybe this can help (Quote from this forum: https://forum.arduino.cc/index.php?topic=6150.0):

if you press the [compile-upload] button with the shift pressed you get information how a sketch get uploaded (commands etc). If you are able to extract the hexcode from one Arduino  this verbose output might give some clues how to upload the hexfile. Check http://www.nongnu.org/avrdude/user-manual/avrdude.html#Top

update:
Just read the page myself and found on http://www.nongnu.org/avrdude/user-manual/avrdude_4.html#Option-Descriptions the option -U memtype:op:filename[:format] (options are case sensitive!!)

The op field specifies what operation to perform:
r   read the specified device memory and write to the specified file
w   read the specified file and write it to the specified device memory


So one can read and write from a device ( I expect reading will produce a 32K image, even if the original sketch was less)

and

The format field is optional and contains the format of the file to read or write. Possible values are:
...
r    raw binary; little-endian byte order, in the case of the flash ROM data
...


So it must be possible to download a raw binary from one device and upload it to another one. You must also have the port right and other flags, so read it more carefully than I did. As Cr0sh said you wil not  get the sourcecode but this thread http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1241117308 is about disassembling the generated hexcode so you may get a faint echo of the original source

PLease let us know if you succeeded as this is a way to quick multiply a busload of Arduinos with the same sketch. Very interesting.

Hope this was helpful

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.