Coding your Arduino projects using Xcode

NOTE: You can only do this with C and C++. All this does is use the Makefile to compile with.

Why: Because it allows you to use all the Xcode goodies to building Arduino apps. Reason I did this was actually because I was bored.

How: Easy either download my pre-built package or follow along.

Download the newest version of Arduino unless you already have it. I put mine on the Desktop "arduino-0010". Now start a Xcode project. Select "Empty Project" After that add a new .cpp file to Xcode. Now we need to import the Makefile from our arduino directory. Import an existing file. "arduino-0010/hardware/cores/arduino/Makefile" Now we need to change the Makefile to suite our needs.

Add this after the comments in the make file.

BIN = /Users/silas/Desktop/arduino-0010/hardware/tools/avr/bin

Change this to what ever your cpp file is called. Ex. If it is called test.cpp put test

TARGET = test

for ARDUINO put

ARDUINO = /Users/silas/Desktop/arduino-0010/hardware/cores/arduino

Now this might be the trickest part. in # Program settings line 119 change all those lines till 128 to this

# Program settings
CC = $(BIN)/avr-gcc
CXX = $(BIN)/avr-g++
OBJCOPY = $(BIN)/avr-objcopy
OBJDUMP = $(BIN)/avr-objdump
AR  = $(BIN)/avr-ar
SIZE = $(BIN)/avr-size
NM = $(BIN)/avr-nm
AVRDUDE = $(BIN)/avrdude

Now what we need to do is add a Target so that we can build our app via Hitting the Build button in Xcode. Right click on Targets and click Add new Target. Click Shell Script Target Type Build Hex Close the window that pops up. Now hit the little arrow to the right of the Targets. You will now see Build Hex right click it and now choose New Build Phase - New Run Script Build Phase. Now in the script dialog box type

make clean
echo "BUILD"
exit 0

Now you are finished. You can read the Makefile to setup your cpp file for building. After you do that you can now click Build to get a build. If you look in your project directory you will hopefully see a test.hex file. If so then I wrote this tutorial correctly and you followed it correctly. If not post a message and I will try and help you.

Now for uploading. Add a New Target. Then a New Build Phase Script. This time put this in

make upload
exit 0

I couldn't test this part but it should work.

I hope that people can add to this tutorial because I could see some good come out of it. Right now there is no way to clean the code. You have to run Build again. You could create another Script Phase for

make clean
echo "CLEANED"
exit 0

but I didn't like that. I wish there was some way you could customize the Clean command in Xcode. If someone knows how that would be sweet.

I know that this is a crappy tutorial but I was rushed to get it out before I drive to Cincy. Again here is the pre-built package

Huh... would like to put this together but I get a 404 trying to get the zip...:(

Hej i cant open the Zip file i always get a 404 problem

can you send it again or post it up again