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.