Possible to copy compiled code from one Arduino to another and have it function?

I have an Uno R3 which has a working, compiled program which run an LED array based on sensor input.

Long term, I will need to re-code the program, since the source is lost, but I need that same code on multiple, identical Uno R3 devices, in the next couple of days.

Is there a way to copy it to a second (or multiple) identical Arduinos?

I know that it is not possible to decompile, I'm looking for a short term fix, because I have a deadline which will come before I can learn enough to re-code the program.

Sure, once you get it to where it will compile, you can upload it to as many Unos as you want.

CrossRoads: Sure, once you get it to where it will compile, you can upload it to as many Unos as you want.

Well each upload initiates a new required compilation from the source sketch which the OP said will or is not available, so your suggestion is not something he can use. What is required is a command line script to use AVRDUDE directly to read back the binary contents of the flash memory on the prior uploaded chip and then a write to each new chip again using AVRDUDE directly. At least that is my take on the OP's question. But then again we both may not have a clear picture of what he is asking and in need of?

Lefty

Re-coding was mentioned, hence fresh compile would be available. I don't know if the original can be downloaded from the existing chip (possible via avrdude if fuses allow that), if so the avrdud commands can be used to load same into additional chips. Not my cup tea tho, need someone with avrdude experience.

I suspect its easier to do (for me anyway) with Atmel's AVR Studio and an AVR ISP MKii programmer.

That last is correct. i apologize if I wasn't clear. I do not have source to compile from. I need to read back the compiled code, and write it to the additional Arduinos.

I'm pretty much completely new to all this, so instructions which are detailed and step by step would very much be appreciated. Thanks for taking the time to answer me.

:)

I will re-code at some point, but this is a job that got dropped on me, and the deadline is too close to be sure that I can learn what I need in time. Copying the compiled code will hopefully let us function, while I learn what I need to know to rewrite the code.

What do you have for tools?

Beyond the uno itself, a Windows PC (or Linux). I do have basic electronic tools, multimeter, etc…

But I don’t know what I would need. That is part of what I’m asking. If I need something I don’t have, I’ll get it.

Here you go - takea look at this thread and see if rabitu can get you thru uploading hex files. http://arduino.cc/forum/index.php/topic,123837.0/topicseen.html

This is one of the most useful tools you can have http://www.mouser.com/ProductDetail/Atmel/ATAVRISP2/?qs=%2fha2pyFadujqFzV%252bExzQOlFEGuFbE5zkYm9OzGvRqkjeoy23MLFzjw%3d%3d

Board needs to powered to use it. MKii senses voltage in use and adjusts its signals accordingly as far as I know.

Nick Gammon has made a very clever solution, to both read and write the compiled hexfile

http://www.gammon.com.au/forum/?id=11638

You could also use avrdude commandline. For example this line

avrdude -c arduino -P com20 -p atmega328p -Uflash:r:d:\hexfiles\test.hex:i

Will read the flash and write the content to the file test.hex

Then you could write this file to another Uno using this line

avrdude -c arduino -P com20 -p atmega328p -Uflash:w:d:\hexfiles\test.hex:i

Output:

avrdude -c arduino -P com20 -p atmega328p   -Uflash:w:d:\hexfiles\test.hex:i

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "d:\hexfiles\test.hex"
avrdude: writing flash (32750 bytes):

Writing | ################################################## | 100% 4.39s

avrdude: 32750 bytes of flash written
avrdude: verifying flash memory against d:\hexfiles\test.hex:
avrdude: load data flash data from input file d:\hexfiles\test.hex:
avrdude: input file d:\hexfiles\test.hex contains 32750 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 5.21s

avrdude: verifying ...
avrdude: 32750 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

What would I use to connect AVRdude to the board? An ISP Programmer? Or can it be done with just the USB connection?

In the above example I have just used an Arduino Uno, connect to my PC via USB. It shows up as COM20

