Language: EN

usar-arduino-para-reprogramar-el-bootloader

Using Arduino to Reprogram the Bootloader of Another Arduino

The Arduino bootloader is software stored in flash memory that allows us to program Arduino through the serial port without the need for an external programmer.

In short, during the Arduino boot process, the bootloader checks if the Arduino is being programmed. If so, it writes the program to memory and restarts Arduino. Otherwise, the bootloader runs the last recorded program.

The Arduino bootloader is one of the essential parts that make Arduino easy and convenient to use (and therefore successful). In general, we don’t usually need to deal with it.

However, there are several circumstances in which we may need to be able to modify the Arduino bootloader. For example:

  • Advanced users may want to modify and customize the boot process.
  • In large projects, we may want to use the space occupied by the bootloader.
  • Some manufacturers ship their boards without the preloaded bootloader.
  • In some cases, the bootloader may become corrupted.

In any of these cases, we do not need to have an external programmer but we can use another Arduino as a programmer to burn the bootloader onto an Arduino.

The Arduino that acts as the programmer will be called master, and the one we are going to program will be called slave. The communication between the PC and the master is done through the serial port, while the master will communicate with the slave through SPI.

Prepare the Arduino Master

First, we will set up our Arduino Master as a programmer. To do this, we simply have to load the “Arduino as ISP” sketch from the Arduino Examples library. We load it into the Master like any other sketch.

arduino-as-isp

That’s it. With this, we have turned our Arduino into an ISP programmer.

Connect Arduino Master with Slave

Disconnect the master from the computer and connect the master and slave. To do this, power the Arduino Slave from the Master by connecting Vcc and Gnd from both boards. On the other hand, connect the SPI bus pins between both boards.

If, for example, we are using an Arduino UNO as the Master programmer and an Arduino Mini as the slave, the connection scheme on the master to the slave pins would be as follows.

arduino-grabar-bootloader-master

While the connection seen from the slave (Mini in the example) to the master’s pins would be as follows.

arduino-grabar-bootloader-slave

Burning the Bootloader

Now we can proceed to burn the bootloader onto the Arduino. Connect the master to the computer via the serial port, keeping the connection between master and slave.

Set up the Arduino IDE. Select:

  • The COM port to which the master is connected.
  • The board model of the slave
  • As the programmer, “Arduino ISP”

arduino-as-isp-2

Finally, select “Burn bootloader” to start the recording process.

arduino-as-isp-3

After a lot of blinking lights and flashes on the LEDs of both boards, we will see a message in the IDE indicating that the bootloader has been successfully burned.

There you go, we have successfully burned the bootloader, and we can disconnect both Arduinos and use them as usual.

Download the code

All the code from this post is available for download on Github. github-full