I wanted to have my own MIDI instrument, so I had to reprogram the atmega16u2 chip on my Arduino UNO R3 board. There is a somewhat outdated tutorial for that, but to completely do that, and easily I had to gather information from various blogs, forums, projects.
Though actually the process is very easy and fast, you can write a .bat file or shell script to change the firmware in seconds.
Programming with the dfu-programmer tool is very easy, for me seems easier than any other options. So these are the steps - written for Linux, but with some straightforward adjustments should apply to Windows as well - mainly the difference is that on Windows you need only the dfu-programmer package, no other installation/compiling needed - and to run dfu-programmer you don't need sudo.
Install necessary software
Download latest dfu-programmer (which knows about the atmega16u2 on the R3 Uno) from http://sourceforge.net/projects/dfu-programmer
On Linux you need to install some extra:
- sudo apt-get install libusb-1.0
Also, on Windows - after you put the Arduino into DFU mode - you need the USB drivers for the atmega16u2 - the best is to get it from atmel's Flip programmer, there you find an Atmel\Flip 3.4.7\usb folder - so go to Device Manager (in Windows Control Panel), select Install Software for your "Unknown Device" - then set this folder as driver source - it will be installed correctly.
Unzip the downloaded file. On Windows you can use it straight away. On Linux you need some extra steps (and might need to install gcc and others tools, see compiler messages.)
To unzip and install on Linux:
- tar xzvf ~/Downloads/dfu-programmer….tar.gz
- cd into the unzipped directory
- run ./configure
- run make
- run sudo make install
Programming a new firmware consists of the following steps:
- Put the atmega16u2 chip into DFU mode
- Erase the atmega16u2 flash memory
- Upload the new content for the atmega16u2 flash memory
- Reset the atmega16u2
- Plug off and in the Arduino
Put Arduino into DFU mode
First connect the Arduino to the computer using the USB port.
To reprogram the atmega16u2, you must put the chip into DFU (Device Firmware Update) mode.
On the Arduino R3 that's very easy: shortcut briefly the 2 leftmost ICSP headers next to the USB port.
Led on pin 13 will flash. (Might not flash if the firmware installed doesn’t do that.)
running lsusb should now show 03eb:2fef Atmel Corp., that is the Arduino is no longer visible as Arduino.
At this point you have not changed anything on the board, if you want to abort the process, just plug off and in the board.
Put new firware
First erase: sudo dfu-programmer atmega16u2 erase
Then flash the new one: sudo dfu-programmer atmega16u2 flash MYFIRMWARE.hex
Reset the chip: sudo dfu-programmer atmega16u2 reset
pull out the usb cable then put it back
Put back old firmware
To put back the original firmware, you must locate it first in your arduino installation, it is Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex
You must first erase the flash (see previous section), then flash the new one with one more special parameter:
sudo dfu-programmer atmega16u2 flash ~/prog/arduino-1.0.4/hardware/arduino/firmwares/atmegaxxu2/Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex --suppress-bootloader-mem
Then reset the chip (see previous section) and replug the Arduino.
Running lsusb should now show Arduino SA Uno R3 (CDC ACM)