# How to read the current program from an Arduino?

I acquired an Arduino PCB with an ATMega2560, already programmed with the Arduino bootloader and some program. I do have the Sketch, but before fiddling with it, I'd like to backup the current binary that is in the controller. As most Arduinos it's connected to the PC using an USB-to-serial converter connected to TX0 and RX0 and there is no ISP interface.

Apparently there is code for reading in the Arduino bootloader, but I have no idea which tool to use to access it as there is no menu item in the Arduino IDE.

What software do I need to read the program from the Arduino?

-
 Found code for reading in the bootloader, edited question. – AndreKR Jun 13 '12 at 17:32

Per the request of the OP, I'm submitting the following as an additional answer.

The Arduino bootloader is a variant of the original STK500 protocol (1.x). The character 't' = 0x74 which is the "Read Page" command. So perhaps it is possible to pull the program out through the serial port via the bootloader using avr-dude... but at best I reckon it will take some fancy timing to pull it off.

-

Does the Backup AVR with avrdude thread answer your question? Basically you can read all memory from an AVR as long as the protection fuse isn't set.

This is the setup I use for ATtiny's and ATmega's.

On the board shown:

• 11 = MOSI
• 12 = MISO
• 13 = SCLK

Refer to the datasheet of the controller which exact pin to use. There are quite a few websites on Internet writing about programming AVR's using an Arduino, eg.: http://hlt.media.mit.edu/?p=1229

-
 I need a second arduino for that, right? I don't have one. – AndreKR Jun 13 '12 at 17:21 This is a two Arduino method, yes. – jippie Jun 13 '12 at 19:12 And, although it's a bit hard to see in the picture, the pins used on the target Arduino are not TX0 and RX0 either, are they? – AndreKR Jun 14 '12 at 22:49 No, TX and RX are not used for ICP. Updated the answer a bit. – jippie Jun 15 '12 at 7:00 Well, I think you missed the whole point of my question, probably because I gave it a bad title. I rephrased the whole question. – AndreKR Jun 16 '12 at 0:52

As far as I can see form the Arduino bootloader source code, there's no way to 'dump' all memory from it. The bootloader does support a 'monitor' mode which allows you to dump one memory byte at a time. However, as per the source code comments "/* monitor functions will only be compiled when using ATmega128, due to bootblock size constraints */"

As such, I guess you're out of luck if you don't want to use ISP, change the bootloader or upload a sketch to do it.

-
 I was referring to the section that starts in line 701 with else if(ch=='t') {. – AndreKR Jun 16 '12 at 16:48 Good point - hadn't seen that. – RJR Jun 26 '12 at 10:57

I thought there was a menu option for that but I'm not finding it right now. If you have an ISP programmer, you can use AVR Studio to Read the memory image off the chip and save it off in a HEX file, that would allow you to restore it through the same means.

Edit

In response to your comment - that's easy! You need to assimilate two diagrams worth of information to pull it off. The first is the Arduino / ATMega2560 Pin Mapping.

The second is the ISP Header / AVR Pin Mapping:

Armed with these two pictures, you should be able to see how to wire it up.

• Run a wire from DIG50 to Dragon ISP header pin 1
• Run a wire from VCC to Dragon ISP header pin 2
• Run a wire from DIG52 to Dragon ISP header pin 3
• Run a wire from DIG51 to Dragon ISP header pin 4
• Run a wire from RESET to Dragon ISP header pin 5
• Run a wire from GND to Dragon ISP header pin 6

With those in place, you should be able to use AVR Studio to read the Hex file off the chip - let me know if you need more guidance.

-

I've dumped a memory from Duemillenova with ATMega328P with the following command:

avrdude -C avrdude.conf -v -v -v -v -p atmega328p -c stk500 -U flash:r:"c:/arduino.hex":r -P\\.\COM2 -b57600

-