birds like wires

Search

Arduino Bootloader on ATmega168

Arduino / ATMega168 by Adam Greig

I’ve recently had cause to build a very simple microcontroller-based project. I like the Arduino platform, so I wanted to burn the Arduino bootloader onto an ATmega168. To keep the circuit as simple as possible, I also wanted to have the ATmega168 use it’s own internal 8MHz oscillator, instead of having to provide a 16MHz one externally. One chip, some power, flashy LEDs; dead simple. Except, how to get that bootloader onto the chip?

The easiest way with the equipment I had around was to pop the Arduino ISP sketch onto a working Arduino and connect everything up as shown in the documentation. The image bottom-left shows the setup I was after. I then moved on to the Arduino to Breadboard documentation, which is lovely and clear, but does seem to have an important little thing missing.

The illustrations all clearly show an ATmega168 on the breadboard, but the archive that it links to only provides the settings for burning to an ATmega328. This doesn’t work with the ’168. It is possible to use the LilyPad Arduino w/ ATmega168 board configuration to burn the bootloader, but I found that this introduced a delay of about 10 seconds before anything happened when the chip was powered up or reset.

Hardware Configurations for 8MHz

To fix it properly, I had a dig inside Arduino.app and found that there’s a proper ATmegaBOOT_168_pro_8MHz.hex bootloader hiding in there. If you’re looking for it, it’s here (on Mac OS X):

/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/bootloaders/atmega/

Great stuff. Now, using a combination of the settings for the LilyPad Arduino and the correct bootloader, I created a boards.txt file in ~/Documents/Arduino/hardware/breadboard/ which contains this:

##############################################################

atmega168bb.name=ATmega168 on a breadboard (8 MHz internal clock)

atmega168bb.upload.protocol=stk500
atmega168bb.upload.maximum_size=14336
atmega168bb.upload.speed=19200

atmega168bb.bootloader.low_fuses=0xe2
atmega168bb.bootloader.high_fuses=0xdd
atmega168bb.bootloader.extended_fuses=0x00
atmega168bb.bootloader.path=arduino:atmega
atmega168bb.bootloader.file=ATmegaBOOT_168_pro_8MHz.hex
atmega168bb.bootloader.unlock_bits=0x3F
atmega168bb.bootloader.lock_bits=0x0F

atmega168bb.build.mcu=atmega168
atmega168bb.build.f_cpu=8000000L
atmega168bb.build.core=arduino:arduino

##############################################################

atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)

atmega328bb.upload.protocol=stk500
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600

atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05
atmega328bb.bootloader.path=arduino:atmega
atmega328bb.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino:arduino

Give Arduino.app a restart and you should see the ‘ATmega168 on a breadboard (8 MHz internal clock)’ option under the Tools > Board menu. Set up the Arduino and the ATmega168 on the board as shown, set your board and serial port from the Tools menu, then go to Tools > Burn Bootloader > w/ Arduino as ISP.

Hooray! That should have worked, and this is what you should have seen.

Exiting, no? ;)

If you now connect the chip up as shown in the ‘Uploading sketches to an ATmega on a breadboard’ illustration (remembering to remove the microcontroller from your Arduino) you can upload sketches directly to the microcontroller on the breadboard. The chip can then be dropped straight into your project using as few components as possible. If you’ve tried the LilyPad flashing method before, you’ll also notice that your sketch starts running almost immediately – much better!

Gotcha!

The first error that haunted me was this one:

avrdude: stk500_getsync(): not in sync: resp=0x15

This is because of the auto-reset function of the Arduino being triggered, causing the whole thing to restart. Ignore everything on the Arduino site about resistors and removing components from your board; just pop a 10µF capacitor between the reset pin and ground. That will ‘soak up’ the pulse telling the chip to reset.

The second error that haunted me was this:

avrdude: Device signature = 0x000000 
avrdude: Yikes!  Invalid device signature. 
         Double check connections and try again, or use -F to override 
         this check. 

The reason I was seeing it was that I had been impatient and swiped the ATmega168 from my Diecimila to test with. These ATmegas have had their fuses set to expect an external timing source, so you must provide one for anything to happen. You can change the fuse settings using the method above (it is done automatically when you choose the 8MHz board option), but you need to provide it with a 16MHz signal first for it to run at all. And no, so far as I am aware you can’t burn the 8MHz bootloader in situ on an Arduino – not without using an external ISP like a USBtinyISP.

From the factory the microcontrollers default to using their own oscillator, so when my blanks arrived they worked perfectly first time.

I was having the exact same problem in fact, thanks :)

jcnossen left this message 1991 days ago

