I was instructed to "burn the bootloader" to my Arduino to fix an error I was getting. How can I do this? (And what exactly is the bootloader?)
The bootloader is a small program that is (almost) always on an Arduino. It manages uploading and starting the sketches you make, and blinks the pin 13 LED whenever the board resets.
To burn the bootloader:
- Obtain an AVR ISP, USBtinyISP, ParallelProgrammer, or another Arduino board. This will be your ISP.
- Unless otherwise instructed, connect the ISP to the ICSP pins on your board.
- Power your board with either a USB cable or an external power supply.
- Open up the Arduino IDE.
- Make sure you selected the correct board that you are burning to at
Tools ► Board ►in the IDE. Double-check this even if you could upload programs correctly; uploading doesn't always require the right board.
- Select the appropriate programmer at
Tools ► Programmer ►.
Tools ► Burn Bootloader, and wait. It shouldn't take more than a minute, and often takes only a few seconds.
What is a bootloader?
And what exactly is the bootloader?
The bootloader is a small piece of code residing in the "high" part of program memory. Normally it is not erased when you upload new sketches. Its purpose it to be activated immediately after a reset (the fuses are configured to commence code at the bootloader address rather than address 0x0000). The bootloader will wait a short time (such as one second) to see if "programming" data is arriving on the serial port.
If so, it reads that data, and decodes it to reprogram the rest of the flash memory. Working in conjunction with the uploading program (normally avrdude) the new sketch is sent via the serial port. The bootloader erases pages of flash memory, and replaces them with the new code. Once done, it executes the new code.
If no instructions arrive, the bootloader jumps to address 0x0000 to execute the existing sketch on the board.
How to replace the bootloader
An alternative method to program a bootloader is to use a sketch I wrote a while ago which runs on a:
- Uno (or similar, such as Duemilanove)
The "programming" board runs the sketch which has bootloaders for a number of boards hard-coded into it. You connect the programming board to the target board (the board wanting the bootloader) with 6 hook-up wires as shown.
That particular photo illustrates one Uno programming another one.
You run the sketch (operating via the Serial Monitor to give it commands). First it identifies the target chip:
Atmega chip programmer. Written by Nick Gammon. Entered programming mode OK. Signature = 0x1E 0x95 0x0F Processor = ATmega328P Flash memory size = 32768 bytes. LFuse = 0xFF HFuse = 0xDE EFuse = 0xFD Lock byte = 0xCF Bootloader address = 0x7E00 Bootloader length = 512 bytes. Type 'L' to use Lilypad (8 MHz) loader, or 'U' for Uno (16 MHz) loader ... Type 'G' to program the chip with the bootloader ...
The you press G to program it.
Erasing chip ... Writing bootloader ... Committing page starting at 0x7E00 Committing page starting at 0x7E80 Committing page starting at 0x7F00 Committing page starting at 0x7F80 Written. Verifying ... No errors found. Writing fuses ... LFuse = 0xFF HFuse = 0xDE EFuse = 0xFD Lock byte = 0xCF Done. Type 'C' when ready to continue with another chip ...
For a Uno this takes one second. To program a Mega2560 takes 3 seconds.
Detailed instructions at Atmega bootloader programmer
Code can be downloaded from Github: nickgammon/arduino_sketches