If you are building your own Arduino, or need to replace the IC, you will need to load a bootloader program into the Atmega328 (on UNO and BBFuino). There are also cases where you have put your board into a weird setting and you cannot upload code into it, reinstalling the bootloader will be the easiest and quickest way to fix it.
What is a bootloader?
A bootloader is basically a .hex file that runs when we turn on the Arduino board and allows us to program Arduino board over the serial port. It is very similar to the BIOS that runs on our PC. Without the bootloader, we will need a special programmer, i.e. AVR USBASP Programmer, to program the Atmel AVR. Due to the effort of Arduino, now we just need a USB cable (on Arduino UNO) or USB to serial converter (On BBFuino) to program our Arduino board.
This tutorial will hopefully show you how to burn the bootloader into an Arduino board, and there is 3 sessions in this tutorial:
- Session 1: Burn Bootloader into CT-UNO
- Session 2: Burn Bootloader into BBFuino
- Session 3: Burn Bootloader into standalone Arduino
Session 1: Burn Bootloader into CT-UNO
Basically there are two steps involved in burn bootloader:
- Step 1: Prepare ISP Programmer
- Step 2: Burn Bootloader
An ISP (In-system programming) programmer is needed to burn bootloader. In this tutorial, we will use a CT-UNO as an ISP programmer. To prepare CT-UNO as ISP programmer, firstly we select “ArduinoISP” from the File > Examples menu.
And upload it into CT-UNO.
After done uploading, we select “Arduino as ISP” from the Tools > Programmer menu.
Now the CT-UNO is working as an ISP programmer.
The next step is to do some wiring between ISP programmer and target Arduino, the connection is shown in table below:
|ISP Programmer (CT-UNO)||Target Arduino Board|
|Pin 13||Pin 13|
|Pin 12||Pin 12|
|Pin 11||Pin 11|
Or, you can refer figure below:
After wiring up, go to Tools > Board and choose “Arduino Uno” as the board of the target Arduino.
After that, click on “Burn Bootloader” from the Tools menu, the ISP programmer will start to burn the bootloader into the target Arduino. It usually takes few minute to complete burning bootloader.
Burn bootloader is in progress.
Arduino IDE will display “Done burning bootloader” when it is done.
After complete burn bootloader, your target Arduino is able to accept code from your Arduino IDE. Just unplug the ISP programmer and plug the target Arduino to PC via USB cable, and you can upload your sketch to the target Arduino as usual. Remember to change the Tools > Programmer from “Arduino as ISP” to “AVR mkII” before you upload sketch to the target Arduino.
Session 2: Burn Bootloader into BBFuino
BBFuino, or Breadboard Friendly Arduino, is the first Cytron version of Arduino compatible board. It is designed to fit breadboard for prototyping and learning purpose. An USB to UART converter, i.e. UC00A or UC00B, is required to upload Arduino sketch into BBFuino. If you get the BBFuino from Cytron, it is preloaded with bootloader :). So the following steps are only applicable if you replace fresh new IC on BBFuino, or in some cases, you corrupt the bootloader.
BBFuino is using ATmega328 IC instead of ATmega328P IC (at the time this tutorial is written). ATmega328 and ATmega328P are almost similar. The difference between these ICs is ATmega328P has the Atmel picoPower technology while ATmega328 does not have. With picoPower technology, ATmega328P are suitable to be used in low power application. Besides, only the ATmega328P is recognized by Arduino whereas the ATmega328 is not. Hence, it may cause an issue that we cannot burn bootloader into ATmega328 using the method we discussed in session 1. When we try to burn the bootloader into ATmega328, you will obtain the error as shown in figure below:
This is due to ATmega328-PU and ATmega328P-PU have the different identification signature: ATmega328 has signature of 0x1E 0x95 0x14 while ATmega328P has the signature of 0x1E 0x95 0x0F.
Can we still burn the bootloader into ATmega328? The answer is YES! There are two methods can be used to burn the bootloader into ATmega328:
- Burn the Optiloader into ATmega328.
- Modify the configuration of Arduino IDE.
The first method is burn the Optiloader into ATmega328. Optiloader is a sketch designed for bulk upgrading of Arduino board bootloaders using another Arduino as an ISP programmer. It is suitable for microcontroller ATmega8, ATmega168, ATmega328 and ATmega328P. To burn the Optiloader, just follow the procedure below:
- Download the Optiloader in Github. Click on “Download ZIP” to start the download.
- After done downloading, extract it using any unzip software.
- There is 3 files in the OptiLoader – master directory, open the optiLoader.pde file using Arduino IDE.
After a couple second, a window will pop out and prompts you whether you wanna create a sketch folder named “optiLoader” and move the optiLoader.pde inside that folder. Click on “OK”.
optiLoader.pde is opened:
- OptiLoader.pde requires its library file to be included in the sketch file. Else, this sketch file cannot be compiled. To include the library file, first click on “Add File…” from the Sketch menu
Choose the “optiLoader.h” library file from the Optiloader – master directory and then click “Open”.
After you click “Open”, you will notice that there is a “optiLoader.h” tab beside “optiLoader” in the Arduino IDE:
- Connect the CT-UNO and BBFuino as figure below:
- Upload the sketch. It will takes up to 2 minutes. Be patient!
- The upload sketch process is completed when Arduino IDE displays “Done uploading”, at the same time, the BBFuino is completed burnt with optiLoader too!
Now the BBFuino is ready with bootloader firmware and can be use with UC00A to accept code from Arduino IDE.
The second method is modify the configuration of Arduino IDE. As we mentioned earlier, the difference between ATmega328 and ATmega328P are the picoPower technology and their identification signature. Other than that, ATmega328 and ATmega328P are the same every sense architecturally. Hence, we can modify the configuration of Arduino IDE so that Arduino IDE can treat ATmega328 as ATmega328P.
There are 3 steps for this method.
The first step is preparing an ISP programmer. Refer to session 1 to turn CT-UNO into an ISP programmer.
The second step is modifying the configuration of Arduino IDE, just follow the procedure below:
- Close the Arduino IDE.
- Locate your Arduino directory. In my case, my Arduino directory is C:\Users\user\Desktop\arduino-1.0.5
Then, locate the directory hardware\tools\avr\etc. You will notice there is a file named “avrdude.conf” inside that directory.
- Make a copy of file “avrdude.conf” for backup purpose.
- Open the file “avrdude.conf” using WordPad.
- Search for “m328p”.
- Look for “signature”. It should be few lines under “m328p”.
Change 0x1e 0x95 0x0f to 0x1e 0x95 0x14
- Click “Save” to save the edited configuration file and close it. Now you done modified the configuration of Arduino IDE.
The third step is burn the bootloader. First, connect the ISP programmer to the BBFuino:
Next, select “Arduino Uno” from the Tools > Board menu.
Click on “Burn Bootloader” from the Tools menu and wait for few minutes for burning bootloader process.
After the burn bootloader process is done, the BBFuino is ready with bootloader firmware and can be use with UC00A to accept code from Arduino IDE.
For this method, if you plan to burn the bootloader or load the program into ATmega328P device, i.e. CT-UNO, be sure you modify the configuration of Arduino IDE before you burn the bootloader or load the program. This is because after modify the configuration, ATmega328 is recognized by Arduino IDE but ATmega328P is not. Repeat the modifying the configuration of Arduino IDE procedure and change the signature from 0x1e 0x95 0x14 to 0x1e 0x95 0x0f.
Session 3: Burn Bootloader into standalone Arduino
Standalone Arduino is the ATmega basic circuit, it is the simplest form of Arduino. Sometime it is called as Arduino on breadboard too.
The hardware required are:
For your information, the ATmega328P ICs carried by Cytron are pre-loaded with Optiboat bootloader. You do not have to burn the bootloader into it before using it.
Construct the standalone Arduino circuit as shown in figure below:
If you refer the datasheet of ATmega328P, you will find that there are Port A, Port B, Port C and Port D in the pinout diagram of ATmega328P. Where is the digital pins and analog pins those label on the Arduino board? Don’t worry, figure below can help you to find out the pin location of Arduino digital pins and analog pins. Figure below is the ATmega168/328-Arduino pin mapping diagram.
Similar with session 1, there are two steps in burning bootloader into standalone Arduino.
The first step is preparing the ISP programmer. Referring to session 1 to turn CT-UNO into ISP programmer.
Next, connect the ISP programmer to the standalone Arduino:
Select “Arduino Uno” from the Tools > Board menu:
Click “Burn Bootloader” on the Tools menu and wait for few minute for burning bootloader process.
After the burn bootloader process is done, the standalone Arduino is ready to accept code from your Arduino IDE. To program it, you can use the CT-UNO as ISP programmer to upload code into the standalone Arduino.
Great! I am done sharing the possible method to load bootloader into Arduino main controller, hopefully it is helpful and if you have any inquiry, please do discuss in our technical forum as we seldom check the comment section in tutorial site. Do bear in mind, once the bootloader is successfully loaded into Atmega, you can utilize bootloader to load new program via normal method from Arduino IDE.