How to Install an Arduino Bootloader
Do you have a bricked Arduino board that won’t upload code anymore? Here’s some help.
Installing a bootloader is the first step in bringing your Arduino projects to life. This is a piece of software that helps you frequently upload Arduino sketches with ease onto the board without the need for special programming equipment.
While this may sound like rocket science, it’s actually simpler than you may think—even for beginners. We’ll show you how to easily install (or reinstall) a bootloader on your Arduino board in just a few simple steps.
But first, what exactly is a bootloader on the Arduino board?
What Is a Bootloader?
An Arduino bootloader is a small program that is stored in the board’s non-volatile memory that gets executed every time the board is powered on, uploaded with new code, or gets reset. Whenever the bootloader program is executed, it initializes the board’s hardware and then loads the main sketch or program that is stored in the board’s flash memory.
It’s worth noting that all Arduino boards ship with a pre-installed bootloader from their manufacturers. You may find boards with faulty bootloaders right out of the box sometimes. However, this rarely happens.
Why Use a Bootloader?
There are several situations where using an Arduino bootloader can be useful. For example, if you are a beginner to the Arduino platform, using a bootloader can make it easier and faster to upload new programs to your board. This is because you do not need to use external programming devices, such as a programmer or a USB-to-serial converter, to upload your code.
If you are working on a project that requires frequent updates to the code, you’ll find it very useful. In this case, using a bootloader can save you time and effort, as you can simply upload the new code to the board without having to use external programming devices.
Additionally, if you are working on a project that requires the Arduino to be in a specific state when it is powered on, such as running a particular program, then using a bootloader can be useful. The bootloader allows you to set the initial state of the board so that it will automatically run the desired program when it is powered on.
Lastly, it provides a way to recover the Arduino if the main sketch becomes corrupted or otherwise fails to run.
Why Is My Bootloader Missing?
There could be four possible reasons why your board may need a new bootloader:
- No pre-installed bootloader: It is pretty common to have many ATMEGA328P stand-alone projects where you solder your chip onto a PCB and happen to fry the chip. It could thus be possible that you replaced the board with a chip without prior bootloader installation.
- Replaced bootloader: You could have replaced your bootloader with a modified third-party bootloader that could be corrupted.
- Corrupted bootloader: This is the least likely scenario. However, in some cases, the Arduino flash memory can get corrupted.
- Extended memory: If you replaced (flashed) the entire bootloader with your application to enjoy the remaining 2K of program memory, your bootloader is definitely missing.
Here’s what you need to do.
Installing/Re-Installing the Arduino Bootloader
Microcontrollers are typically programmed before being soldered onto a PCB. This is typically done using In-System Programming (ISP), such as In-Circuit Serial Programming (ICSP), which allows the microcontroller to be programmed using an external programmer. Many microcontroller manufacturers, such as Atmel and Microchip, provide an ISP header on their boards for this purpose.
Using Another Arduino Board
In order to flash the bootloader on an ATmega328 microcontroller, you need to use the ICSP header on the board before you can install the bootloader using the other board as an ISP programmer.
Launch the Arduino IDE, navigate to ArduinoISP as shown below, and upload the example code to the board you intend to use as a programmer. (Follow the video tutorial for hardware hookup).
The code should look like this just so you know you are on the right track.
From the Tools tab, go to Programmer then click on Arduino as ISP as shown below.
Finally, from the Tools tab again, click on Burn Bootloader as shown.
Once the process is complete, the target board is now ready to be programmed.
Using a Dedicated Programmer
There are many AVR programming devices available for this kind of installation. One good option you can try is the AVR Pocket Programmer (Windows only) based on Dick Streefland’s USBtiny and Limor Fried’s USBtinyISP. It offers a simpler way to program AVR microcontrollers, like the ones found on Arduino boards. Other than the fact that it’s powered by a USB connection. It’s the best option because it’s compatible with a variety of programming languages and software. Making it a versatile tool for any Arduino user.
You can also try other options like the official Atmel-ICE programmer for ARM microcontrollers. Especially if you are not on Windows.
Wiring
Hook up the Arduino board to the programmer and flash the bootloader. Refer to this video tutorial below.
The process should be simple and not take more than 20 seconds.
Note: The target board should be powered on properly before attempting this method. Otherwise, you will not be able to flash the .hex file to your target.
For power users, there is a more complex way to install the bootloader using the command line. It’s not necessary to get to this stage, but it gives you the power to modify or recompile the code to get a more customized experience.
The first step in the process is to configure the fuse bits. Which are part of the AVR chip, and control settings such as the use of an external crystal. Use the following command to set your fuse bits:
avrdude -b 19200 -c usbtiny -p m328p -v -e -U efuse:w:0x05:m -U hfuse:w:0xD6:m -U lfuse:w:0xFF:m
After the fuse bits have been configured. The next step is to transfer a compiled .hex file to the target board and set the lock bits. This will allow you to run the program on the board. Ensure you are in the same directory as the optiboot_atmega328.hex file before keying in this command:
avrdude -b 19200 -c usbtiny -p m328p -v -e -U flash:w:hexfilename.hex -U lock:w:0x0F:m
Note: These commands are for the Arduino Uno. You’ll need to refactor the fuse bits for your board found in the board.txt file and tweak the AVRDUDE’s part number parameters as well for them to work.
Read More: How to Install an Arduino Bootloader – MakeUseOf