36.Burn the bootloader on UNO, Mega, and classic Nano using another Arduino

The bootloader is a small piece of software that allows uploading of sketches onto the Arduino board. It comes preprogrammed on the microcontrollers on Arduino boards. Whether the bootloader has been corrupted or intentionally has been removed, it can be restored by burning (also called, flashing or programming) a new bootloader to the board.

The easiest way to burn the bootloader to classic AVR boards (UNO, Mega, Nano, etc.) is using a second Arduino AVR board as a programmer, which is the method that will be covered below.


Step 1: Connect the boards

AVR boards are programmed with the SPI interface (COPI, CIPO and SCK signals). On many boards (including UNO, Mega, and Nano), these are available in two locations:

  • The digital and power pins. These are the most commonly used pins on Arduino, and you’ll only need six standard male-to-male jumper wires.
  • The ICSP header. CIPO, COPI, and SCK are available in a consistent physical location on the ICSP header. You’ll need female-to-female jumper cables for these pins.

Note

It’s recommended to use a board of the AVR architecture as the programmer. Although the ArduinoISP programmer sketch will compile for many boards, you may experience issues running it on non-AVR boards.

These are examples of Arduino AVR boards that you can use as “Arduino as ISP” programmers:

Note

To use an Arduino AVR board that’s not included in the table below, check the pinout diagrams in Arduino Docs to find which pins to use for CIPO, COPI, and SCK. On some boards PIN 10 may not be available. In this case, change the line #define RESET 10 to use a different pin.

Option A: Using the digital and power pins

For each row in the table below, connect the programmer pin to the corresponding target pin.

PROGRAMMER BOARDTARGET BOARD
PIN 10RESET
COPI
UNO: PIN 11
Nano: PIN 11
Mega: PIN 51
COPI
UNO: PIN 11
Nano: PIN 11
Mega: PIN 51
CIPO
UNO: PIN 12
Nano: PIN 12
Mega: PIN 50
CIPO
UNO: PIN 12
Nano: PIN 12
Mega: PIN 50
SCK
UNO: PIN 13
Nano: PIN 13
Mega: PIN 52
SCK
UNO: PIN 13
Nano: PIN 13
Mega: PIN 52
5V5V
GNDGND

When the boards are connected, you can proceed with burning the bootloader in Arduino IDE.

Circuit Diagram. UNO and Nano connected with digital and power pins.
Example: Using an UNO to program a Nano (digital and power pins).

Option B: Using the ICSP header pins

The ICSP header on UNO R3, Nano and Mega.Note that the orientation of the header relative to the USB port is different on the Nano.

  1. Connect every programmer ICSP pin except RESET to the equivalent ICSP pin on the target.
  2. Connect PIN 10 on the programmer board to any RESET pin on the target.
Circuit Diagram. UNO and Mega connected with ICSP pins.
Example: Using an UNO to program a Mega (ICSP pins).

Step 2: Burn the bootloader in Arduino IDE

Now that the board connections are set up, we can use Arduino IDE to burn the bootloader.

  1. Open Arduino IDE.
  2. Connect the programmer board to the computer.
  3. Select your programmer board in Tools > Board, for example Tools > Board > Arduino AVR Boards > Arduino Uno.
  4. Select the port the board is connecting to in Tools > Port.
  5. Open File > Examples > 11.ArduinoISP > ArduinoISP.IDE with ArduinoISP example selected in the menu
  6. Click Upload button Upload to upload the sketch to the board.
  7. Select the target board in Tools > Board.
  8. Select Tools > Programmer > Arduino as ISP.
  9. We can now start the burning process. It’s a good idea to enable verbose upload output in preferences since there will be no console output during the process otherwise. To start the process, select Tools > Burn Bootloader.IDE with Burn Bootloader selected in the menu
  10. Wait for the process to complete, which may take up to a minute. When it’s finished, the message “Done burning bootloader” will appear on top of the console, or in a bottom-right notification pop-up, depending on your IDE version.IDE with "Done burning bootloader" message

Troubleshooting

Error: Missing programmer

avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

Error while burning the bootloader: Failed chip erase: uploading error: exit    status 1

Check your selection in Tools > Programmer.

Error: Failed chip erase: uploading error: exit status 1

Error while burning the bootloader: Failed chip erase: uploading error: exit status 1
  • Make sure you’ve selected the target board in Tools > Board.
  • Make sure you’ve connected the RESET pin correctly.

avrdude: Error: Could not find USBtiny device

Error while burning bootloader.
avrdude: Error: Could not find USBtiny device (0x2341/0x49)

Make sure you’ve selected Arduino as ISP in Tools > Programmer, and not ArduinoISP or other similar options.


Further reading

Link:https://support.arduino.cc/hc/en-us/articles/4841602539164-Burn-the-bootloader-on-UNO-Mega-and-classic-Nano-using-another-Arduino