June 4, 2009

Arduino XCode Template

Filed under: Arduino, various stuff — melka @ 5:04 am

I had some time today, and I wondered how to code Arduino sketches using XCode.

So I made a template. You can download it here : http://www.sendspace.com/file/ebij84

More infos next (README.txt file from the archive)

  1. ==============================
  2. = ARDUINO XCODE 3.1 TEMPLATE =
  3. ==============================
  4.  
  5. Introduction :
  6. This is a XCode 3.1 template project that I
  7. made in order to code, build and upload Arduino
  8. sketches in XCode.
  9. Why ? SVN, code completion, code folding, syntax
  10. coloring, etc…
  11. Feel free to use and modify it as you want.
  12. If you make any significant improvement, please
  13. tell me : melka@melkaone.net
  14.  
  15. Thanks :
  16. This template is based on the Makefile by
  17. Martin Oldfield
  18. http://mjo.tc/atelier/2009/02/arduino-cli.html
  19.  
  20. Disclaimer :
  21. I made this project for my personal use. If you
  22. can’t make it work despite the installation
  23. instructions, drop me an email, but my answer may
  24. be delayed.
  25. My board is an Arduino NG with an ATMega168. I
  26. don’t have the time and hardware to test other
  27. build settings.
  28.  
  29. Installation :
  30. - Be sure that your Arduino installation path doesn’t
  31.   contain any weird character like spaces and slashes.
  32.   Example : /Applications/arduino-0015/Arduino.app = good
  33.             /Users/tom/Arduino IDE/Arduino.app = bad
  34.  
  35. - Find some infos for your board.
  36.   List of boards can be found here :
  37.   http://code.google.com/p/arduino/source/browse/trunk/hardware/boards.txt
  38.   What we’ll need : mcu type, frequency and upload speed.
  39.   Example : the new Arduino Mega.
  40.   mega.name=Arduino Mega
  41.   mega.upload.speed=57600    > UPLOAD SPEED
  42.   mega.build.mcu=atmega1280  > MCU TYPE
  43.   mega.build.f_cpu=16000000L > MCU FREQUENCY
  44.  
  45. - Open the ArduinoBaseTemplate/___PROJECTNAME___
  46.   xcode project
  47. - Go to Project -> Edit Project Settings
  48. - Modify the Settings :
  49.    ARDUINO_DIR :
  50.       Installation directory of the Arduino IDE.
  51.       Needed to access libraries and tools
  52.    ARDUINO_PORT :
  53.       Serial port used by your arduino board.
  54.       You can find it by launching the Arduino IDE
  55.       and looking in Tools -> Serial Port
  56.    AVRDUDE_PROGRAMMER :
  57.       Type of programmer used by avrdude.
  58.    F_CPU :
  59.       CPU Frequency (16000000 = 16MHz)
  60.       Put the .build.f_cpu var here (without
  61.       the ending L)
  62.    INCLUDE_LIBRARIES :
  63.       Libraries to include, leave as is for the
  64.       template.
  65.    MCU :
  66.       Microcontroller type.
  67.       Put the .build.mcu var here
  68.    TARGET :
  69.       Main class. Do not change.
  70.    UPLOAD_RATE :
  71.       avrdude upload speed.
  72.       Put the .upload.speed var here
  73.  
  74. - Close the settings
  75. - Expand the includes group. You’ll see 3 groups :
  76.   core, examples and libraries
  77.   For each one, click on File -> Get Info, click on
  78.   Choose and change the Path.
  79.   Core      : /hardware/cores/arduino
  80.   Examples  : /examples
  81.   Libraries : /hardware/libraries
  82. - Those paths won’t be used on build, it’s just to get
  83.   code completion etc…
  84. - Open src/main.cpp
  85.   This is a test program
  86. - Choose the make_upload target and build the project (Build -> Build)
  87. - If it doesn’t work, make sure you did all the steps
  88.   correctly. You can use the build console (Build -> Build Results)
  89.   to get infos on the build process. Don’t forget to check
  90.   the 3 icons at the bottom of the window (checkmark,
  91.   warning sign, and text) to view all the infos.
  92. - If it works, you can launch your favorite Serial Terminal.
  93.   Each time you’ll send a character, it will be written to
  94.   EEPROM and the Arduino will send you back all the infos
  95.   it stored.
  96. - Once you’re sure that it works, you can delete all the code
  97.   in main.cpp. Get sure to leave the commented header and the
  98.   setup() and loop() declarations.
  99. - Reopen the project settings and delete EEPROM from
  100.   INCLUDE_LIBRARIES.
  101. - Save and close XCode
  102. - Delete the build folder that XCode automatically created
  103. - Go to /Library/Application Support/Developer/Shared/
  104.   XCode/Project Templates
  105. - Create a folder named Arduino
  106. - Copy the ArduinoBaseTemplate folder in the folder
  107.   you juste created
  108. - Launch XCode, File -> New Project
  109. - You’ll see a new Arduino category with the template in it.
  110. - Start having fun.
  111.  
  112. A bit more informations :
  113. - When you create a new project, be sure that you don’t have
  114.   any weird characters in the path name either, or the build
  115.   will fail. If anyone know how to modify the Makefile to
  116.   allow for exotic path, please post infos.
  117.  
  118. - INCLUDE_LIBRARIES setting :
  119.   Each time you want to include a library (like EEPROM.h in
  120.   the test project), you have to add the name in this field.
  121.   For example, if you want to use Firmata and EEPROM, the
  122.   INCLUDE_LIBRARIES field will be :
  123.   EEPROM Firmata
  124.   Don’t forget to add #include "library.h" in the main.cpp
  125.  
  126. - As I said, the core / examples / libraries folder are not
  127.   used for builing the .hex file, but for allowing
  128.   XCode to have code completion and such.
  129.  
  130. - I’ve included a small applescript called SerialTerminal.scpt
  131.   in the utils folder. This is a dead simple Serial Terminal that
  132.   uses Terminal.app and screen to connect to your Arduino.
  133.   You can launch it from XCode by building the Terminal target.
  134.   The code is from here :
  135.   http://www.macosxhints.com/article.php?story=20061109133825654
  136.  
  137. - It’s late and I’m tired, so I’ll stop there. Cheers.
  138.  
  139. melka
  140. melka@melkaone.net
  141. http://melka.one.free.fr/blog/



5 Comments »

  1. tx,

    Comment by balam — June 4, 2009 @ 5:00 pm

  2. [...] melka » Arduino XCode Template Arduino Xcode template (tags: arduino xcode development) [...]

    Pingback by adoption curve dot net » Blog Archive » links for 2009-06-05 — June 6, 2009 @ 2:04 am

  3. Super ! Merci beaucoup pour ce travail, je n’avais jamais pensé à faire un truc pareil car l’IDE arduino est disponible…
    Merci encore !

    Comment by Anthony — June 6, 2009 @ 1:13 pm

  4. So can you upload the sketches from XCode too?

    Comment by Mike — June 17, 2009 @ 3:29 am

  5. I haven’t tested it with the newer arduino boards that don’t require you to press the reset button, but on my old Arduino NG, I just have to press the reset button on the board then Build on XCode and it compiles then upload the sketch

    Comment by melka — June 17, 2009 @ 9:47 am

RSS feed for comments on this post. TrackBack URL

Leave a comment