How to Program Atmega328 From Arduino Uno (No Extra Crystal)
by TechNinja2020 in Circuits > Arduino
2765 Views, 19 Favorites, 0 Comments
How to Program Atmega328 From Arduino Uno (No Extra Crystal)
This is a tutorial on how to program an Atmega328P taken out of an Arduino Uno.
This will work with any Atmega328 such as the Atmega328P U, Atmega328P-PU, etc.
There are 2 methods. Scroll to the bottom for method 2.
Supplies
1 x Arduino Uno
1 x LED (Any Color) (Optional - Just for testing)
1 x 220-600 Ohm Resistor (Optional - Just for testing)
2 x 18-22 pF Capacitor (Optional - Not needed in Method 2)
10 x Jumper Wires
Soldering Iron + Solder (Optional - Not needed in Method 2)
Desolder and Add Headers to the Crystal Oscillator
The crystal oscillator is located here. (Image 1)
Desolder it and solder 2 male header pins like this. Make sure that the solder doesn't touch the metal case of the oscillator. (Image 2)
Back to the Arduino, solder 2 female header pins onto the place where you desoldered the crystal. (Image 3)
Now, we can swap the oscillator from the Arduino to the breadboard or vice-versa when needed.
Then, insert the oscillator into the header pins. (Image 4)
Upload the Code to the Arduino Uno
For this step, you need to upload your code of choice to the Arduino Uno. For this tutorial, we will be using a modified version of the Blink sketch.
Plug in the Arduino Uno and select the port and select the board as Arduino Uno.
After uploading the code, make sure to unplug the Arduino.
Code:
int ledPin = 8; //Sets the variable ledPin to 8
void setup() {
pinMode(ledPin, OUTPUT); //ledPin = 8 so it sets pin 8 as an output
}
void loop() {
digitalWrite(ledPin, HIGH); // turn on the LED
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // turn off the LED
delay(1000); / wait for a second
}
Download:
Downloads
Take the Atmega328 Out of the Arduino Uno
Most Arduino Unos have an Atmega328 in the DIP28 Package. An official Uno from Arduino will have it in this package. Some clones have a surface-mounted chip that we can't use. (Image 1)
To remove the chip, use a flathead screwdriver to push out the edges on both sides of the socket. DO NOT BEND THE LEADS OF THE CHIP. (Image 2)
Finished (Image 3)
Put the Components on the Breadboard
For this tutorial, we will be making this circuit on a breadboard. (Image 1, 2)
Put the Atmega328 In the middle (The notch in the front facing the front of the breadboard)
Attach a jumper wire connecting from pin 7 to the 5V Bus,
Pin 8 to the GND Bus
Pin 14 to the + terminal of the led,
Pin 22 to the GND Bus
Pin 20 to the 5V Bus
- terminal of the led to the 220 Ohm Resistor,
Other lead of the resistor to the GND Bus,
Take out the crystal and put it at the top
Both leads of the Oscilattor to 2 x 18-22 pF Capacitors
The other leads of the Capacitors to the GND Bus
One lead of the Oscillator to Pin 9 (Either one)
The Other lead of the Oscillator Pin 10 (Either one)
One wire connecting the Left GND Bus to the Right GND Bus
And another connecting the Right 5V Bus to the Left 5V Bus
One connecting the Left 5V Bus to the 5V Pin of the Arduino
And another connecting the Left GND Bus to the GND Pin of the Arduino
Make Something!
Now you can make something with the Atmega328. To reprogram it, but the chip back into the IC socket. Make sure the notch faces towards the notch on the IC Socket, (Away from the USB and DC Jack)
Remember to re-insert the crystal as well.
Above is the Pin Map that shows which IC Pin goes to which Digital/Analog Pin.
Method 2 (No Soldering)
If you don't want to take the chip out of your breadboard to re-program it,
you can connect it like this. With this method, you don't need to remove the crystal.
All you have to do is connect a few pins of the IC socket to the Atmega328 on the breadboard.
Socket - Pin on Socket
Chip - Pin on Atmega328
For pin locations, check the Pin Mapping in the previous step.
Wiring: (Image 1, Image 2; Everything is color-coded)
Socket 1 - Chip 1 (Blue Wire)
Socket 2 - Chip 2 (Green Wire)
Socket 3 - Chip 3 (Yellow Wire)
Socket 9 - Chip 9 (White Wire)
Socket 10 - Chip 10 (White Wire)
Chip 7 - 5V Bus (Green Jumper)
Chip 8 - GND Bus (Green Jumper)
Chip 20 - 5V Bus (Green Jumper)
Chip 22 - GND Bus (Green Jumper)
Left 5V Bus - Right 5V Bus (Red Wire 1)
Left GND Bus - Right GND Bus (Black Wire 1)
Left 5V Bus - Arduino 5V (Red Wire 2)
Left GND Bus - Arduino GND (Black Wire 2)
Wiring Diagram Image Download: