Burn a bootloader to a blank atmega328/atmega328p with an Arduino UNO

optiLoader shield

Build your own optiLoader shield!

You cant use your Arduino UNO as programmer unless you modify it, but i didnt want to do that!

Some people had luck using a Resistor and Capacitor to disable the auto reset feature but it did not work for me (Using an Arduino UNO R2)

So i tried using a parallel port programmer but never got it to work. It seems easy, so if your interested go ahead and try it yourself, but be warned, could lead to frustration :)

Fortunately Bill Westfield wrote optiLoader!

 

The readme file doesent tell you how to connect the blank chip so i asumed that you need an oscillator and a pull up resistor and... well... it worked! (for me)
A nice thing about optiLoader is that is supports multiple chips, even atmega328 (non p) - the cheaper version whithout "pico power" features.
That way you dont have to edit your avrdude's config file, after bootloading a atmega328 the bootloader lies to avrdude telling that he is a atmega328p, keeping em quiet :)

 

You need:

  • Working Arduino (with µC and Bootloader) - optiLoader will run on that one
  • 16MHz oscillator
  • 2 x 22pF ceramic capacitor
  • 10KΩ resistor

Update: 
If your chip comes straight out of the factory it 'should' be fused to work without an external clock -  meaning that you don't need the clock and the two capacitors.
But if you allready burnt a bootloader (even if it was aborted) or your supplier modifed the fuses for some reason - you need them.

Breadboard setup looks like this:

optiLoader on breadboard

Powering the circuit over pin 9 is questionable, but seems to work well with this setup (look at optiLoader source files for more info on this).

After downloading optiLoader go to the directory where your sketches reside and create a new directory named 'optiLoader' and put the files inside it.
Structure should look like this:

optiLoader/optiLoader.pde
optiLoader/optiLoader.h

If you use Arduino SDK 1.0 it will ask you if it should rename it to .ino -> Allow that. 
Now upload optiLoader to your arduino and connect the serial monitor (with 19200 Baud) to see what is going on.
You dont even need the serial monitor, but thats the only way to get feedback on the process.

If you plan to make a shield out of this circuit you could learn from my mistakes:
Look at the main image on top of this page, i forgot to leave room to get to the reset button :)

Tags: 
arduino
bootloader
atmega328
atmega328p
optiLoader on breadboard

Comments

Hi Flo, Excuse my basis question. How do you load the optiloader to Arduino?I am able to downlaod optiloader.h and optiloader.pde, but do not know how and were to incorporate them in the Arduino folder so that the IDE could detect them and upload them as a sketch into the arduino. thanks

This worked like a charm - totally painless. After hours and hours of messing around with a regular Amtel 328-pu (not 328p), setting fuses etc, this was a one show solution that worked 100%. Burned 10 chips in about 3 minutes.
flo's picture

@Paul You have to get the folder structure right, like: Arduino/optiLoader/optiLoader.ino Arduino/optiLoader/optiLoader.h Arduino refers to the directory yours sketches reside, you have to create the optiLoader directory

Hi! Excelent blog! Is the optiLoader only for burning bootloaders? or I can burn any firmware to an Atmega168P ?? Thanks!

Great tutorial, thanks a lot! Is there any possibility to test if the bootloader updated successfully? I'm using an Atmega8 - 16 PU (instead Atmega328) an cannot upload any sketch to the Atmega8. It say "avrdude: stk500_recv(): programmer is not responding"... PLEASE help me! :)

Great post. Helped me get to where I needed to in flashing some atmega328(s) with my Arduino UNO boards. Side note, I couldn't get the board to work, so in reading the author comments in the code, you can use 2 Arduino uno boards instead of building your own breadboard. Worked great for me. Granted, you'd need two Arduino boards, but if you've got them already.... :)

Hm, looks like I'm not so lucky. I'm trying to progam a set of 328p (fresh out of the tube) and can't get past go. Using rather primitive means (led and resister) I'm able to see activity on MOSI and SCK, but nothing coming back on MISO. The result read by OptiLoader is 0x00. I can pull MISO high and see the expected result OxFF but the 328P seems dead to the world. I've been over the wiring a couple of dozen times so I'm pretty sure I've got it as shown above. Any suggestions? If I've read my documentation correctly no crystal should be required as the default fuses are set for internal clocking.

Hi Flo, After searching the web and trying all kind of solutions how I'am able to burn a bootloader on a blank AtMega328P-PU I finally found yours and YES this one works using the sketch from Bill Westfield..! I have the latest Arduino Uno Revise 3 and after testing I found out that you need the external oscillator for this version of Uno. Thanks...

Hi Flo, Thanks for the post. I'm just a bit lost. I assume you are using the Arduino software (Arduino-0023) to program the working uC that will in turn bootload the "virgin" uC? I'm having a problem in that the optiLoader.pde and .h do not compile, so can't really get further than that. Am I doing something wrong? Sorry, just need a little more info on the software side. Thanks so much!

Hi Flo, thanks for sharing this. I'm a newbie and don't know much about electronics and microprocessors. So I have question to you, what do you mean by an "Arduino (with µC)"? I had google it and still cannot find an answer. I bought a Arduino UNO RV2 and want to be sure that this will work. Thanks for clarifying. Erick

I am getting the following errors when I verify the sketch file, any ideas? Thanks optiLoader.pde:-1: error: variable or field 'read_image' declared void optiLoader.pde:-1: error: 'image_t' was not declared in this scope optiLoader.pde:-1: error: 'ip' was not declared in this scope

Beware that not all suppliers ship the chips with the default fuse settings. In my case I bought a couple of 328Ps from Mouser. They came with the clock fuses set to external. This meant that I did indeed need the crystal and caps. Once I had those in place it worked like a charm
flo's picture

Sorry for the long delay, looks like the blog's notify function is broken... @Willy Its only for burning the bootloader, lookup ArduinoISP - might be what your after... @Daniel Connect over serial to get some feedback... But i'm not sure if its even posssible with an Atmega8 because optiLoader loads the complete bootloader into RAM bevore writing it. And if this fails it just resets in the middle of the operation. @Wing Tang Wong I think that was the original purpurse of this sketch - using two arduinos - but i didn't want to buy another one :) @Gray, @Morfus I guess i should be more precise about the clock in the blog post - i'll update it @Barney, @Terry I will add more info @Erick Yes this works with a UNO R2. And with 'with µC' i mean an Arduino with the microcontroller in place - thats the way they ship it, so you should be fine

Thanks a lot...it works in both ways...first I upload the optiloader sketch with the blank ATMega conected...so I think it reprograms the fuses...not works...next I connect 5 more new Atmegas (blank from Mouser) and it works Ok...next I add the 16Mhz circuit to the first Atmega and..it works!!!...all atmegas328P tested on the arduino board...great job and thanks for sharing...

Upadate went ok completed, Yeah! but im getting the same message stk500_rev().... My chip was previously screwed up by a parallel attempt... Any help would be appreciated

I've got a Uno R2 and I've hooked things up according to your schematic. I loaded the sketch and when I run the serial monitor I get the following message: OptiLoader Bootstrap programmer. 2011 by Bill Westfield (WestfW) Target power on! ...No RESET pullup detected! - no target? Target power OFF! Type 'G' or hit RESET for next chip

Check your wire going from pin 9. I had the same error. Now I get the error "Failed, result = 0x0" I am trying to program an ATMEGA8-16PU. Does anyone know what error this is (i suspect that it is the chip running out of memory, but am not sure), or does anyone know how I can program my ATMEGA8-16PU with my Arduino Uno. I want to be able to run multiple chips at once.

thank you. it's work 100% :)

For anyone else who has this problem. During compilation the optiloader.h file can't be found. In my case I had a misspelling. Once this was corrected it compliled.

For those programming Optiboot on a routine bases, you might find the ISP Shield from Evil Mad Science useful. http://evilmadscience.com/productsmenu/tinykitlist/253 It is available as a kit or bare pcb.

Many thanks worked perfectly for me,I had 2 atmega 328s non P and they now work on my bare bones board.

Thanks for this, it worked like a charm. I spent several days trying other methods. I would only add that if you have damaged your chip trying other methods, it will not work. Also you cannot run it twice on the same chip, it will fail the second time, but the chip works.

while burning the bootloader must the controller be already there in the board

HI, trying this setup, i get error "Starting Program Mode - Failed, result = 0x0" and the chip is getting very hot fast. i have a 4*33 ohm resistors for the reset pin, the 5v from arduino to the breadboard. my board is uno r3 and the chip is 328p-up any idea? thanks

I get this error: Starting Program Mode - Failed, result = 0x0 Changed 328's, same result. Any help?

Awesome site:)) I was searching exactly for this. I have a doubt. y have u connected Pin9 of the arduino(Programmer) to the positive rail of the breadboard. Why isn't +5v of the arduino connected to the breadboard?? Pls reply ASAP:) Thanks.

If this works i will be glad

Hi! just wanted to ask if i need to remove the existing atmega328 from my UNO-R3 before setting this up or not. thanks!

Thx, Its working perfect. I burn bootloader (optiLoader) to two ATmega328. 1st one require no external clock, but 2nd need. There was error for second one 'Starting Program Mode Failed, result 0x0' but it work when I connect 16MHz clock.

I would like to follow your method but bootloading different controllers : the attiny s'

Wow, great guide, I all worked perfectly with the oscillator and caps... My first project of this type... Thank you very much :-)

Hi man, I tried with a 328-PU, u know the cheap one, and I got this: Target power on! ... Starting Program Mode - Failed, result = 0x0 Target power OFF! I checked the wiring n I don't find any mistake...please helpme out.

