Introduction: How to Load Your ATMEGA 168/328 Inside Your Project.
This is my first instructable so here we go.
Have you ever loaded your sketch plugged in your chip only to find out you need to tweak the code a little? Why keep moving the chip from socket to socket risking damage to the pins or static discharge? Did you know that when using an Arduino UNO as your isp there are only 4 wires needed to load a sketch with no special programming?
Step 1: Introduction
If you are using the ATMEGA 168/328 chip in your projects then you obviously have the skills to complete this instructable. This instructable is intended for those like myself who got tired of moving the chip back and forth any time a programming change is needed. Some assumptions will be made in this project and if you have any questions or would like more details on any step please don't hesitate to ask.
Step 2: Parts Needed
There are really only 3 required parts.
1 x Arduino uno.
1 x 5 pin in line wire harness.
1 x 5 pin male header.
2 x PNP transistors such as the SN2907, SN3906,
or the SN4403.
2 x 1k ohm resistors
3 x 330 ohm resistors.
1 x Red led
1 x Yellow led
1 x Green led
1 x Arduino prototype shield.
Any type of enclosure that you would like to use.
I recycled an old case.
Step 3: Remove the ATMEGA328 From the UNO
Using the Arduino UNO as your ISP to program ATMEGA 168/328 chip while it is inside your project requires removing the ATMEGA 168/328 from the UNO. Keep in mind that your ATMEGA 168/328 must have the bootloader already loaded. This "Sketch loader" is intended to load your sketch not to load the bootloader. Most of the Chips I order come with the bootloader already installed however there is a great instructable by Shaditheman123 at https://www.instructables.com/id/burning-atmega328-pu-and-atmega328p-pu-bootloader that should help get you in the right direction.
Step 4: Select Your Cable
There were only 4 pins needed to load your ATMega 168/328 inside your project.
Reset, RX, TX, and Ground.
Take your 5 pin wiring harness and remove one of the center wires. In my case pin 2. Fill in the missing hole with some hot glue or a toothpick. This will give you a one way pattern that you can use repeatedly from one project to another ensuring that you don't get the plug in backwards and preventing damage to the chip.
Step 5: Useing the Arduino Prototype Shield.
Using the prototype shield is the easiest way to go. It will give you the pin connections that line up with the Arduino as well as a place to put your circuit for the leds.
I used three leds to show status outside the case.
Red is for power from USB port. Yellow for RX and Green for TX.
Using the above schematic drawing, create your circuit on the prototype shield.
You have two options for your led inputs (TX and RX):
One is to connect the TX and RX of this circuit to the TX and RX of the I/O pins....or
Two (the method I chose) You can soldier the TX and RX of the circuit directly to the left side of the leds on the UNO itself.
Step 6: Wiring the Connector.
Now that you have your circuit built on the prototype shield it's time to connect the cable. You can use any order you want. Some wire connectors use the same color wire and some don't. I recommend using one with different colors. Easier to keep up with.
I used the colors on the connector as follows:
Red = Reset on UNO to reset on ATMEGA 168/328 (chip pin 1). Keep in mind you still need to install the reset button with the 10k pull up resistor on the reset pin.
Black = Ground. You must establish a common ground connection, commonly known as bonding.
Yellow = Data in or TX connection on UNO digital pin 1 to the ATMEGA 168/328 digital pin 1 (chip pin 3)
Green = Data out or RX connection on UNO digital pin 0 to the ATMEGA 168/328 digital pin 0 (chip pin 2)
Step 7: Final Step
And finally it's time to add the header pin to your project.
Connect each pin of the header to the corresponding chip pins. Again you can use any order you wish as long as they match on both ends.
Remove the same position pin from the 5 pin male header as you did the harness earlier.
In this case I used header pins 1-5 removing pin 2:
1 = TX chip pin 3
2 = no connection
3 = Reset chip pin 1
4 = Ground
5 = RX chip pin 2
Once you have your "sketch loader" built and as long as you use the same header pin lineup on all your future projects you will be able to load all your sketchs straight into your project as well as making "on the fly" updates.
I used two of my projects to show how the "sketch loader" works.
Step 8: Programming
As you may have guessed by now there is no sketch support setup needed. Once you connect the UNO to your computer, locate the port number assigned to the device and right it on the front of your "sketch loader". No matter what project you plug it into it will be the same port number. The Arduino IDE software will see all your projects as the same device. Remember your ATMEGA 168/328 will need to have the bootloader already loaded.
On the back I wrote down the pin layout as reference for each new project. Now all you have to do is load your sketch just like a normal UNO.
I hope this is helpful. It sure made things easier for me.