Upload and decompile

I have a program on a Mega which works ok but I have lost the 'program'.ino. Can it be uploaded from the board and decompiled for further work?

Not really. You can get the hex code out of the board, but you probably can't make enough sense of it to do anything with it. You can find decompilers that can get it back to C code, but even then what you get back won't look like what you started with. It will just be something that gets to the same end and probably doesn't have the structure you want to start adding to.

Moral of the story: Backup and backup often. I host all the stuff I'm concerned with keeping on github.

I'd be surprised if there's a decompiler for the Arduino. And, if such a thing exists I'd be surprised if it were well-done because it's not a high-demand tool.

And yeah, your original variable names (and to some extent the program structure) are lost when you compile, and of course the comments. If you've ever tried to understand & modify someone else's code that's similar to what you'd be working with.

I've never used a decompiler. I've never known of anyone using one... But, I know they exist. However, most of the Arduino functions are not ANSI/ISO standard C/C++. i.e. digitalWrite() does not exist in standard C++.

A disassembler is a lot more practical than a decompiler, but I'd rather not work in assembly language. And, you'd still have to do some translation between the ATmega ports/pins and the Arduino pin numbers, etc.

BTW - I've also lost some Arduino code that I'll probably want to re-create at some point. You know... It's always easier the 2nd time! :smiley: :smiley: :smiley:

FYI, the correct term in this case is "download", not "upload".

pert:
FYI, the correct term in this case is "download", not "upload".

I think that depends on whether you have the Arduino sitting on top of the computer or underneath it on the desk.

I was taught that it depended on the most important or higher level to the lower level

So if you have a PC it would be download to the Arduino (sending info to the Arduino) or upload from the Arduino (receiving info from the Arduino to the PC)

from the same PC it would be upload to the server (send info to the server) or download from the server (info received from the server)

And yes I got tripped up with the programming terminal on the desktop and the computer (PLC) mounted on the wall above the table and I wanted to use the term "upload" when sending the program to the PLC high on the wall - backwards of the convention in the controls industry at the time

Thanks for help/opinions, but I'm loving the argument over the semantics of upload and download! I spend hours wondering whether it would be an upload or a download.

Then don't move into the world of controls engineering. There download is to the controller from the PC and upload is to the PC from the controller. Even though they are just glorified microcontrollers. All hail Allen-Bradley!

To me it always seemed to depend on which end of the connection I was on and where the data that was being transferred was. You "upload to" and you "download from".

Spend the time on trying to recover the source.

Backup, Backup, Backup, Backup, Backup and oh, Backup.

.

To me it always seemed to depend on which end of the connection I was on and where the data that was being transferred was. You "upload to" and you "download from".

That's always been my understanding too and it makes so much more sense that some subjective distinction of what's more "important" or just a completely arbitrary choice of terminology, though I do like the elevation-based definition.

I think that when beginners use the wrong term it is often due to a fundamental lack of understanding of the relation of the computer, IDE, compiler, and Arduino board. When I first stumbled on Arduino I didn't understand that you are flashing firmware to the microcontroller rather than writing a program that runs on your computer and controls the board, which was the application I was looking for at the time. I had previously heard of flashing chips using a UV EPROM programmer in a high school computer class (we weren't allowed to play with any of that stuff but the teacher had all sorts of crazy electronics piled up all over in the classroom) and hadn't realized that technology had progressed far beyond that in the meantime. When the board arrived in the mail and I realized what was actually going on it became vastly more interesting to me. I get a kick from seeing code I wrote running on that tiny little IC.