programming ATmega chips over ICSP

So, after spending about 7 hours today figuring this out, I figured I would make a short tutorial. The information on how to this was very scattered, and some was not even documented (I had to look at some of the arduino configuration files). Now, what I wanted to do was use my existing programmed ATMega328p in a duemillanove to program another blank ATmega in a project, like
computer=>duemillanove=>blank or pre-programmed ATmega
This is nice because you don't need to buy any extra gear for programming, not an ICSP circuit OR a usb-serial converter for a boarduino. I used AVRdude, but things never seemed to work properly. Here's how I got it working on my mac. On the hardware side, I had a duemillanove loaded with arduinoISP, and this was hooked up to my boarduino. This is the standard setup for bootloading a blank ATmega chip over ICSP. Attatch pins 13, 12, and 11 on both the master and slave. Attach master pin 10 to slave reset pin. Attach ground on both units. That's the easy part, software was a lot trickier. First, one tutorial said to use fink to download AVRdude, but this IS NOT the latest version, and the config file does not include support for the atmega328 chip. I used macports, and that gave me version 5.8 with support for the atmega328p. So, I finally got support for that chip. But now it gave me a connection error! Some more internet research showed that I should set the baud rate to 57600, as opposed to leaving it unspecified. This appeared to work, and gave me a success message on AVRdude. But this would only produce really weird stuff, like the master arduino executing the program somehow without losing the bootloader, or the slave ATmega blinking slowly. Finally, I looked at some internal configuration files for uploading firmware over arduinoISP (note how the arduino app has a separate option for arduino as isp and avrisp) and the file showed that the ideal baud rate was actually 19200. So, in a last-ditch effort, I tried running AVRdude with this baud rate and success!

The command I used was
avrdude -p m328p -b 19200 -P /dev/tty.usbserialA900adK4 -c avrisp -U flash:w:/Applications/applet/testapplication.cpp.hex

the format is :
avrdude -p [chip code, if you don't know yours type something random in its place and a list will show up] -b [baud rate] -P [connection port] -c [programmer type, arduinoISP is avrisp] -U [memory type, most likely flash]:[just use w for programming]:[.hex file to upload]

I hope this can help you out and maybe save you some cash, I saved myself like 30 bucks on an ISP programmer and another 20 on a serial board for arduino. It's worth noting that if you install a program this way, it will erase the boot loader. This means 2 things:
1:there will be instant start-up, unlike bootloaded arduinos which have a slight delay
2:the arduino will NOT be programmable over serial unless you re-install the bootloader by hooking everything up and in the arduino app choosing tools>burn bootloader>w/ arduino as isp with the correct serial port and target board selected.

Now, another important part of this is how to get the .hex files after the arduino 0018 update. In the preferences.txt file (look it up on arduino.cc to find it), you have to add the line build.path=applet or something similar, in my case it will build in /Applications/applet/. This makes finding the files much easier.

this is a pretty hasty tut and I probably forgot some stuff, but I hope it will save somebody the frustration I experienced ;D
will

Maybe you could put this into the ArduinoCoreHardware Arduino Playground.

The trouble with posting on the forum is it will slip into history, and not be found as easily as a playground page.

HTH
GB-)

Good idea, but first I need to revise it. I kind of want to bounce it off people first, just in case I have a freak computer and this only works for me LOL.

I am a bit puzzled why you needed to download avrdude.
When I install the Arduino environment I get avrdude installed as part of it.

GB

Do you have a PC? For me (on a mac), AVRdude is packaged into the arduino app and I can't activate it by simply typing in "avrdude" in terminal. I have to CD a bunch until I get into the app, then do "./avrdude".

I have a Mac.

Do you understand how the OS X Terminal (which runs bash) finds programs? Bash looks in all of the directories (folders) on a list stored in an environment variable called PATH.

I added the directory (folder) containing avrdude to bash'es PATH variable in .bashrc. Then I can just run it from any Terminal no matter what directory (folder) I am in.

HTH
GB

facepalm well you learn something new every day. I guess I'll leave AVRdude installation out of a tutorial. How do I add something to PATH? is it a file I can vim or what?

A good way to add something to PATH is to edit the .bashrc file in your home directory. This is the file which bash reads to set itself up before accepting input from the keyboard. If you do it this way, everything will be set up every time you run Terminal.

When you start the Terminal application, you will be in your home directory. If you type "ls -a" you will see all the files.
If you start vim (or whatever text editor you like) eg. with "vim .bashrc" you should see a file (my setup is so old, I honestly can't remember if there is a .bashrc already). If not, it doesn't matter, this will create it.

you need to add a line which looks something like:
export PATH=$PATH:/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin

where needs to be filled in appropriately.
I usually just navigate to a folder with the file browser, then drag the folder icon from the title bar to the editor window.
Save the file, and restart Terminal, and you'll find avrdude is invoked from the command line.

HTH
GB-)