Restoring Arduino MEGA Bootloader

22 January 2016

After programming an Arduino MEGA board using Atmel Studio, the bootloader in the Arduino will be overwritten by the program loaded to the Arduino. The instructions that follow show how to restore the bootloader of an Arduino MEGA 2560 using an Atmel AVRISP mkII or AVR Dragon and Atmel Studio. When the bootloader is restored, the Arduino will be able to be programmed using the Arduino IDE software via the USB port.

1. Locate the Arduino MEGA Bootloader File

Locate the bootloader hexadecimal or hex file for the Arduino MEGA 2560 which is included with the Arduino IDE software. After downloading the Arduino IDE software and unzipping it, open the Arduino IDE folder which is in the form arduino-<Arduino IDE Version Number> and locate the bootloader file called stk500boot_v2_mega2560.hex as described below.

For example, in Arduino IDE version 1.6.7, the hex file is found in arduino-1.6.7\hardware\arduino\avr\bootloaders\stk500v2\ as shown in the image below. This is just to show the location of the file – we will need to navigate to this file from within Atmel Studio.

Arduino MEGA 2560 bootloader file location

Location of the Bootloader File for the Arduino MEGA 2560

2. Connect the Programmer

Connect the programming device, such as the AVRISP mkII or AVR Dragon to the PC USB port and to the ICSP header of the Arduino MEGA 2560, then power the Arduino from its own USB cable.

Start Atmel Studio and click the Device Programming icon on the top toolbar or select Tools → Device Programming from the top menu.

Atmel Studio Device Programming Button on Top Toolbar

Atmel Studio Device Programming Button on Top Toolbar

In the Device Programming dialog box, select the Tool (AVRISP mkII or AVR Dragon), Device (ATmega2560) and Interface (ISP) then the click the Apply button. To test that Atmel Studio can communicate with the AVR on the Arduino board, click the Read button under the Device signature heading.

Connect Atmel Studio to the ATmega2560 AVR on the Arduino MEGA 2560

Connecting Atmel Studio to the ATmega2560 AVR on the Arduino MEGA 2560

3. Program the Bootloader using Atmel Studio

Click Memories in the left pane of the Device Programming dialog box. Click the [...] button found at the right of the box under the Flash label to browse for the bootloader file.

Browse for the Arduino MEGA 2560 bootloader hex file

Browse for the Arduino MEGA 2560 Bootloader Hex File

Navigate to and select the hexadecimal bootloader file called stk500boot_v2_mega2560.hex found in the Arduino IDE software sub-folder hardware\arduino\avr\bootloaders\stk500v2. Click the file in the dialog box and then click the Open button as shown in the image below.

Selecting the MEGA 2560 bootloader file

Selecting the MEGA 2560 Bootloader File in Atmel Studio

Click the Program button in the Device Programming dialog box to load the bootloader to the ATmega2560 AVR. Close the dialog box when done by clicking the Close button.

Programming the bootloader to the Arduino MEGA 2560

Programming the Bootloader to the Arduino MEGA 2560

4. Test the Bootloader using Arduino IDE

After loading the bootloader to the Arduino MEGA 2560, test the Arduino to make sure that the correct bootloader was loaded and that the board works with the Arduino IDE USB programming.

If you broke the track between the two RESET-EN pads to use the board with the debugger, first solder the pads together before continuing.

Unplug the USB cable from the Arduino board to power it down and then unplug the programmer from the Arduino board ICSP header. After a few seconds, plug the Arduino MEGA 2560 board back into the PC using a USB cable.

Open the Arduino IDE and select the correct board and port under Tools → Board and Tools → Port. Also make sure that ATmega2560 is selected under Tools → Processor.

Open the Blink example sketch from the top menu under File → Examples → 01.Basics → Blink. Load the Blink sketch to the Arduino MEGA 2560 from the Arduino IDE using the Upload button on the Arduino IDE toolbar.

Using the blink sketch to test that the Arduino MEGA 2560 bootloader is working

If everything is working, the Arduino IDE will compile and load the sketch and the L LED on the Arduino MEGA will blink on and off continually.