how to download the current code from an arduino board?

hello arduino forum,

my question seems to be a basic principle - but i nowhere found the answer so far:

is it possible to download the current code from an arduino board to the pc – is there a workaround?
(i lost the code i uploaded some time ago and i need a exact copy of the existing for a
second installation)

thanks and best
sebastian

Yes, look up avrdude. You'll want to use something like this (it worked on my computer, but you'll have to change the ports and probably some other stuff.)

You open up cmd (assuming windows; essentially same for linux and mac though), then type

"C:\arduino-1.0\hardware\tools\avrdude -p m328p -C C:\arduino-1.0\hardware\tools\avrdude.conf -c arduino -D -P COM5 -U flash:r:output.bin:r"

changing each of the "C:\arduino-1.0"s to where your arduino is located (it should work on multiple versions) and changing "output.bin" to where you want the output going.

The small problem is that it's not in C++ anymore, it's in machine code. Meaning you can't* edit it

*conditional can't

There is no way to get the C++ out of it, save disassemblers and stuff.

Agreed. To get the "binary data" off the chip do something along these lines:

avrdude -c usbtiny -p m328p -U flash:r:myfile.hex:i

Then attach the other board and do:

avrdude -c usbtiny -p m328p -U flash:w:myfile.hex

The "r" version reads the flash memory, the "w" writes it.

You will need something like USBtinyISP to connect to do this.

http://www.ladyada.net/make/usbtinyisp/

As WizenedEE said this will not give you back the sketch (in C++) but you can make another board behave the same as the first one.