@jcnossen Glad it was useful! I’m slowly writing a new article on running the ATmega168 at 1MHz instead of 8MHz to save power; hopefully I’ll get some time over Christmas to finish it, but it does work. I’ll be including a little download with the 1K bootloader compiled for various Atmel chips and a hardware config file to make things nice and easy.

Andy left this message 1990 days ago

Finally finished 'Saving Power with your ATmega'. :)

Andy left this message 1949 days ago

To make the bootloader work for the atmega168 @8mhz internal clock.
I’m using this bootloader with your above hardware settings and it works perfectly with this tricky procedure: press&hold the hardware reset button on your breadboard then click the upload button in the arduino ide, release the reset button two seconds or so after the arduino compilation string came up. it works!!. I hope this could be useful for you. …. regards! A.R.

adrian Rmz left this message 1776 days ago

Thanks for the tut! The bootloader burns fine but I cannot get the atmega168 to use the bootloader with the internal 8Mhz. When following your instructions he cannot find pins_arduino.h. Using the Pro Board with 8Mhz instead should work but I only get a “not in sync” or “not responding”. I’ve tried a lot fuse configurations and locks but the bootloader works only with an external crystal. Any ideas?

martin left this message 1684 days ago

@martin Is this a chip that has previously been used on an Arduino board, or is it a single separate chip that you’ve purchased? I had a heap of trouble trying to set a chip from an Arduino board to the internal oscillator, but never found out why (as my blanks arrived the same day!). Sorry not to be of much help, but perhaps try picking up a totally fresh chip and trying again..?

Andy left this message 1684 days ago

Useful link for anyone reading this in the future, including myself: http://www.ladyada.net/library/arduino/arduinoisp.html Ladyada has a modified arduinoISP sketch that outputs 8MHz from pin 9 of the arduino that can be used to supply a clock to pin 9 of the chip that you’re uploading the bootloader to.

Jon left this message 1683 days ago

@Jon Clever!

Andy left this message 1683 days ago

@Andy It was a new chip and I have a few of those, didn’t change it.

martin left this message 1682 days ago

hi, I’ve been searching for days how to get a bootloader onto an atmega168 by using an arduino Uno as the ISP programmer.. this is the closest solution I’ve found so far, but yet: it doesn’t seem to be a Uno your using. do you know if this is possible at all ?

søren left this message 1672 days ago

@martin I’m afraid I’m a bit stuck with that one – tricky to debug at a distance!

@søren An Uno should work in exactly the same way when set up as an ISP – give it a shot, you should be fine. :)

Andy left this message 1671 days ago

Andy, nice tutorial.
I have two arduinos, a diecimila atmega168 and a freeduino atmega328P. I wanted convert atmega168 in 1MHz internal clock for another project. I finally found the way to burn the 1MHz bootloader (http://www.experiment4.com/2011/08/21/slowduino/) with an external timing source ( the diecimila board without uc) and the arduino ISP.
My problem is when I try to upload the Blink sketch (according to http://arduino.cc/en/Tutorial/ArduinoToBreadboard – Uploading Using an Arduino Board) and I recive the compiling message (arduino 1.0.5)

In file included from Blink.ino:10:
C:\Program Files\Arduino\hardware\arduino\cores\arduino/Arduino.h:213:26: error: pins_arduino.h: No such file or directory

any idea? Thanks in advance

dgomres left this message 1246 days ago

If you are getting build errors, try changing to this:
(remove :aruino from .build.core)
(add .build.variant=standard )
##############################################################

atmega168bb.name=ATmega168 on a breadboard (8 MHz internal clock)

atmega168bb.upload.protocol=stk500
atmega168bb.upload.maximum_size=14336
atmega168bb.upload.speed=19200

atmega168bb.bootloader.low_fuses=0xe2
atmega168bb.bootloader.high_fuses=0xdd
atmega168bb.bootloader.extended_fuses=0×00
atmega168bb.bootloader.path=arduino:atmega
atmega168bb.bootloader.file=ATmegaBOOT_168_pro_8MHz.hex
atmega168bb.bootloader.unlock_bits=0×3F
atmega168bb.bootloader.lock_bits=0×0F

atmega168bb.build.mcu=atmega168
atmega168bb.build.f_cpu=8000000L
atmega168bb.build.core=arduino
atmega168bb.build.variant=standard

##############################################################

atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)

atmega328bb.upload.protocol=stk500
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600

atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0×05
atmega328bb.bootloader.path=arduino:atmega
atmega328bb.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0×3F
atmega328bb.bootloader.lock_bits=0×0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino
atmega328bb.build.variant=standard

This tutorial and comments were major help for me today. Much gratitude to you all!

Intechgreater left this message 524 days ago

@Intechgreater Thanks for letting me know! It’s been a little while since I’ve had chance to mess around with these MCUs, so it’s great that the details in this are still useful. :)

Andy left this message 524 days ago