Downloading existing code

First, we’re going to do a dummy upload in the Arduino IDE in order to get it to help us generate the avrdude command used to read the program from the Arduino board:

  1. Plug your Arduino board that contains the program you want to read into your computer.
  2. Select your board from the Arduino IDE’s Tools > Board menu.
  3. Select your board’s port from the Tools > Port menu.
  4. VERY IMPORTANT: Unplug your board from your computer.
  5. File > Preferences
  6. Check the box next to "Show verbose output during > upload".
  7. Click the OK button.
  8. Sketch > Upload
  9. Wait for the upload to fail.
  10. Scroll up the black console window at the bottom of the Arduino IDE window until you see the avrdude command that was generated for the upload. It will look something like this:
    E:\Arduino\hardware\tools\avr\avrdude -CE:\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM17 -b115200 -D -Uflash:w:C:\Users\per\AppData\Local\Temp\arduino_build_91864/sketch_jan22b.ino.hex:i
    
  11. Select the full text of the upload command.
  12. Press Ctrl+C. This will copy the upload command to the clipboard.
  13. Next, you need to modify the upload command to read the hex file out of your Arduino board:
  14. Start a text editor program.
  15. In the text editor window, press Ctrl+V. This will paste the command into the text editor.
  16. The end of the command will look something like this:
    -D -Uflash:w:C:\Users\per\AppData\Local\Temp\arduino_build_91864/sketch_jan22b.ino.hex:i
    
    That is the part of the command that tells it to write.
    Replace that part of the command with the command that tells AVRDUDE to read:
    -Uflash:r:readfile.hex:i
    
    That will cause the read file to be named "readfile.hex", which will be saved to whichever folder you run the command from. So now the full command looks something like this:
    E:\Arduino\hardware\tools\avr\avrdude -CE:\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM17 -b115200 -D -Uflash:r:readfile.hex:i
    
  17. If the paths in the command contain spaces, wrap the paths in quotes.
  18. Plug your Arduino board into your computer.
  19. Copy and paste the command from the text editor to the command line
  20. If you are using to an ATmega32U4-based board (e.g., Leonardo, Micro, Yun), you’ll need to press and release the reset button on the board immediately after running the command. If you are using a Pro Micro, use a wire to momentarily connect the RST and GND pins. If you are using a Yun, press and release the "32U4 RST" button quickly twice. Wait about a second after resetting the board before running the command.
  21. Run the command.
  22. Wait for the command to finish successfully.

Writing the file to a board

You can follow a similar procedure to write the file to another Arduino board. Remember that this file was compiled specifically for the Arduino board you read it from. You can’t use it with an Arduino board that has a different configuration. For example, if you read it from an Uno, it is compiled for an ATmega328P running at 16 MHz, and won't work correctly on a board with a different microcontroller or clock speed.

Generate model command

First, we’re going to do a dummy upload in the Arduino IDE in order to get it to help us generate the avrdude command used to write the program to the Arduino board.

Note: It doesn't matter whether the upload will succeed or fail. You get the command either way.

  1. Plug the Arduino board you want to write to into your computer.
  2. Select your board from the Arduino IDE’s Tools > Board menu.
  3. Select your board’s port from the Tools > Port menu.
  4. Select File > Preferences from the Arduino IDE's menus.
  5. Check the box next to "Show verbose output during: [] upload".
  6. Click the OK button.
  7. Select Sketch > Upload from the Arduino IDE's menus.
  8. Wait for the upload to finish/fail.
  9. Scroll up the black console window at the bottom of the Arduino IDE window until you see the avrdude command that was generated for the upload. It will look something like this:
    E:\Arduino\hardware\tools\avr\avrdude -CE:\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM17 -b115200 -D -Uflash:w:C:\Users\per\AppData\Local\Temp\arduino_build_91864/sketch_jan22b.ino.hex:i
    
  10. Select the full text of the upload command.
  11. Press Ctrl+C. This will copy the upload command to the clipboard.

Customize command

Next, you need to modify the upload command to write the hex file you read from your other Arduino board:

  1. Start a text editor program.
  2. In the text editor window, press Ctrl+V. This will paste the command into the text editor. The end of the command will look something like this:
    -D -Uflash:w:C:\Users\per\AppData\Local\Temp\arduino_build_91864/sketch_jan22b.ino.hex:i
    
    That is the part of the command that tells it to write.
  3. Replace the filename in that part of the command with the name of the file you read:
    -Uflash:w:readfile.hex:i
    
    So now the full command looks something like this:
    E:\Arduino\hardware\tools\avr\avrdude -CE:\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM17 -b115200 -D -Uflash:w:readfile.hex:i
    
    If the paths in the command contain spaces, wrap the paths in quotes.

Run command

Now the write command is all prepared. It's time to run it!

  1. Plug the Arduino board you want to write to into your computer.
  2. Select the full text of the write command in your text editor.
  3. Press Ctrl+C. This will copy the write command to the clipboard.
  4. Open a command line terminal. On Windows, you can use the Run dialog, PowerShell, or cmd.
  5. In the command line, press Ctrl+V. This will paste the avrdude command.
  6. If you are uploading to an ATmega32U4-based board (e.g., Leonardo, Arduino Micro), you’ll need to press and release the reset button on the board before running the command. If you are using a Pro Micro, use a wire to momentarily connect the RST and GND pins. If you are using a Yun, press and release the "32U4 RST" button quickly twice. Wait about one second before running the command.
  7. Press Enter to run the command.
  8. Wait for the writing process to finish successfully.