I’ve found that most tutorials relating to Xcode and Arduino don’t work. For the most part it seems that the arduino IDE gets an upgrade and files get shuffled around breaking peoples xcode and arduino setup. This tutorial is a modified version of Robert Carlsen’s. I found I had to make several modifications to get it working for me.
What You’ll Need:
- Arduino 0018
- Xcode 3.1 from Apple (I haven’t tested this on the newer 3.2. Let me know if it works for you)
- CrossPack for AVR (using version 20100115 for this tutorial)
- An Arduino (Using a freeduino with atmega168. I’ll give some specifics on using other version too)
- Modified version of Robert Carlsen’s ArduinoOnXcode template
Setup:
- Install xcode
- Install Arduino
- Install CrossPack. The tools are located at /usr/local/AVRMacPack
- Uncompress the ArduinoOnXcode project template. Move it to /Developer/Library/Xcode/Project Templates/Other/
- Open the Makefile in the AurdinoOnXcode folder. Edit MCU, ARDUINO, UPLOAD_RATE, and AVRDUDE_DIR if needed. The included values will work with an Arduino Diecimila/Duemilanove with an atmega168 chip. See below if you’re using and atmega328 or Arduino Mega.
- atmega328 use the following value:
- MCU atmega328
- UPLOAD_RATE 57600
- Arduino mega use:
- MCU atmega1280
- UPLOAD_RATE 57600
How to Use:
Create a new project in Xcode and select ‘Other’ then ‘ArduinoOnXcode’. It will ask for a new location to save the file.
Main.cpp is where your arduino code lives. Currently the project has a blinking LED sketch.
I’ve added the “clean all” button to my toolbar by right clicking on the toolbar and selecting “customize toolbar”. This is the button you’ll use to upload your sketch to the arduino. Once you’ve written your code just make sure that upload is selected in the dropdown menu and press “clean all”.
Head over to Robert Carlsen’s page for a few more handy tips.




Thanks for the compiled tutorial!
Just another data point: This still works with Arduino 0021 (the latest pack)
Also, those who would want to use this with Uno and MEGA, please check out:
Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/boards.txt
This file contains all the values for the MCU, upload speed and the protocol.
Hi – I got this to work with Arduino 0022 and XCode 3.2 using a Diecimila 168.
I had to add $(ARDUINO)/WString.cpp to line 73 before $(ARDUINO)/Print.cpp
Thanks!
Thank you for the useful hints.
On my MacBook, with Xcode 3.2.5 on OS X 10.6.6, I have to change line 67 of Makefile from
PORT = /dev/tty.usbserial* # does not work
to
PORT = /dev/tty.usbmodem* # works
Best regards,
Hi!
I can’t manage compiling projects involving a library. After some research, it seems to be related to the link options.
Full report at http://arduino.cc/forum/index.php/topic,49956.0.html
Any idea?
Thank you and best regards,
yeah I had this same problem. I haven’t come up with a solution though.
This is great, but I haven’t got it working with xCode 4.2. Anyone have a template for the new xCode format ?
I used Xcode 3 to program my Arduino using a template with the AVR tool-chain and the right Makefile.
It worked fine. See http://bit.ly/s4uASG.
But with Xcode 4, everything has changed for the template and I’m lost.
Does any reader try and write a template for Arduino?
I manage to use Xcode 4 for Arduino and chipKIT platforms.
Two issues:
1• personal #include libraries are not compiled/linked
2• templates on Xcode 4 are not compatible with Xcode 3 ones.
So I may need some help but here’s abase to start with at http://bit.ly/uEyP4c
I managed to develop a template running on Xcode 4.3 for Arduino and chipKIT boards.
See https://github.com/rei-vilo/embedXcode and http://sites.google.com/site/vilorei/
I’ve developed an Xcode 4.3 template for Arduino and chipKIT boards.
Code is here https://github.com/rei-vilo/embedXcode
And explanations are there http://bit.ly/xy0UQU
Enjoy and participate!