Bootload an ATmega328

254,582

208

147

Introduction: Bootload an ATmega328

About: 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. A while back I discovered a way to turn my inter…

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

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

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

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?

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

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

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.

Be the First to Share

    Recommendations

    • Battery Powered Contest

      Battery Powered Contest
    • Plywood Challenge

      Plywood Challenge
    • Plastic Contest

      Plastic Contest

    147 Discussions

    0
    rohit_gaidhane
    rohit_gaidhane

    Reply 4 years ago

    Is that its work on new IDE

    0
    gewkwn
    gewkwn

    6 years ago on Step 6

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

    0
    Antzy Carmasaic
    Antzy Carmasaic

    6 years ago on Step 6

    Thanks for this. Helped me save a wasted ATmega328

    0
    AndyTallack
    AndyTallack

    Reply 6 years ago on Step 6

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

    1
    ParagB6
    ParagB6

    8 months ago

    i am facing same problem,
    done with changes as per suggestion. please let me how to make overwrite with "-F"
    my IC details are Atmel 35473D,ATMEGA328 U, 1907Y2J

    error_android.JPG
    0
    ghoshtunir
    ghoshtunir

    11 months ago

    I have the latest arduino ide and changing the source code does nothing, I changed the code at 3 places
    1. The avr.config file
    2. The duemili part in board.txt( given in a comment )
    3. Lastly added the -F parameter too,
    But still getting same output.
    Restarted the ide, reset the board,
    Restarted computer, nothing, same output.
    Thanks in advance.

    1
    ParagB6
    ParagB6

    Reply 8 months ago

    how did you done this -F parameter change ?

    0
    Shaikh Muhammad
    Shaikh Muhammad

    Reply 10 months ago

    What error are you getting?

    0
    ghoshtunir
    ghoshtunir

    Reply 10 months ago

    Forgot to update, but I got it right. Bad breadboard.
    Second thing would be external power helps, in my case ot was a necessity.

    1
    biobuilder
    biobuilder

    5 years ago on Step 6

    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!

    0
    ParagB6
    ParagB6

    Reply 8 months ago

    not working this method also.
    still error is same as attached image. please let me know how to do this -F for overwriting.

    error_android.JPG
    0
    Azayles
    Azayles

    Reply 1 year ago

    Ok this looked WAY easier than futzing with avrdude.conf so I tried this and yeah it WORKED!
    I made a copy of a custom board definition I had for a bare 328p on a breadboard, changed build.mcu to reference atmega328, then saved it.
    Thank you! :D

    0
    biobuilder
    biobuilder

    Reply 5 years ago on Step 6

    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.

    0
    ParagB6
    ParagB6

    Question 8 months ago on Step 6

    as per suggestion , changes done , but still facing this problem.
    my IC details are - ATMEL 35473D , ATMEGA328 U , 1907Y2J
    how to get clear with this error.

    error_android.JPG
    0
    RaviD7
    RaviD7

    4 years ago

    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?

    0
    Shaikh Muhammad
    Shaikh Muhammad

    Reply 10 months ago

    Have you replaced both files shown above?

    0
    rajesh.dey.397
    rajesh.dey.397

    4 years ago

    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?