Bootload an ATmega328

222,988

201

126

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 int...

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.

Share

    Recommendations

    • Plastics Contest

      Plastics Contest
    • Optics Contest

      Optics Contest
    • Make it Glow Contest 2018

      Make it Glow Contest 2018

    126 Discussions

    0
    None
    gewkwn

    4 years ago on Step 6

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

    0
    None
    1502santosh

    Question 4 weeks ago on Introduction

    can we use arduino nano to upload the boot loader to bare atmega 328. i have tried a lot but no success. i am guessing that my nano may be reason i have tried both PU & p-PU chips but no success. any help...?? i have used samr schematics

    0
    None
    BinoyT1

    7 weeks ago

    IT'S WORK

    THANK YOU SO MUCH SIR

    0
    None
    charanm1

    7 months ago

    Sorry but mine is not working

    i did all steps same as given in description

    but still mine IC is not getting bootable

    can any one help me ?

    0
    None
    OnurEmre

    7 months ago

    Hi all,

    I have project about obtaining a PCB board including ATMEGA microprocessor, but I have a difficulties in bootloading the ATMEGA. In shortly, I have bootloaded a ATMEGA328P-PU by using Arduino as ISP mode. ATMEGA328P-PU works with 16MHz crystal and the necessary capacitor and resistor etc. Everything is OK. However, I have a ATMEGA328P-U, and I have performed the same steps for bootloading. The bootloading process is done, successfully. In this point, I have a problem is that the ATMEGA328P-U works a different frequency I think, but also it may be depending on different cause. It can be explained what I say as follows;

    For example, you know a Blink example code in Arduino (LED blinks connected in D13 with 1 sec). Here, ATMEGA328P-PU is OK meaning that the application program (LED Blink) runs, well. But, the ATMEGA328P-U works with different speed meaning that LED blinks with 10 sec, even though I used 16MHz crystal and same circuit components. Why this problem come out and how can I correct/handle this case? Please help.

    0
    None
    shailendrac13-

    9 months ago

    Hello, This tutorial was really helpfull.
    I am trying to bootload Atmega2560 from an arduino Atmega328p. The following error came
    avrdude: Device signature = 0x000000 (probably m2560)
    avrdude: Yikes! Invalid device signature.
    Double check connections and try again, or use -F to override
    this check.
    In the avrdude.conf i changed the signature
    #------------------------------------------------------------
    # ATmega2560
    #------------------------------------------------------------

    part
    id = "m2560";
    desc = "ATmega2560";
    signature = 0x00 0x00 0x00;
    has_jtag = yes;
    Still i am getting this error. Can some one help in resolving this issue.
    Thanks in advance.

    0
    None
    ChandrashekarR

    12 months ago

    Sir, I am using atmega328 internal clock 8 Mhz with breadboard , but controller runs very slowly i mean half of the speed. what maybe the problem sir ?

    I working this for audio project , the audio is playing very slowly.

    0
    None
    sherman.chen

    1 year ago

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

    0
    None
    hstucki

    1 year ago

    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.

    0
    None
    LiboAhmed

    1 year ago

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

    0
    None
    ImpigerI

    1 year ago

    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?

    0
    None
    arai4

    1 year ago

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

    0
    None
    wandersen

    1 year ago

    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!

    0
    None
    geekboy32.

    1 year ago

    It works. Thanks a million Andy! :)