Setting up Xcode to Compile & Upload to an Arduino ATMega328 (Duemilanove)

This morning Joshua Noble tweeted a link to this excellent post that details how to setup your Xcode environment to compile & upload to an older Arduino168 like a Diecimila. This is awesome for anyone who would rather code in a more feature rich environment than the Processing / Arduino IDE such as myself. However, while trying to get this working with my Duemilanove, I ran into a few problems compiling and uploading code to the board.

After sifting through the comments and making some tweaks to the Makefile I finally got this working and so without further ado, here are the steps to get Xcode talking to your ATMega328 (Duemilanove).

1. Install Xcode obviously if you haven’t already.
2. Download & Install the Arduino IDE as you still need the core Arduino libraries to compile against.
3. Download & Install the AVR Programming Tools. The most recent version worked fine for me.


4. Download this Project Template to compile & upload the “Blink” sketch to confirm everything is working.
5. Unzip the template and put it in /Developer/Library/Xcode/Project Templates/Other/
6. Now fire up Xcode and create a new project from the template found in Other -> ArduinoOnXcode


Now take a look at the Makefile in your new project. This file defines all your compiler arguments and tells Xcode where to find the dependency libraries it needs on your system.


The AVR Programming tools should have installed to /usr/local/CrossPack-AVR

If for some reason this is not the case be sure to set the correct path so Xcode can find your CrossPack in the AVRDUDE_DIR on line 65. Note also that /usr/local/CrossPack-AVR is a symlink so if you are using a newer version of the CrossPack this path should still work fine.

At this point connect your Arduino to one of your USB ports, change the Active Target to “Upload” and select “Clean All Targets” from the Build menu and you should see the the TX/RX lights flash rapidly as the code is compiled and uploaded to the board.

Now go ahead and make some changes to the main.cpp file in your project, recompile and you should see these changes reflected on your board.

Note, I still get a few warnings on compilation that I think are related to properties in the Makefile.
Any suggestions to remedy these warnings or any other improvements are most welcome in the comments below.