Arduino UNO As AtMega328P Programmer
124,551
235
73
Introduction: Arduino UNO As AtMega328P Programmer
After receiving my first Arduino UNO, I soon realised that it will be impractical to use an UNO for every project. As with the Microchip family of MCUs, I wanted an easy way to program stand-alone circuits and chips.
Searching the internet, it was clear that the Arduino IDE can cater for all my needs, and that no additional hardware will be required. The Arduino UNO can be programmed as an In Circuit Programmer with the supplied example sketch ArduinoISP and the UNO. There is thus no need for a separate programmer, or using AvrDude software for programming. A lot of examples on this was found on the internet.
After some testing, it was clear that programming the AtMega328P was not as easy as I thought. Programming all depended on the AtMega328P chip. Does it already contained the bootloader, or is the chip blank? Costs of a chip with bootloader is double that of a clean chip, so my first batch of chips was blank.
What is the difference, you may ask. Well, it is all about the AtMega328P oscillator selection.
Lets look at the differences
AtMega328P with bootloader
Cost of this chip is about double that of a blank chip
The config registers of the chip is set to use an external crystal as clock (16MHz)
Without an external oscillator, one can not program the chip using the Arduino as programmer
Once fitted with an external oscillator, the chip can be programmed using the Arduino as programmer
AtMega328P without bootloader
Cost is half of a chip with bootloader
The config register of the chip is set to use the internal 1MHz clock
Chip can be programmed using the Arduino as programmer, BUT the program will run 16 times slower than the code should, as the Arduino IDE compiles the code to run at 16MHz, and not 1MHz
Chip can be configured for 16MHz by uploading the Arduino bootloader.
Step 1: Designing a Programmer Shield
Designing the programmer shield, I looked at the requirements to program chips with and without bootloaders. First, I looked at the oscillator selection.
Oscillator
AtMega328P with bootloader
The chip needs an external oscillator to be programmed, so this must be present on the shield.
AtMega328P without bootloader
If the chip was configured to use the internal oscillator, no additional components are needed. However, if the chip was previously configured to use an external oscillator, an oscillator will be required. With an external oscillator, both types can be programmed.
It is clear that adding an external oscillator to the shield, will accommodate all types of chips. A 16MHz crystal and 2 x 15pf capacitors, or a 16MHz resonator can be used.
LED indications
The source code or sketch indicated 3 outputs that can be connected to LEDs. This indications should be present on the shield.
Resetting the programmer
With a shield placed on top of an Arduino UNO, the UNO reset button is normally out of reach. The shield should include a separate reset button.
Powering the chip to be programmed
The chip that needs to be programmed, must have power connected to it. For the supply, the +5V and 0V is taken from the Arduino UNO board. However, inserting and removing a chip from the programmer with supply on, might cause damage to the chip. For this reason, a switch was added to the shield.
I/O Port protection
The ArduinoISP shield sets certain pins as OUTPUT on the Arduino UNO. If one now connect a previously used AtMega328P to the programmer, there can be conflict between the two chip's I/O lines that can cause damage to the ports. For protection, I added 470R resistors between the programmer, and the chip to be programmed.
Reset line of chip to be programmed
To ensure a stable reset circuit for the chip to be programmed, I added a 10K pull-up resistor to the RESET line.
Programming Method
ZIF Socket
This will be an easy way to program stand-alone chips, or to burn the bootloader on new chips. I thus added the ZIF socket to the design.
Programming cable
As almost all my designs are stand-alone circuits, my programming and development is done on breadboard. Thereafter, program updates are done via programming headers on the final circuit board. For this reason, I added the programming cable to the design.
Step 2: Building the Shield
I designed a PC Board with the free version of Eagle, and the shield fits directly onto the Arduino UNO. After designing the layout of the board, I noticed that the space taken up by the ZIF socket as well as the standard programming cable leave me with two options:
- use normal 1/4W resistors, which will leave no space for labels, or
- use SMD resistors which is more work, but will leave space for the labels.
My final PCB design uses SMD resistors, soldered to the solder side of the board. I used a 16MHz resonator as oscillator, but this can easily be changed with a crystal and 2 capacitors.
The power switch is connected such as to switch off the +5V to the ZIF socket, as well as the programming headers. This give more options when doing development on stand-alone circuits. Due to the limited space for the shield, the power switch was placed where the A0 - A5 pins are located on the Arduino. As these pins are not used for programming, they were omitted.
Building the circuit is quick using the PC Board. The standard header pins used to connect the shield to the Arduino, was modified. Using needle nose pliers, the header pins were pressed flush with the black plastic, and inserted from the component side.
Finally, I added labels to the LEDs and programming header.
Step 3: Setting Up the Arduino IDE to Use the Programmer
After building the programming shield, connect it to an Arduino UNO, and connect the Arduino USB cable to the PC.
- Open Arduino IDE.
- Select File - Examples - ArduinoISP
- Upload the sketch to the Arduino.
- The programmer shield LEDs should flash rapidly, where after the OK LED will fade on/off.
- Select Tools - Board - Arduino UNO
- Select Tools - Programmer - Arduino as ISP
The shield is now ready to be used to program any AtMega328P.
Step 4: Using the Programmer Shield
To burn the bootloader to the chip:
- Insert the chip into the ZIF socket.
- Goto Tools - Burn Bootloader
- Programmer LEDs will indicate programming status
- On completion, the OK LED will again fade on/off
To burn a sketch to the chip
- Insert the chip into the ZIF socket.
- Goto File - Upload Using Programmer
- Programmer LEDs will indicate programming status
- On completion, the OK LED will again fade on/off
The same method can be used to program an AtMege328P in a stand-alone circuit (breadboard or PC board) using the programming cable. For stand-alone circuits, it is normally required that they are powered up via their own supply. If no supply is available, and the circuit does not require a lot of power, the circuit can be power from the programming shield by switching on the +5V
NOTE:
Always ensure that you switch off the power switch (+5V LED off) before inserting or removing a chip into the ZIF socket, or before connecting/disconnecting the programming cables to the stand-alone circuit.
7 People Made This Project!
- majidfallout made it!
- aledaniel1 made it!
- MitjaG1 made it!
- arahmou made it!
See 3 More
73 Comments
11 months ago
very usefully.
Thanks for sharing.
1 year ago
Very elegant tutorial. Thanks for sharing.
Tip 2 years ago
- Insert the chip into the ZIF socket.
- Goto File - Upload Using Programmer
You have to go to "Sketch" and click on Upload Using Programmer
Question 3 years ago
Hi there! I'm a teacher.
What did you study in order to arrive at this level of engineering? I can use your example to inspire students in my tech-related classes. Thanks
Question 3 years ago on Step 3
Sevgili arkadaşım. Öncelikle teşekkürler baskidevre pdf formatı atabilirmisin gönderebilirmisin.
3 years ago
Hello, I can record the transistorteste firmware, Thanks
3 years ago
I keep getting an error when trying to burn the bootloader:
avrdude: stk500_recv(): programmer is not responding
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
Error while burning bootloader.
I tried a 328 and a 328P, and I'm using the 1.6.12 IDE version. Any thoughts on where i may be going wrong?
Reply 3 years ago
Hi.
Did you upload the ArduinoISP sketch to your Arduino board?
Did you select the Arduino as ISP under Programmer?
Question 3 years ago
Thanks for this tutorial.
In Step 4 you have a picture showing your programming shield cabled to a smaller board. What is this showing? If this is using the header cable to program a different chip, why does the smaller board have other components on it? Thanks!
Answer 3 years ago
The smaller PC Board is a stand-alone project being programmed with the programming shield.
The shield can be used to program the AtMega328p via the ZIF socket, or perform "In Circuit Serial Programming" directly on a finished project.
Hope this help.
Regards, Eric
3 years ago
From Brazil. I made it. It works very well. TKS
Reply 3 years ago
Thank you for your feedback.
Regards, Eric.
Question 3 years ago
Could you put an 8 Mhz resonator instead of 16? Would it work? I have seen that you do not put anything on the Aref pin, should placed o a capacitor form Aref to vcc?
Answer 3 years ago
Hi
I have not tried using a 8MHz crystal, but as far as I understand the programming of the ATMega328p, it should work.
Aref is not used during programming, thus nothing is connect to the pin. No cap needed.
Regards, Eric.
3 years ago
hi first thanks for sharing your project i made your eagle pcb but i don't know pins or anything please give me datasheet of pcb in eagle but not the simple one i mean the board
Reply 3 years ago
Hi
The Eagle PC Board file is available for download under Step 2.
Regards, Eric.
4 years ago
Hi Eric
Thank you very much for sharing your proyect. I found very useful the idea of the board fitting on the (omnipresent) arduino uno, so I toke your board design, I built it and it worked like a charm.
Anyway, when I was working with the printed (I migrated the files to Altium's CM) it seemed to me that the labeling for the isp header was not completely correct. I think that the order should be SCK, MISO, MOSI, RST, 5V, 0V.
Since for ISP purposes I use to connect the programming cable directly to the arduino ICSP six-pin connector, I did not check it, but it was the impression I had following the leads.
Reply 4 years ago
Hi
Thanks for pointing out the labeling. When I have timer, I will update this.
Regards
ERic
Question 4 years ago on Step 4
Using your board I were successful with programming boatloader on Atmega 328p, but I am not sure if is possible to program HEX file on it.
4 years ago
Thanks for sharing this interesting project. Very clear and instructive.
However I can find Arduino Mini,Micro,Nano at a lower cost than Atmega328p + resonator including shipping to Norway.
Quite strange but the lowest cost Atmega328p I have found was about £ 1.8 ?
I have built one for programming an Atmega644, working fine first time.