Programming Arduino with Xcode

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:

Setup:

  1. Install xcode
  2. Install Arduino
  3. Install CrossPack. The tools are located at /usr/local/AVRMacPack
  4. Uncompress the ArduinoOnXcode project template. Move it to /Developer/Library/Xcode/Project Templates/Other/
  5. 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.

11 Comments on "Programming Arduino with Xcode"

  1. thechimerical says:

    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.

  2. Louis says:

    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!

  3. avenue33 says:

    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,

  4. avenue33 says:

    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,

  5. Nick says:

    yeah I had this same problem. I haven’t come up with a solution though.

  6. Mark Windrim says:

    This is great, but I haven’t got it working with xCode 4.2. Anyone have a template for the new xCode format ?

  7. Rei Vilo says:

    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?

  8. Rei Vilo says:

    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

  9. Rei VILO says:

    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/

  10. Rei VILO says:

    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!

Trackbacks for this post

  1. Sharp IR sensors with arduino | Tekstop!

Got something to say? Go for it!