Getting binary image off an arduino - SOLVED

Ok.

I have a 3d printer based around an arduino mega.
I would like to look at and perhaps hack up the code a little.
I have the source code for the firmware. (It doesn't compile :frowning: , but that's not the issue)
I am concerned that if I hack up the code, upload it, and it doesn't work, I will have bricked by new 3d-printer.

So I would like to extract the existing image in flash on the mega in such a way as I can restore that image later on and return the printer to the state that it is in now.

What command-line commands to I give to extract the firmware in the device right now, and restore it?

(The source code bundle comes with a .hex file, incidentally, but can I really trust that this .hex file is really what's in the printer right now? No, I cannot. I would far rather pull the image out of the printer and know for sure that it's right.)

I use this line to read the code from a Mega2560:-

"C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude" -C"C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf" -c wiring -P com6 -p atmega2560   -Uflash:r:code.hex:i

To get the exact paths to "avrdude.exe" and "avrdude.conf" for your system, upload a simple sketch to a Mega, with "Show verbose output during upload" checked, and the output window will have the path to each. Then just edit the line above to the correct paths. You'll also need to change the port to the one you're using for the printer controller.
It will produce a *.hex file named "code.hex".

I have the above line in a batch file, with "pause" on the second line so that I can view the avrdude output before closing the command prompt window, and the "code.hex" output file appears in the same folder as the batch file.


Almost forgot - this is the line to write that code to the Mega.:-

"C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude" -C"C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf" -v -patmega2560 -cwiring -PCOM6 -b115200 -D   -Uflash:w:code.hex:i

Again, you'll need to edit it for the correct paths for your system and the right COM port.
This will work if you use a batch file, with the "code.hex" file in the same folder as the batch file. If the "code.hex" file isn't in the same folder, you need to use the full path to it after the "w:"

Thanks, Steve - will try it when I get home. Karma added.

PaulMurrayCbr:
Thanks, Steve - will try it when I get home.

No worries. Let me know if you have a problem.

Karma added.

Thank you for that Paul.