Programming Micro Controllers ATMEGA328
Overview Why? Arduinos are great prototyping tools but are very expensive ($20 to $50). Stand alone microcontrollers are vastly cheaper ($0.99 to $5). Stand alone microcontrollers are also more compact We are going to introduce standalone microcontrollers and show you the basics of programming and using one We will be using the ATMEGA328 as an example This is the same microcontroller that most Arduinos are built around
Steps 1: Set up the microcontroller on the bread board There are several components needed for the microcontroller to run reliably and communicate with the programmer 2: Boot load the microcontroller ship Think of this like downloading the operating system for the chip 3: Program the microchip Adding code to change the functionality of the chip 4: Add additional hardware with the help of pinouts
Step 1 First we need to set up our microcontroller on the breadboard You will need a following components to set up an ATMEGA328 Two 22pF capacitors One 10KΩ resistor One 16MHz Crystal 6 to 10 jumper cables Obviously one ATMEGA328 microcontroller On the next page is a schematic showing you how to set up the ATMEGA on a breadboard
Wiring diagram of set up Schematic of set up
Picture of set up
Talking to the Chip Before we can move on to step 2 we need to discuss how to get information off your computer and onto your microcontroller There are several options Use an Arduino Duemilanove Board Use a dedicated microcontroller programmer In this tutorial we will use another Arduino Board to program our ATMEGA328 If you want to read more about different options here is a link going more in depth on the issue.
Step 2 : The Wiring Step 2 is boot loading the ATMEGA328 Boot loading is essentially the same as installing the operating system that the chip will use First connect your Arduino to the breadboard according to the schematic on the next page Disconnect any external power sources attached to the board Use the 5V and GND pins of the Arduino to power the board as shown in the schematic
Boot Loading Schematic
Step 2: The Software After you have verified everything is correctly wired it’s time to move to the software First upload the Arduino ISP code from examples Secondly Set the programmer to the correct setting
Step 2: The Software Finally boot load the chip! This could take some time expect between thirty seconds and two minutes of time If it gives you an “out of synch” error do not worry this is common and 99% of the time can be fixed just by trying again
Testing Your Boot Load All chips will automatically have the example program “Blink” on the chip after you boot load it Attach a 560Ω resistor and an LED to PIN13 If it blinks your boot load was successful! If not don’t panic your LED might be burnt out or wiring wrong troubleshoot and reboot if necessary
Step 3: The Wiring Now that the chip is boot loaded it is ready to receive code Unfortunately this requires a different wiring set up This set up does not require any additional hardware other than a few jumpers First remove the Arduino’s microcontroller from it’s perch (this is fairly tough and will require some prying) Secondly wire according to schematic on the next page
Programming Schematic
Programming Set Up
Step 3: The Software This is where things get familiar Select the Duemilanove w/ ATmega328 from the Board menu Now you can upload code the exact same way that you would on an Arduino!
Step 4 At this point you can add hardware and upload sketches as you normally would any Arduino Below is the Pin Map for the ATMEGA328 Red lettering indicates Arduino equivalent
Words of Caution Most microcontroller chips can only handle 5V. You will very likely short circuit your chip if you give feed it more than 5V! Do not forget to remove the microcontroller on the Arduino board when programming or your program WILL NOT upload to the chip on the bread board. If you want to learn more check out the links below http://arduino.cc/en/Tutorial/ArduinoToBreadboard http://arduino.cc/en/Main/Standalone https://learn.sparkfun.com/tutorials/tiny-avr-programmer-hookup-guide