avrdude -c arduino -P com20 -p atmega328p -Uflash:r:d:\hexfiles\test.hex:i

A brief explanation -c arduino programmer is arduino -P com20 The com port that arduino connects to -p atmega328p Partnumber, The mcu on an Arduino is Atmega328p -Uflash memorytype is Flash as opposed to EEPROM r read d:\hexfiles\test.hex:i the path and filename on your computer (the i indicate Intel hex)

So what you could do is: Connect the Arduino with the sketch you want to copy to your PC via USB as normal, and observe the com port

Make a command window and type the avrdude command to copy the Flash

Connect The Arduino you wish to copy to, via the USB

Make a command window and type the avrdude command to write the file to Flash

This is on a Windows machine

zenbike: What would I use to connect AVRdude to the board? An ISP Programmer? Or can it be done with just the USB connection?

Yes either a ISP programmer that your AVRDUDE configuration file knows how to use or another arduino board running the arduino as ISP sketch.

Lefty

Yes either a ISP programmer that your AVRDUDE configuration file knows how to use or another arduino board running the arduino as ISP sketch.

No need for ISP programmer or Arduino as ISP. Just connect the Arduino via USB cable as you would do if you were going to upload a sketch

Erni:

Yes either a ISP programmer that your AVRDUDE configuration file knows how to use or another arduino board running the arduino as ISP sketch.

No need for ISP programmer or Arduino as ISP. Just connect the Arduino via USB cable as you would do if you were going to upload a sketch

Yes, I've read back the hex file with the bootloader (just usb cable from arduino to C)

When I tried to use avrdude to read a chip, I found that more was needed that posted previously. For example, this is what I had to use when I wanted to read back from a tiny84 using ArduinoISP:

\hardware\tools\avr\bin\avrdude -p t84 -P\.\COM6 -b19200 -c stk500v1 -C …/etc/avrdude.conf -U flash:r:E:\flash.bin:r

I found that more was needed that posted previously

That depends on the settings of your Environment Variable. It is described in the WinAVR user Manual. For example I can use avrdude from anywhere without specifying the path, as you do.

First off, Yes I know I'm replying to an old question, my answer is more for anyone who stumbles upon it (Like me)

The other day I copied a working Arduino's contents (i.e., sketch etc) to another, I used the Atmel AVR studio with one of their in circuit programmers (using the 6 pin header). So if you have, or know someone with an Atmel programmer, give it a go.

I bought a batch of Arduinio Nano Chineese clones, one has either a faulty USB chip, or the micro has a faulty serial port, eitherway, it cannot be programmed via the regular Arduino environment. So to make use of an otherwise dud board, I can upload a finished/debugged etc sketch to a good Nano, then copy it over to the dud board via AVR studio, freeing up the good board for the next project.

This is also, a possible solution if you want to distribute a working Arduino program without sending them the source code, or even letting them know you did your programming in Arduino.

pastubbs: This is also, a possible solution if you want to distribute a working Arduino program without sending them the source code, or even letting them know you did your programming in Arduino.

So instead of simply providing them with a copy of avrdude.exe, avrdude.conf and libusb0.dll, or using XLoader or similar, they have to install the full Atmel Studio? Sounds like doing it the hard way to me.

I can upload a finished/debugged etc sketch to a good Nano, then copy it over to the dud board via AVR studio

But if you're going to upload it to the dud board using ISP afterwards anyway, why upload to a good board, then copy it back to upload to the dud board. Why not simply use ">Sketch >Export compiled binary" to generate a hex file directly from the IDE, then upload that to the dud board with your ISP programmer?

Led array and sensor input. Doesn't sound that difficult to write new code with same behavior. I mean, you're either going to spend your time learning to extract machine code, then spend more time writing a new sketch as you've said you'll have to do anyway.

It'd be silly to exchange one learning curve for another possibly more complex one because you don't understand the scope of either.

For Windows users: Copy 386 via batch script

Ray