Introduction: Bootload an ATmega328

Picture of Bootload an ATmega328

This instructable adds to any of the Arduino on a Breadboard instructables. I wrote my own breadboard-Arduino tutorial, and then I found that I was struggling to program some of the boards I made. A lot of research and dead-ends got me understanding that:

1. You either need a microcontroller with a pre-loaded Bootloader, or must load your own
2. Not all ATmega328’s are equal

(A bootloader, very simply, is a programme that sits on the chip and manages the upload of your sketches onto the chip)

There are plenty of bootloading resources, but I couldn’t find a single one that pulled everything together in a way that made sense to me.

If this instructable helped you, please visit Crash Bang Prototyping, follow us on twitter, and join in with our prototyping resources and tools.

Here goes…

Step 1: Parts

1 x Arduino on a Breadboard
1 x Arduino UNO
Connecting Wires
Arduino IDE installed on your PC

Step 2: The Approach

Picture of The Approach

We’re going to use the Arduino UNO to bootload the ATmega328 that is sitting on the Arduino-on-a-Breadboard. This is fairly straightforward if you have an ATmega328P-PU, but needs an extra step for an ATmega328-PU. I’ll tackle the differences later in the Instructable.

Step 3: Program Your Arduino UNO As an ISP

Picture of Program Your Arduino UNO As an ISP

We need to program the Arduino UNO to act as a an ISP (In-System Programmer), so that it can burn the bootloader onto the Breadboard chip.

  1. Open the Arduino IDE
  2. Open the ArduinoISP sketch (under File, Examples)
  3. If you’re using version 1.0 of the IDE:

search for void heartbeatand change the line that reads:

delay(40);

to

delay(20);

Connect your UNO to the PC, making sure it’s not connected to the Arduino on a Breadboard.

Ensure your UNO is selected under the Boards menu option, and upload the sketch.

Step 4: Connect Your ATmega328

Picture of Connect Your ATmega328

Now connect your ATmega to your UNO as follows:

  • UNO 5v ---> ATmega pin 7 (VCC)
  • UNO GND ---> ATmega pin 8 (GND)
  • UNO pin 10 ---> ATmega pin 1 (RESET)
  • UNO pin 11 ---> ATmega pin 17 (MOSI)
  • UNO pin 12 ---> ATmega pin 18 (MISO)
  • UNO pin 13 ---> ATmega pin 19 (SCK)


Make sure that you don’t have anything else connected to the ATmega pins used above.

Step 5: Which ATmega328 Are You Using?

Picture of Which ATmega328 Are You Using?

I learnt the hard way that there is more than one type of ATmega328. The two variants that are of interest to us are the ATmega328-PU and the ATmega328P-PU.

The -PU suffix means that the chips are in a PDIP package, the format we need for our breadboard.

The 328P is a picoPower processor, designed for low power consumption, and is used on the Arduino boards. Given low power consumption this is first choice.

The 328 does not have picoPower technology, and is not used on the Arduino boards – and is not explicitly supported by the Arduino IDE.

What this means is that we can easily bootload the ATmega328P, but not the ATmega328. Unfortunately the websites that sell these chips don't always differentiate between them and forums are filled with people struggling to use the ATmega328-PU.

Luckily there is a workaround - take a look at my Crash Bang website.

Step 6: ATmega328-PU Workaround

Picture of ATmega328-PU Workaround

Each microprocessor has a signature – a unique code that identifies its model. When you bootload a chip (or even upload a sketch) the Arduino IDE checks that the chip selected matches the type it’s connected to. Even though the ATmega328-PU in essence functions in the same way as the ATmega328P-PU, it has a different signature, and one that isn’t recognised by the Arduino IDE.

(Behind the Scenes: The Arduino IDE actually uses AVRDUDE to programme the chips, so you’ll see error messages from avrdude)

If you try to bootload an ATmega328-PU, you’ll get a message something along the lines of:

avrdude: Device signature = 0x1e9514
avrdude: Expected signature for ATMEGA328P is 1E 95 0F
Double check chip, or use -F to override this check.

You could also get a more colourful version:

avrdude: Yikes! Invalid device signature.


