Burn the MYSBootloader on the ATMega328P MCU

The bootloader is a small program resident on the MCU memory that allows to install new firmware through a serial connection, without the need of an external programmer.

The Arduino bootloader is optiboot and, for example, it is installed in the ATMega2560 microcontroller embedded in the d-diot board.

The optiboot doesn't support the upload of the firmware over the air (FOTA), but here comes into play the MYSBootloader developed by the MySensors team, that in combination with a NRF24L01 radio module, enables this feature, at least for the ATMega32P MCU.

Another advantage of the MYSBootloader is that it supports three different operating frequencies of the ATMega328P MCU:

  • 16 Mhz with an external oscillator (like the Arduino UNO board)
  • 8 Mhz with the internal oscillator (like the Arduino Pro Mini board)
  • 1 Mhz with the internal oscillator (none of the Arduino boards use this frequency)

For each operating frequencies there is a lower voltage limit (see picture below) that can not be exceeded, otherwise the ATMega32P became unstable and it does not work properly.

ATMega328P frequency vs Vcc

The support for the 1 Mhz operating frequency is fundamental for battery powered boards like this one, especially if the voltage provided by the battery is < 2.4V, like in the case of 2 x AAA rechargeable batteries.

There are several methods to burn the bootloader into the ATmega328P, below the most common (and easiest).

Probably this is the easiest method. You need:

  • A working installation of the Arduino IDE with MySensors libraries and MySensors official hardware installed
  • A cheap (about 1.50€) USPasp programmer, possibly with a selectable output voltage (3.3V and 5.5V)
USBasp programmer with selectable voltage (3.3V and 5V)

To install the Arduino IDE in your PC and to add the MySensors library, you can follow this guide.

Once you have installed the MySensors libraries, you have to:

  • Copy the MYSBootloader .hex files (available here) to the [Arduino IDE installation folder]/hardware/arduino/avr/bootloaders/MySensors/
  • Add this lines into the [Arduino IDE installation folder]/hardware/arduino/avr/boards.txt file in your Arduino IDE.

Restart the Arduino IDE and you are ready to burn the MYSBootloader on your ATMega32P MCU or Arduino board. To do that follow this steps:

  1. Select the appropriate voltage (it depends on your board) and connect the USBasp programmer to the ICSP header of your board and to one USB port of your PC
  2. In the Arduino IDE go to Tools → Board and select “ATMega328p with MYSBootloader 1.3.0”
  3. Go to Tools → Frequency and select your desired frequency (it depends on your board)
  4. Go to Tools → Programmer and select “USBasp”
  5. Click Tools → “Burn Bootloader”

Done! You should see a success message in the CLI bar of the Arduino IDE.

If you are using a Linux OS it is possible that you can encounter some permission issues with the USBasp programmer. The solution is simple, follow this guide.

This method is very similar to the previous one, but in this case an Arduino UNO board is used as an ISP programmer.

The wiring diagram and the procedure are the same described in the guide for flashing the Arduino bootloader into the ATMega2560 MCU embedded in the d-diot board.

The steps in the Arduino IDE are the same described in Method 1, except for the step 4 that becomes:

  • Go to Tools → Programmer and select “Arduino as ISP”

  • how_to/mysensors/burn_mysbootloader.txt
  • Last modified: 2019/12/31 13:38
  • by franzunix