Hi, I was having issues with this method, but I found on arduino forum, another simple way of wiring, it is just like if you where to use arduino ISP to burn the bootloader. http://arduino.cc/en/Tutorial/ArduinoISP thanks to this blog for show me the way to solve my problem!

HI, Thanks for this tutorial! Only i cant get it working. I did everything like written above and my serial monitor is saying: cäF‡„…ᇅ…„¤§…Ƥg…\¤†ÁÆ$Ô¤¼†Ä…%fƒ¤…„¼……§„çù#„…æ…Χ•†º„dcb#„ħ»„F‡´…á‡å…„¤§…Ƥ…„¤ÁÆ$Ĥ††Ä¿…%f¤…„ä!‡ë!œþ#„…æ!ço¡Ão¡dcb#„ħئ‡„¾Ç„D#„¥†§¤§”†…ç „áä 儦çd„†…¥æ†¦¨§„ļ¤Åƒ¤„…„„¥¥„„¥„b„à„†Å„……„„Ecä慅…兤§…Ææe â凭$„ D§‡­$„ D¦æ¨€!ÀJ„Àäx$„<c §…¼æ…åï愤 „…Å´…„„^DóáƆ¤äDä%Db„áƆ¤d¤ä%„b„áÆæ¤ä$Áä%†b„ácCȤD¤!䥁b#¤¼Å§äφ†……e„âå‡%$LDó¤… 䅅£cÀ„¤ Has anyone an idea what i do wrong? thanks!

Keep going

Hey Flo, thanks for sharing this valuable information. I do have a question thoug (I'm novice so bear it with me): I followed your updated setup (the one without the capacitors and crystal), since I've got the atmega328 chip straight from digikey. After setting up, I've set the directory as optiLoader and was able to compile and program through my Uno board. At this point, what do I do next? How can I confirm that my bootloader worked?

Did you manage to solve this error? I am also receiving this error but my target chip is an Atmega328p-pu using an Arduino Uno R3

Assume that you simply are operating as a computer technician for just a company with a large network. You're assigned to find out precisely what is wrong with an employee?s computer and repair it. You suspect that the computer is not properly connected to your community. Describe the troubleshooting steps you'll choose to test your theory that the computer is not physically or logically connected to the network, and describe how you would resolve the resolve the numerous reasons for your computer not connecting for the community..

Hi there, congratulations! I'm wondering if you can help me. I'm trying to burn Arduino UNO bootloader on a blank, standard factory settings, ATMEGA328p-mu. Can someone helpe me with some tips? Thanks a lot

Thank you! I bought a ATmega328 with the bootloader already burned, but when I put it on the Uno board and tried to upload a new sketch, there would be no USB communication (only the Rx led flashed). I burned the bootloader myself and it's working now!

Thank you thank you thank you!!! The chip on one of my UNO board got fried and I was getting frustrated that none of the my previously bought 328P chips works on the new UNO board.... Something about stk500 programmer error. This optiloader is the ticket. I just successfully programmed 4 chips and they all work. I didn't use a breadboard, just used a 2nd UNO board and connected them per instructions in the sketch.

hi everyone, i have the atmega328 with arduino uno bootloader, and a arduino mega, how do i use the chip instead of the arduino board when making a project an how do i upload a sketch to the chip, i've tried to find how to upload a sketch to the chip and can't seem to find anything that says anything with using a arduino mega only stuff on using a uno board. any help would be great thanks

thanks a lot, it worked perfectly for me, now i can go on with my project:) but one question: where can i find the original article with the use of the oscillator and the compositors. i would like to know what to do if you have a already burned chip. please send me a mail at treaki@gmail,com so i dont have to check this comment section recently thanks again and greetings treaki

Worked for me - I found I needed the oscillator sub-circuit though. Came back with "failed, error 0x0" otherwise.

I tried this without the crystal and two capacitors and got "Failed, result = 0x0". When I added those into the circuit, however, it worked. I'm not sure if this is because maybe the internal clock was disabled or maybe because I have an Uno R3. Regardless, thanks a bunch, this was very helpful.

Hey I'm getting following error message while uploading optiloader. optiLoader.pde:-1: error: stray '\' in program optiLoader.pde:-1: error: stray '\' in program optiLoader.cpp:249:46: error: exponent has no digits optiLoader.cpp:250:62: error: exponent has no digits optiLoader.pde:-1: error: stray '#' in program optiLoader.pde:-1: error: expected unqualified-id before '<' token optiLoader.pde:-1: error: expected constructor, destructor, or type conversion before '<' token optiLoader.pde:-1: error: expected constructor, destructor, or type conversion before '<' token optiLoader.pde:-1: error: expected constructor, destructor, or type conversion before '<' token optiLoader.pde:-1: error: expected unqualified-id before numeric constant

This is the only tutorial that actually works. I've tried lots of them.