The way to work around this is to “trick” the IDE into believing your 328-PU is in fact a 328P-PU. Disclaimer: I have tested this myself and it works – no guarantees however that you won’t have unforeseen consequences.

Workaround:
In your Arduino folder, find the subfolder: ..\hardware\tools\avr\etc

  1. Make a backup copy of the file: avrdude.conf
  2. Open the file avrdude.conf in a text editor
  3. Search for: “0x1e 0x95 0x0F” (this is the ATmega328P signature)
  4. Replace it with: “0x1e 0x95 0x14” (this is the ATmega328 signature)
  5. Save the file
  6. Restart the Arduino IDE
  7. Continue with the rest of the steps in the instructable, and once bootloading is complete restore the backup copy you made.

Step 7: Bootload the ATmega328

Picture of Bootload the ATmega328

In the Arduino IDE, from the Tools menu:

  • under the Board option choose Arduino UNO
  • under the Serial Port option ensure the correct port is selected
  • under the Programmer option choose Arduino as ISP


To burn the Bootloader, choose Burn Bootloader from the Tools menu

You should see a message “Burning bootloader to I/O Board (this may take a minute)"

Once the bootloader has been burned, you’ll see a message confirming the success.
 

Congratulations: You're now ready to load sketches onto your Arduino on a breadboard!



Uploading Sketches

ATmega328P-PU: You can leave your setup as it is, and use the Arduino UNO to upload sketches to your newly bootloaded ATmega (File, Upload using Programmer).

ATmega328-PU: the IDE will notice that the signature isn’t valid – so you’ll have to either alter the avrdude.conf file again or use an FTDI board to upload. I prefer using an FTDI board anyway as it doesn’t take my UNO out of circulation and is quick to connect.

Comments

kylebarker82 (author)2014-01-09

IT WORKED!!!

AndyTallack (author)kylebarker822014-01-10

Great stuff - thanks for letting me know! Would love it if you followed Crash-Bang on Twitter as a thanks :)

Is that its work on new IDE

bhutanidivye (author)2014-02-21

Thanks a lot

gewkwn (author)2014-02-01

thanks for info !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Antzy Carmasaic (author)2014-01-01

Thanks for this. Helped me save a wasted ATmega328

Excellent, pleased it helped! Thanks for letting me know.

sherman.chen (author)2017-10-29

Your article really saved me a lot of time! Thanks!

hstucki (author)2017-10-24

It worked. Thanks for the informations.It helped me a lot.

Another easy workaroud for the 328pu. Open boards.txt in your arduino directory:

Copy/paste the description of the uno (when you want to use a crystal) or the arduino on breadboard 8 Mhz and replace the the word uno in every line you pasted to something specific you like (eg: atmega328pu). Give a nice unique memorable name to your new entry (eg:atmega328pu.name=ATmega328 PU on a breadboard with crystal). Modify the line build.mcu. and remove the p (eg atmega328pu.build.mcu=atmega328). If you restart your arduino you are able to choose between the pu and the p-pu without further manipulation of the avrdude.conf file.

LiboAhmed (author)2017-10-21

Hi my atmega 328p don't good working in my test bored?

ImpigerI (author)2017-10-12

Actually for me the device signature keeps on changing

avrdude: Device signature = 0x00ff00

avrdude: Device signature = 0xffff00

avrdude: Device signature = 0x000ff

like this.. what could I do now?

arai4 (author)2017-09-20

Im stuck to change and save averdude.conf file,can somebody help

wandersen (author)2017-09-03

A big thanks for this post. I would note a couple of things: To edit the conf file you might need to go into preferences and security tab to give your self modify privileges. Secondly I found there were a couple avrdude.conf files in the maze of IDE download files. The one in ..Arduino/hardware/tools/avr/etc was the correct file to use.

Now on to the next problem that I am pealing away like layers of an onion.

Blink has less than 50% duty cycle even though on/off delays are equivalent in the sketch. : delay(1000);

Probably related to the errors I got uploading the sketch:

...

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x1c

Maybe I have to do something different when loading the bootloader if I am using a 16 MHz crystal externally ?

Here is to slow progress!

geekboy32. (author)2017-01-06

It works. Thanks a million Andy! :)

guptabs (author)geekboy32.2017-08-12

