I'm trying to add a bootloader hex to Nick Gammon's Atmega Board Programmer sketch, and I can't seem to get a hex file to convert.

I need to convert "Arduino-usbserial-atmega16u2-Uno-Rev3.hex", but that wasn't working so I thought I'd try converting one that's already used in the sketch, "Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex", but that's not working either. I've followed the instructions from http://www.gammon.com.au/bootloader

I've tried it using Wine and Paralells. Clicking the copy button when using Wine causes the program to stop responding.

Here is a screenshot of the error:

Error Screenshot

Thank you

  • Why do you need to do this? Normally you don't need to reflash the Atmega16U2 chip.
    – Nick Gammon
    Mar 1, 2016 at 21:22
  • I work at a university and I'm making a shield that plugs into the top of dead Arduinos the see if they can be fixed with a simple re-flash of the chips, which is usually the fix. I used your sketch to put the Atmega16U2 chips into DFU mode, but it still requires me to connect the Arduinos to a computer to finish off the fix. It'd just be easier to put the working hex file on the chip in the first place. Mar 2, 2016 at 18:42
  • I have another sketch which uploads a hex file from a SD card. The size of the full file for the Atmega16U2 may not fit into the bootloader programmer PROGMEM. However you could easily reflash the entire chip using the hex-uploader sketch. In fact you probably don't need the bootloader on the Atmega16U2 - because that is only used for entering DFU mode.
    – Nick Gammon
    Mar 2, 2016 at 19:39

1 Answer 1


I can't reproduce that.

My apologies - I couldn't quite read the error message in the screen dump. What you got was:

Don't know end address for 0
Please add to table: end_addresses
Run-time error
World: smaug2
Immediate execution
[string "Immediate"]:96: Cannot continue
stack traceback:
        [C]: in function 'error'
        [string "Immediate"]:96: in function 'process'
        [string "Immediate"]:134: in main chunk

The relevant error is the first line. That file has code for address 0 - which is not part of the bootloader. It tries to detect bootloader addresses, and zero is not one of them. Looking at the start of the file I see this:


In particular the format is:

 :10 0000 00 90C00000A9C00000A7C00000A5C00000 6B
  ^  ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^
len  addr TT   data                          sumcheck

So this file includes code for the Atmega16U2 as well as the bootloader.

My sketch is not designed to program non-bootloaders (it is a bootloader programmer after all).

Scroll down that page for how to reprogram the Atmega16U2 chip.

The bootloader programmer sketch (as published) will put the bootloader onto the Atmega16U2. Then follow the instructions on that page, or on this page, below, for entering DFU mode and uploading the main part of the code (not the bootloader part).

Entering DFU mode

If you have just flashed the bootloader using the bootloader programmer sketch then it should enter DFU mode, visible because the pin 13 LED flashes rapidly.

If not, enter DFU mode by shorting together Reset and Ground briefly with a screwdriver or similar. They are the two left-most pins visible in the image above, nearest to the Reset button and below the hole on the board.

(Don't keep them shorted, just a brief touch should do it).

Enter DFU mode

Once in DFU mode, you should see it appear as an Atmel USB device, if you type lsusb (on Linux):

$ lsusb
Bus 003 Device 092: ID 03eb:2fef Atmel Corp. 

A Uno which is not in USB mode might look like this:

$ lsusb
Bus 003 Device 090: ID 2341:0043 Arduino SA Uno R3 (CDC ACM)

(or not appear at all if there is no firmware on it).

If you are using Ubuntu or similar you can obtain the DFU programmer as follows:

 sudo apt-get install dfu-programmer

You can obtain the code for the firmware from here:


(RH-click and "save as" to put a copy on your hard disk).

Assuming you place that firmware in the current directory of your terminal window, you can now flash the code as follows:

sudo dfu-programmer atmega16u2 flash Arduino-atmega16u2-Uno-firmware-Rev3.hex

You should see a message like:

4034 bytes used (32.83%)

Now you can unplug the USB cable, plug it back in, and the USB interface should be back to factory settings.

For other operating systems, such as Windows, you should be able to get a copy of the DFU programmer from:

  • Why am I getting the same error message when I try and convert Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex, the same used in your bootloader programmer sketch? Mar 2, 2016 at 18:39
  • Being a combined file it would start at address zero as well. I would have stripped out the low-order bytes from the .hex file, leaving only the bootloader part.
    – Nick Gammon
    Mar 2, 2016 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.