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.
Step 1: Parts
1 x Arduino on a Breadboard
1 x Arduino UNO
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.
search for void heartbeatand change the line that reads:
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:
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.
In your Arduino folder, find the subfolder: ..\hardware\tools\avr\etc
Step 7: Bootload the ATmega328
In the Arduino IDE, from the Tools menu:
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!
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.