In arduino 1.8.2 we are not allowed to change and save averdude.conf file,can somebody help

Magick_67 (author)2017-07-24

I fought for DAYS to get a bootloader on my 328-AU and was beginning to wonder if I had bricked the thing or my circuit was screwed up.

Swapping out the config files is a circuitous and laborious task, but it's a winner!

Nelvig (author)2017-05-02

You're the man! If I were in the committee you'd get the Nobel Prize next year.

AmeyT (author)2017-03-12

Thanks a lot Andy Tallack, It worked, What a relief to 3 weeks of frustration.

SethuR1 (author)2017-02-23

ERROR! Fired?

avrdude: verification error, first mismatch at byte 0x0000 0x00 != 0x0c avrdude: verification error; content mismatch

kd8bxp (author)2017-02-18

Got my hands on a couple of old boards with "weird" bootloaders on them, and old ATmega328 chips - I can say that it worked with 1.6.9 of the IDE thou the avrdude.conf file was moved to a different location and took a little bit to find.

Made the old boards usable again thou, thanks

MayurP21 (author)2017-02-10

COMPLETLY WORKED.

kd8bxp (author)2017-01-25

Thanks for the info.

subhro.j.bose (author)2015-05-03

I can't save F0. it is showing this error message. now what to do? please help........

Wow - that's an error I've never seen before. Can you give me more info on what you were doing when it happened? Looks like some kind of security rights issue.

Error while bootloading avrdude: stk500_getsync() :not in sync: resp=0x00

actually I have done all the job but it is showing the same problem.Nothing new is showing. And inside the "etc" folder there already have “0x1e 0x95 0x14” sooooooo what to do now ?

KshitishD (author)2016-10-20

thanks brahhh

MonojitS2 (author)2016-09-23

IT'S WORK

THANK YOU SO MUCH SIR

jaatbuddhi (author)2016-09-11

Thanks this was helpful and it worked too!!

rajesh.dey.397 (author)2016-08-16

With great thanks sir I want to inform u that, after changing the signature to

0x1e 0x95 0x14 I'm not allowed to save the changes in that location. Now what I have to do?

Balachandra.M.Hegde (author)2016-06-09

Thanks a lot. This works perfectly..

RaviD7 (author)2016-03-08

avrdude: Yikes! Invalid device signature.

Double check connections and try again, or use -F to override

this check. I am still getting the same problem again and again even i tried every step mention above with 2/3 affected ATMega328P-Pu IC. Please tell me what to do now?

RaviD7 (author)2016-03-08

avrdude: Yikes! Invalid device signature.

Double check connections and try again, or use -F to override

this check. I am still getting the same problem again and again even i tried every step mention above with 2/3 affected ATMega328P-Pu IC. Please tell me what to do now?

VlatkoG (author)2016-01-16

I used this tutorial to build my own atmega based system and so i ordered a bunch of Atmegas from retail seller. All i had were 10 and 47 pF capacitors and so i used them for oscillator. I have struggled for days with avrdude: stk500_getsync(): not in sync: resp=0x00 message and after running out of ideas i went to parts store today and bought exactly 22pF capacitors. Imagine, it worked like a charm. Thank you!

AndyTallack (author)VlatkoG2016-01-16

Great! I've often wondered about, but never tested, the tolerance on the capacitors... good to know the datasheet doesn't lie :)

karthickashwath247 (author)2015-12-28

Tried all the methods. Spent a few hours working on it. Then I discovered that my UNO was responding only to the older version of the IDE. It refused to upload in the newer IDE. After discovering this, I tried it in the older IDE. Worked like a charm. Bootloaded 2 chips and also uploaded blink programmes.

Thank You so much for this tutorial!

Abhishek Basu (author)2015-12-20

U r a life saver. Thank a lot

fotherby (author)2015-10-23

Thank you so much. This finally solved my problem after hours of work!!!

khuffman35 (author)2015-10-15

My ATMega328 is running the internal clock at 8 MHz. I successfully installed the bootloader but can't communicate via the UART (FT230X SCI to USB circuit). I've used the circuit successfully many times before, so I don't suspect the hardware. Since the baud rate for the communications from the ATMega is derived from the system clock, I suspect the bootloader is expecting a 16 MHz crystal and is setting an incorrect baud rate (I had to modify the bootloader code and set it to an internal clock on the fuse register). Does anyone have access to the source code for the hex bootloader that is sent to the microcontroller? Any other ideas?

