Copy hex file from one Arduino Leonardo to another

Hi all! The issue I've come across is that I have an Arduino Leonardo board with an uploaded code in it, and one in which I need to copy this code into. I don't have access to the original code, I only have the board. I've tried using AVRdude to create the hex file of the first board, in order to then upload it to the other board, typing the following command in cmd:

avrdude -c arduino -P com6 (this is where it is) -p atmega32u4 -Uflash:r:c:\hexfiles\test.hex:i

But then nothing happens. What am I doing wrong? I really need to finish this as quickly as possible and I am pretty noob to it.

Thanks in advance!

I am no expert but simply ask for it. It should be under the software licence they should be happy to share it unless it has been copyrighted. If so then the legalities come with the libraries that were used.

Unfortunately there is no way to get the code from its authors. It was a home made code and the authors are out of touch atm…

What does the code do ? For future Maintainance and development it may well be worth re writing it yourself .

I'd really like to rewrite it, but I haven't got the time. I want it as a temporary solution and then try to rewrite the code. Isn't there any way to do this?

Are you using an ISP programmer or the usual USB interface used for the bootloader?

A suggestion, experiment using another Leonardo, you do not want to accidentally wipe the flash on the original.

I find that the Arduino copy of avrdude is not on any search path and the easiest way to get the right command is to turn on "Preferences: Show verbose output during: compilation upload". UNPLUG THE ARDUINO and click on the upload button for a small or empty sketch. The upload will fail but the first three lines in the log window will be:

Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
/Users/john/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude -C/Users/john/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -carduino -P/dev/cu.usbserial-14230 -b115200 -D -Uflash:w:/var/folders/kq/89qrmhn9563d565c5th318kw0000gn/T/arduino_build_795458/sketch_mar29a.ino.hex:i

Take the third line and replace "Uflash:w:/var/folders/.../sketch_mar29a.ino.hex:i" with "Uflash:r:test.hex:i", resulting in a command line that looks like:

/Users/john/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude -C/Users/john/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -carduino -P/dev/cu.usbserial-14230 -b115200 -D -Uflash:r:test.hex:i

Plug the Arduino back in and run the command line. The result should be a "test.hex" file in the current directory. If you then plug in the new Arduino and run the command again with "Uflash:r:" changed back to "Uflash:w:" the "test.hex" file will be uploaded to the FLASH on the new board.

1 Like

Thanks! That seems to work, but it gives the avrdude: butterfly_recv(): programmer not responding. Pressing the reset button just ends the command…

At what step do you get the error?

When I execute the command, it writes some characteristics and then is says “connecting to programmer” and gives that message twice afterwards.

If only I could see what command you are executing.

I’m writing this:
C:\Avrdude\avrdude -CC:\Avrdude\avrdude.conf -v -patmega32u4 -cavr109 -PCOM6 -b57600 -D -Uflash:w:test.hex:i

It runs the command, shows some characteristics such as using port, using programmer, overriding baud rate etc, then a table with memory type mode delay size etc, it says
Programmer type: butterfly
Description: atmel appnote avr109 boot loader

Connecting to programmer…: .avrdude: butterfly_recv(): programmer is not responding

And then it says the same message about programmer not responding once more and stays there forever until I cancel the command or reset the board.

And what command do you see when you upload a sketch to your Leonardo? On my system the command looks like:

/Users/john/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude -C/Users/john/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -patmega32u4 -cavr109 -P/dev/cu.usbserial-14230 -b57600 -D -Uflash:w:/var/folders/kq/89qrmhn9563d565c5th318kw0000gn/T/arduino_build_627582/BlinkWithoutDelay.ino.hex:i

Did you put a copy of the Arduino bin/avrdude and etc/avrdude.conf into C:\Avrdude?

Are you sure you have the Leonardo plugged in as COM6? I don’t have a Leonardo plugged in and got the same “avrdude: butterfly_recv(): programmer is not responding” messages.