Downloading "Sketch" from Arduino to PC

Thread Starter

SamR

Joined Mar 19, 2019
3,411
I understand that the sketch is compiled and loaded onto the uP as machine code. And that it is possible to download the HEX code from the board to the PC to be copied into another board. Does anyone have any experience with this? Wish there was some way to decompile the HEX code... According to Arduino's Forum it's not possible. Only copy HEX to new board. Any ideas?
 

sagor

Joined Mar 10, 2019
439
Not sure what you want to do. There is a HEX file left somewhere in the working directory I believe (in the user's \appdata\local\temp.... folder). As long as the IDE is left running, that hex file should remain. It is likely deleted when the IDE closes.
Once you copy the HEX file, you can program a similar Amtel chip using any programmer of your choice with ICSP, whatever that programmer may be.
 

Thread Starter

SamR

Joined Mar 19, 2019
3,411
What I have are some "toys" controlled by preprogrammed Arduino NANOs. Which means that their programming is unavailable to me to peruse or modify. Yes, it is a simple(?) task to extract and copy the HEX file to another NANO but not look at the actual program or make any changes to it. Started just out of curiosity as to how they programmed them to do what they do. One is an Evil Genius Labs Fibonacci 32 which has 32 RGB LED modules that generates "random" patterns, colors, brightness, and a glitter/flicker effect based on the Fibonacci equation. Out of curiosity, I would be interested in how it is coded. Only 10 pins are used and 2 of those are power and ground. Schematic would be nice also but the 32 LED modules use one anode pin for each color with a common cathode. So that is at least 4 of the 10 pins used. Possibly available from the EG Lab (haven't contacted yet) but would be nice to extract it myself. Several of these various different NANO based toys came into my lap and am curious as to how they were coded.

Evil Genius Labs | Fibonacci 32 Kit
 

Thread Starter

SamR

Joined Mar 19, 2019
3,411
OK, that is apparently an AVR hardware interface from chip to a software suite I don't have. Haven't quite made it to AVR standalone chip programming but have it on the todo list and some of the hardware, software, documentation and some various ATmel DIP chips waiting. These NANOs have a small square 32 pin SMD uC chip which will take a special harness to access onboard. Or a special chassis for the unmounted chip. Not quite there yet... At this point sticking to the USB interface of the NANO and the Arduino 2.0 BETA IDE or the version 1.8xxx.
 

Yaakov

Joined Jan 27, 2019
3,161
What I have are some "toys" controlled by preprogrammed Arduino NANOs. Which means that their programming is unavailable to me to peruse or modify. Yes, it is a simple(?) task to extract and copy the HEX file to another NANO but not look at the actual program or make any changes to it. Started just out of curiosity as to how they programmed them to do what they do. One is an Evil Genius Labs Fibonacci 32 which has 32 RGB LED modules that generates "random" patterns, colors, brightness, and a glitter/flicker effect based on the Fibonacci equation. Out of curiosity, I would be interested in how it is coded. Only 10 pins are used and 2 of those are power and ground. Schematic would be nice also but the 32 LED modules use one anode pin for each color with a common cathode. So that is at least 4 of the 10 pins used. Possibly available from the EG Lab (haven't contacted yet) but would be nice to extract it myself. Several of these various different NANO based toys came into my lap and am curious as to how they were coded.

Evil Genius Labs | Fibonacci 32 Kit
On the page linked there is a heading "Code" which has a link to a repo. Is it not what you want?
 

andrewmm

Joined Feb 25, 2011
1,474
What I have are some "toys" controlled by preprogrammed Arduino NANOs. Which means that their programming is unavailable to me to peruse or modify. Yes, it is a simple(?) task to extract and copy the HEX file to another NANO but not look at the actual program or make any changes to it. Started just out of curiosity as to how they programmed them to do what they do. One is an Evil Genius Labs Fibonacci 32 which has 32 RGB LED modules that generates "random" patterns, colors, brightness, and a glitter/flicker effect based on the Fibonacci equation. Out of curiosity, I would be interested in how it is coded. Only 10 pins are used and 2 of those are power and ground. Schematic would be nice also but the 32 LED modules use one anode pin for each color with a common cathode. So that is at least 4 of the 10 pins used. Possibly available from the EG Lab (haven't contacted yet) but would be nice to extract it myself. Several of these various different NANO based toys came into my lap and am curious as to how they were coded.

Evil Genius Labs | Fibonacci 32 Kit
Just a thought

If you don't have the source, are you entitled to revers engineer the hex code ?
 

Thread Starter

SamR

Joined Mar 19, 2019
3,411
Considering that they are no longer made... I would think so, yes, especially considering it for personal curiosity only with no commercial intent. @Yaakov Yes and following the link to GitHub the code is posted. Quite interesting programming and see some things written in the code that were not in the instruction that came with it! But still leaves the question as to capability to decompile the HEX code. Is it even possible? Didn't find the schematic but the Fibonacci 32 (or 34 to be an actual Fibonacci number) code itself is an ongoing active open source project. Find it interesting that the timing has been adjusted to decrease the overall mA usage.
 

Yaakov

Joined Jan 27, 2019
3,161
Yes. The open source way would be with avr-objdump from http://www.nongnu.org/avr-libc/

But that's a disassembler, if you want C-like code, there are third party products. To be clear, compilation is a lossy process as far as the source code goes. The compiled code can't be reversed into the source code, but it can be functionally described.
 

Thread Starter

SamR

Joined Mar 19, 2019
3,411
K, thx, AVR is solidly on my todo list. Arduino is good stuff but I wan't to take the training wheels off and program the chips directly without the development board supporting me. I'm headed there as soon as I finish the semiconductors textbook I'm currently working with so it may take a while yet. Yes, I understand that compiling and disassembling and recompiling is like translating from one language to another and then back again. You might get the gist of if but lose all the nuances and connotations of the language.
 
Top