ecotack (author)2015-09-25

When I change the signature to the ATMEGA328-PU, my code compiles and uploads fine. However, the code runs very slow. PWM LEDs become a visible flicker. I'm using an external 16MHz clock. Circuit and code works fine with a ATMEGA328P-PU.

Abhishek Basu (author)2015-09-22

God Bless u. U r a life saver.

Thanks a lot

biobuilder (author)2015-09-16

Hey everyone, Here's a permanent way to fix the programming issue with ATMEL328 and still keep your UNO (ATMEL328P) programmable. You want the ATMEL328 device signature to be a Diecimila. However, the Boards.txt file included with the standard copy of Arduino (1.6.3) has a typo, which you will have to fix if you want to seamlessly program your Diecimila with ATMEL 328 instead of ATMEL 328P. Here's how you do it:

1. Find your Arduino Application

2. Go to Java, then hardware, then arduino, then avr, then find "boards.txt"

3. Make a copy of "boards.txt" in case you mess up

4. Find the line in "boards.txt" that says:

diecimila.menu.cpu.atmega328.build.mcu=atmega328p

5. Backspace the "p" off of the line so it looks like this:

diecimila.menu.cpu.atmega328.build.mcu=atmega328

6. save the txt file, restart Arduino, and you're Done!

biobuilder (author)biobuilder2015-09-16

Please note: Using this method will not allow you to simply plug the ATMEL328 into an old UNO shield and have it programmable via the USB cable. You will have to use a number of workarounds or program via ISP. It is possible to make your own board profile if you really want to do this, but chances are the ATMEL328 is destined for something other than a regular Arduino board.

biobuilder (author)2015-09-16

Hey everyone, Here's a permanent way to fix the programming issue with ATMEL328 and still keep your UNO (ATMEL328P) programmable. You want the ATMEL328 device signature to be a Diecimila. However, the Boards.txt file included with the standard copy of Arduino (1.6.3) has a typo, which you will have to fix if you want to seamlessly program your Diecimila with ATMEL 328 instead of ATMEL 328P. Here's how you do it:

1. Find your Arduino Application

2. Go to Java, then hardware, then arduino, then avr, then find "boards.txt"

3. Make a copy of "boards.txt" in case you mess up

4. Find the line in "boards.txt" that says:

diecimila.menu.cpu.atmega328.build.mcu=atmega328p

5. Backspace the "p" off of the line so it looks like this:

diecimila.menu.cpu.atmega328.build.mcu=atmega328

6. save the txt file, restart Arduino, and you're Done!

biobuilder (author)biobuilder2015-09-16

The reason why you can't program an ATMEL 328 inside of an UNO shield is because the avrdude.config for Diecimila doesn't match exactly what the UNO layout is. The ATMEL 328 is better off bare-bones or some other custom layout.

biobuilder (author)biobuilder2015-09-16

Please note: I haven't been able to make the ATMEL 328 in an UNO shield be programmable via a USB cable using this technique, but it will save you some trouble when programming via ISP (MOSI, CLK, and MISO) so that you do not have to change the device signature of your UNO ATMEL 328P.

NeilH5 (author)2015-08-20

Thank you. It works

ksnanda (author)2015-06-09

Hi,

I have an atmega328p MLF package type that's mounted on a pcb with crystal (SMD Type) and other few components.

How to upload code to this ?

AndyTallack (author)ksnanda2015-06-09

Hi

It may have an ISP header? Can you send a link to the product you have?

Cheers

Andrew

bpatil65 (author)2015-05-12

my softwear are not working

About This Instructable

203,653views

195favorites

License:

Bio: I’m not a rocket scientist. I don’t have a master’s degree in Electrical Engineering. I love automating, hacking, robotics, creating, building, understanding ... More »
More by AndyTallack:Bootload an ATmega328BaW-Bot Part 3: Adding Sight and Touch to the BotBaW-Bot Part 2: Build the motor-controller & body
Add instructable to: