Atmega328P-PU Bootloader (Optiboot) Burning Guide

30K2330

Intro: Atmega328P-PU Bootloader (Optiboot) Burning Guide

Yet another Atmega bootloader burning giude. But this time i bet on the first attempt you will succeed!!

This is Nick Gammons bootloader burning tutorial for Arduino boards.

STEP 1: A Few Words

The Atmega328P-PU microcontroller is one of the most popular Arduino chips that are used in a wide range all over the world. But most importantly the bare bones Atmega still does what the standard Uno R3 can do. The main reason why i love this microcontroller is the "Low Power" mode. I have written a some new sketches for a few sensors and i am testing them for a time now.

Back in a few years when i started to play with Arduino my first order was a Atmega328P microcontroller. Later i realised that the ones i ordered from Aliexpress are blank chips. The chips are very cheap on Ali , you can buy them from 1.40$. But they have not contained the Uno Bootloader (Optiboot) and without it i could not upload any sketches. Tough break ha??!! It was a really cold shower for me .......So i was searching for a way to burn the bootloader into the chips. I have tried 5 or 6 methods, but no luck. After a week i found a topic on a website forum that mentioned Nick Gammon's bootloader burning tutorial. First attempt and SUCCESS!! :D Now i will show you how to burn the bootloader to blank Atmega328P-PU chips easily without messing up stuff in Arduino IDE.

STEP 2: What Is the Bootloader? (Optiboot)

The bootloader is a small program (HEX file , 0.5Kbyte)that allows you to upload sketches to the flash memory directly from Arduino IDE. The HEX file always runs before the main program and that's why it is needed.

Whithout the bootloader :

-The microcontroller still CAN BE PROGRAMMED!(yes, it is possible), but you would need a dedicated AVR programmer to do that. And it is not cheap!

- It can not be programmed through the Arduino IDE.

Supported bootloaders of this method:

Atmega8 (1024 bytes)

Atmega168 Optiboot (512 bytes)

Atmega328 Optiboot (for Uno etc. at 16 MHz) (512 bytes)

Atmega328 (8 MHz) for Lilypad etc. (2048 bytes)

Atmega32U4 for Leonardo (4096 bytes) Atmega1280 Optiboot (1024 bytes)

Atmega1284 Optiboot (1024 bytes)

Atmega2560 with fixes for watchdog timer problem (8192 bytes)

Atmega16U2 - the bootloader on the USB interface chip of the Uno

Atmega256RFR2 - the bootloader on the Pinoccio Scout board

The code for the following bootloaders is incorporated in the sketch, and will be downloaded depending on which signature is detected.

So we have everything we need.

STEP 3: Arduino Sketches Master

First of all you need the arduino library.

Download it from here: https://github.com/nickgammon/arduino_sketches

Or download it from here.

After you have downloaded extract it to Arduino libraries forlder and look for Board Programmer. Open it and run Board Programmer.ino.

STEP 4: The Hardware Setup

There are 3 ways to wire up before programming:

- Use the AVR ISP shield

- Arduino A to Arduino B

- And the breadboard method

On the picture you can see how to wire up. On the breadboard the ceramic capacitors are not really needed, but the 16Mhz crystal must be added.

I am using my AVR ISP shield this time.

The goal of this method is, that the program is using the serial monitor to access the flash memory to write the Optiboot (bootloader)

STEP 5: The Programming!

After the hardware setup is complete run Board Programmer.ino!

Compile and upload to your Arduino, but don't close the window!! You will need it :)

The upload will take a few seconds.

STEP 6: Disconnect!

After you uploaded the sketch disconnent the Arduino from your PC and wire up everything if you planning to do this on the breadboard.

If you use the AVR shield put the Atmega chip in the ZIF socket and "lock" it down.

Very important: As long as the hardware is not set up, the processor must not get VCC!! That way you risk a damage!!

STEP 7: Connect!

Ok! The hardware is set up and everything is in place we connect the Arduino to the PC.

Next open the Serial monitor and set the baud rate 115200 and you will see this.

In the serial monitor you can see that the Arduino has entered programming mode. Cool!! :)

Since we want to program Uno (Atmega328P) type a "U" on the in the message prompt and hit enter.

STEP 8: Programming State!

In the next window you will see this.

We won't quit or Verify, type a G and hit enter!

STEP 9: The Fun Begins! :)

After hitting enter you will see this:

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 = 0xEF
Clock calibration = 0x9E

Done.

Programming mode off.
Type 'C' when ready to continue with another chip ...

And happy day!! :D Your Atmega328P chip is now ready to upload sketches!

This was easy wasn't it? :)

STEP 10: A New Chip!

If you want to program another chip disconnect Arduino from your PC, replace the chip with a blank one. Reconnect Arduino and do the steps again.

If the serial monitor does not respond after reconnecting the Arduino, don't panic just close it and open a new one.

STEP 11: DISCLAIMER!!

I DO NOT OWN ANY OF THIS!! All the credit goes to Nick Gammon!!

I just showed this method in this Instructable.

Hope you will find this useful.

Have a nice day.

STEP 12: When Weird Stuff Happen

Recently i received this Arduino Nano with Atmega328P-MU processor.

So i have tried uploading a sketch to it, but i could not. The processor not responded to anything with options Atmega328.

OK! So maybe the bootloader is corrupted and needs a rewriting. I wired it up with another arduino and done the bootloader burning. Still nothing......!!!!

Ok then, i need a brake (coffee and a cigarette)!! As a last chance i selected Arduino Uno again as a target. Upload complete :D

At this time i have a Nano that acts like a Arduino Uno. I don't know why this happened but i think this is because of the Processor signature. Anyway it really made my day and it is a bit funny :)

19 Comments

Some cheap Nanos ship with "ATmega328p (Old Bootloader)" This must be selected on the IDE. If you want the new bootloader:' Atmega328 Optiboot' to gain some space in flash 0.5 instead of old bootloaders 2k, you can burn the new bootloader as an UNO (Julian Ilet has a YouTube video) As well as gaining some memory it will also correct the WDT reset bug of the old bootloader;) ALSO....The 'Arduino As ISP' bootloader sometimes does not work because some Nanos are shipped with ATMEGA 328PB chips instead of 328P. AVRDUDE expects a response of 1E950F from a P chip and gets response 1E9516 from a PB. So it gives an error. I'm not sure if this matters if using the Gammon sketch... must try it:) I found this page which explains and gives a workaroud if using Arduino to burn the bootloader on a Nano with 328PB. Sorry it's in French. http://riton-duino.blogspot.com/2020/01/arduino-le-bootloader.html
Good point! :)

Interesting facts. I have read that postand learned something new.
Good tutorial; I have some questions:
1) Should the Mainboard (not Target) have the Optiboot Bootloader updated or not necessarily?
2) Does the procedure also fit the Arduino Nano?
3) To record the sketch 'Board Programmer.ino' must be selected 'Arduino Uno' as board ok?
4) And if it is to write Bootloader to a Nano, should 'Arduino Nano' be selected as board?
Thanks
1. Not it is not important to use only an Arduino uno with optiboot. You can use Mega2560 as well.
2. Yes it fits the Nano as well.
3. Yes it is ok.
4. No. Since you are using the serial monitor no need to change the board type. The only option counts, what board are you uploading the program.
Sorry for the late response.
Sorry, I'm not satisfied yet.
After loading 'Board Programmer.ino' on Arduino Uno, to record Bootloader (Optiboot) on an Arduino Nano, which board should I choose from Tools > Board? Arduino Uno or Arduino Nano?
Thanks again
Ok :)
I will explain this shortly, because i see you misunderstood the steps.
You compile the sketch and upload it to an Arduino Uno, that is the programmer board and the only target. Disconnect the programmer board from pc, but you dont close the window. Next you connect the programmer board to the Nano which you want to bootload;Thus you connect the Uno and Nano SPI pins, see picture, it is the same for the Nano as well. After this you reconnect the Uno and open the serial monitor with 115200 baud rate. In the Arduino IDE there is no need to change the target, cause the Uno is the target on the available COM port,thus he is the programmer. Open serial monitor and pls take a look at Step 7.
I made a quick setup for you, i add the images. I bootloaded my nano again :D
This is the whole thing and i can not explain this more simple :)
OK, thank you so much, now I get it!
And almost forgot to mention. If you successfully bootload your nano it will have the risk that next time you can only upload sketches as an Arduino Uno. Because Nano uses the same Atmega 328P-Au chip.
Pls report back.

Good instructable Thanks

I used the same method to burn Lilypad Bootloard to 8 MHz without crystal quartz and it works well, I had tried with an Arduino UNO card and ISPS but nothing worked, I even lost my ATmega 328, fortunately, I was able to recover it thanks to Fusebit Doctor a dedicated and free PCB.

http://mdiy.pl/atmega-fusebit-doctor-hvpp/?lang=en

I am very glad that you find it useful. I burn bootloaders for a time now with this method and i have succeeded every time with it. That is why i made this instructable. Keep up the good work. Cheers!!

How would be best to do it if I wanted an 8Mhz 328, to run like a pro mini? The reason being, I need everything to run at 3.3v, not 5v.
Update: I could burn it with 8Mhz lilypad. Give it a go.
But try to burn it with Lilypad 8Mhz option. Maybe it will work. Sorry for that, but i did not experiment this kind of idea. But i will give it a try.
Although the chip has an internal 8Mhz crystal oscillator i dont think it is possible to make it like a 3.3V pro mini. The first problem is the chip signiture. The second is that you would need a different bootloader burning method. The chip uses 5 volt logic level. Even if you power it up with only 3.3 volts, a 3 volt logic level display will not correctly. With a 8Mhz bootloader, maybe. I did not succed with thoose methods at all. For that i use 8Mhz pro mini.
One of the best... it works :)
Worked perfectly, thank you for sharing this! :)