Arduino on Xcode Project — Official Thread

pde / .ino files are considered as .cpp files and are natively supported.

That is probably a problem for many existing arduino sketch projects because the .pde files in arduino are joined into a single cpp file . This allows all of the variables and methods of every .pde to be shared (and is heavily used by many arduino sketches).

.cpp files need .h files and public declrations + #includes to be access by other files where as .pde files are global. Example: if we have void Test() {} in Blink2.pde then it should automatically be accessible from Blink1.pde

The joining of .pde files into a single .cpp is where the complexity arises when mapping error line numbers back to source. This is why I asked about it so often, it's messy!

Infact the problem is even worse, as you say you need the arduino.h or wprogram.h but Arduino also extracts and automatically adds the prototypes for each .pde method.
So when we translate error source line numbers we need to subtract the header lines then any other combined pde file line lengths.

Would you like to consider NetBeans instead

Normally no, because I am very happy with Visual Studio and would like to get back to building sketches instead of plugins :slight_smile:
But my nephew wants me to install netbeans to help him make some minecraft mods :slight_smile:
So maybe netbeans is a solution, escpecially because the arduino ide source is .java files so should be easily portable to netbeans? I would be happy to help you if you do!!

I was talking about Xcode hidden features but you're right in pointing Arduino ones.

Wait a minute: Are they features or bugs?

IMHO, I think we shouldn't mimic Arduino bad habits —or not so good habits— when using a real IDE as Visual Studio, Xcode, NetBeans or alike.

We could go back to a more canonical way of programming and get rid of the false automatons that make programers' life more difficult.

That's the way I've taken, in order to get as much as possible from Xcode.

But my nephew wants me to install netbeans to help him make some minecraft mods

Splendid, just suggest him this challenge: building an Arduino plug-in for NetBeans!

IMHO, I think we shouldn't mimic Arduino bad habits —or not so good habits— when using a real IDE as Visual Studio, Xcode, NetBeans or alike

I hear what you say but actually I think the Arduino design is for users who don't want the complexities of .cpp/.h and #includes. The objective with the Visual Studio plugin was to be 100% compatible with Arduino ensuring a 100% identical program output. That said, more advanced users should find your xcode solution to be excellent

Splendid, just suggest him this challenge: building an Arduino plug-in for NetBeans!

:slight_smile: Can you believe it. 10 years old, already installed netbeans and has no interest in learning how to make an led light up with an Arduino. Doh!

HaakonStorm:
Wow! I just recently found the mpIDE app and the mpide xcode project, and wanted to try this with my UNO. I'm getting some strange
errors so far. I got as far as a clean compile, but uploader returns with error 2 (programmer not responding). I might be
doing something wrong.

I experienced the same error.

Just add the -F flag to AVRDUDE_COM_OPTS:

AVRDUDE_COM_OPTS  = -q -V -F -p $(MCU)

The original structure of the makefiles in mpideXcode was limiting further development (because it was depending on the sole MPIDE application for both Arduino and chipKIT boards) and wasn't flexible enough (with one single file for all).

Now, the new makefiles suite uses Arduino IDE and chipKIT MPIDE for their corresponding boards. Adding a new platform only requires adding a new makefile specific to that platform.

So the new name for the project is embedXcode!

Hi,

just read all the posts of this thread - So you all don't have any problems with the output from Serial.println();? I just cloned tims Arduino-With-XCode project and also tested some other projects but I don't get any logs in xcode. The rate is set to 9600 bps Serial.begin(9600); Did I miss something to get the output?

Oh, and thanks for all the help getting a projet to work in xcode!

Actually, the output from Serial.println() goes to a separate Terminal window.

I can't manage to get it on the Xcode debug window.

Someone has found a trick but I can't replicate it.

avenue33 -

Can't you simply associate the .pde extension with the Xcode app in order for it to appear as a C++ Source file inside of Xcode?

I've just added to release 1 an Installation Guide.

As usual, the repository is rei-vilo/embedXcode

ave33 et. al.

Awesome work! Just stumbled upon this. Tried to get a project working as per the pdf instructions, there appear to be a couple of snags. I don't have a "Libraries" folder in my ~/Documents/Arduino folder. Also, some funny business with the Build and Make targets- at first glance, it looks like the location that is expected for the arduino_pins.h is incorrect, and the script ends up making empty .h and .c files for it? Build and Make fail because of this.

I have to run, but will give this a good look later and report back. The thought of being able to use XCode for this is too cool.

Note- The Serial target works just fine, puts up a Terminal window that does communicate with the Arduino.

Dave

Oh, yeah, I'm using the Arduino 1.0. Is the project template compatible with this?

Dave

Thank you for the accolade.

Just add a Libraries folder into your sketchbook folder.

I know there are too many targets. Build includes Clean and so compile everything from scratch, while Make only compile updated files for faster answer. Build = Clean + Make, as in Borland Turbo Pascal :wink: .

Arduino 1.0 ins't supported yet. Among the main reasons:

  • Based on feed-back from the forum, Arduino 1.0 doesn't seem to be stable enough.
  • chipKIT UNO32 IDE is still 0023 based, as other boards.

So I rather prefer to wait before updating the project and template.

Nothing worse than addressing two different and incompatible releases!

Has the Installation Guide helped you?

Feel free to participate. I've listed the open issues on the GitHub repository.

Hey,

Thanks for the fast reply. No prob, I'll be happy to go back to 0023 if I can use XCode as the IDE :wink:

My board of choice is the Teensy right now, maybe I can figure out how to make it one of the board options...

Cheers,

Dave

New releases add Arduino 1.0 support.

embedXcode • Mar 06, 2012 release 4 - Arduino 1.0 support
mpideXcode • Mar 06, 2012 release 7 - Arduino 1.0 support

Code is here and documentation there.

Next step is to add Wiring, if I find a Wiring S board to test the upload.

Unfortunately your template doesn't seem to work for me without quite a few tweaks. I have Arduino 1.0. I've followed all the steps in your guide, but I firstly get an error in Step1.mk "Error: no application found". That's because in Step1.mk ARDUINO_APP = /Applications/Arduino23.app when it should be just Arduino.app.

Upon fixing that, I then get

grep: /Applications/Arduino23.app/Contents/Resources/Java/hardware/arduino/boards.txt: No such file or directory

Sometimes I get an error that the compiler can't locate "pins_arduino.h". Doing the following fixes both errors.
In Step1.mk, change

include $(MAKEFILE_PATH)/Arduino23.mk

to

include $(MAKEFILE_PATH)/Arduino1.mk

Also, inside Arduino1.mk "APP_HEADER = WProgram.h" appears to be wrong, as Arduino 1.0 uses Arduino.h.
APPLICATION_PATH in the same file assumes the Arduino 1.0 is called "Arduino1.app" also. Most people won't have a number in their Arduino app name, it'll just be the default Arduino.app. CORE_LIB_PATH should have a lower case "Arduino" in the path, as it's lower case in the filesystem (in Arduino 1.0 at least). Currently, this won't work on case sensitive filesystems. USER_LIB_PATH should have a lower case "libraries".

If leaving the target on All, an error "/bin/sh: Builds/nil: No such file or directory" occurs. After using other targets, the Builds folder is created so the error goes away. A Builds folder should be in the file template.

main.cpp in the project template should be Arduino.h not WProgram.h. Same in the C++ and Library file templates.

Another thing, why do you force people to enter their name and email address to access the files through Google Docs? Why did you remove everything from GitHub? Makes it rather difficult to see what changes have been made... Don't get me wrong, it's great that you're helping out with your template, just seems you're trying to hide it from everyone!

Elijahg,

Thank you very much for the detailed feed-back on the template.

I'm working on the points you mention.

I've been obliged to implement this indirect download mode due to unpleasant experience with other projects, not to mention cooperation on GitHub close to nil.

Elijahg:
Unfortunately your template doesn't seem to work for me without quite a few tweaks. I have Arduino 1.0. I've followed all the steps in your guide, but I firstly get an error in Step1.mk "Error: no application found". That's because in Step1.mk ARDUINO_APP = /Applications/Arduino23.app when it should be just Arduino.app.

Upon fixing that, I then get
Sometimes I get an error that the compiler can't locate "pins_arduino.h". Doing the following fixes both errors.
In Step1.mk, change

Fixed. Arduino.mk now points to Arduino.app.

Elijahg:
Also, inside Arduino1.mk "APP_HEADER = WProgram.h" appears to be wrong, as Arduino 1.0 uses Arduino.h.
APPLICATION_PATH in the same file assumes the Arduino 1.0 is called "Arduino1.app" also.

Fixed.

Elijahg:
Most people won't have a number in their Arduino app name, it'll just be the default Arduino.app.

Fixed.
Arduino.mk addresses Arduino.app.
Arduino1.mk and Arduino23.mk makefiles are supplied for convenience.

Elijahg:
CORE_LIB_PATH should have a lower case "Arduino" in the path, as it's lower case in the filesystem (in Arduino 1.0 at least). Currently, this won't work on case sensitive filesystems. USER_LIB_PATH should have a lower case "libraries".

Fixed for SketchBook/Library or library.
Fixed for /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino
By default, OS X is case insensitive.

Elijahg:
If leaving the target on All, an error "/bin/sh: Builds/nil: No such file or directory" occurs. After using other targets, the Builds folder is created so the error goes away. A Builds folder should be in the file template.

Fixed.

Elijahg:
main.cpp in the project template should be Arduino.h not WProgram.h. Same in the C++ and Library file templates.

Actually, the #include in main.cpp is used to activate code-sense.
Fixed in the Library file template.

I hope to release the updated version soon.

Thanks again for the detailed feed-back.

Feel free to explore Xcode 4.3-related issues!

avenue33:
By default, OS X is case insensitive.

It is yes, but it's always best to write code that handles unexpected or unusual conditions rather than just failing :slight_smile:

Actually, the #include in main.cpp is used to activate code-sense.
Fixed in the Library file template.

With WProgram.h included in main.cpp code sense doesn't work for me. If I change it to Arduino.h it works right away. The default .pde file includes WProgram.h too when it should again just include Arduino.h

There's a small problem with uploading too, for some reason the port for AVRdude to use gets lost somewhere. Changing AVRDUDE_PORT in Avrdude.mk to $(BOARD_PORT) fixes that.

Thanks again for the detailed feed-back.

No problem, thanks for the template!

Elijahg:
There's a small problem with uploading too, for some reason the port for AVRdude to use gets lost somewhere. Changing AVRDUDE_PORT in Avrdude.mk to $(BOARD_PORT) fixes that.

That's strange, AVRDUDE_PORT is defined in Avrdude.mk by:

AVRDUDE_PORT      = $(firstword $(wildcard $(BOARD_PORT)))

with BOARD_PORT defined in Arduino UNO.xconfig by

BOARD_PORT = /dev/tty.usbmodem*

or in Step1.mk otherwise by

ifndef BOARD_PORT
    BOARD_PORT = /dev/tty.usb*
endif

Arduino UNO.xconfig has priority over Step1.mk.

avenue33:
That's strange, AVRDUDE_PORT is defined in Avrdude.mk by:

AVRDUDE_PORT      = $(firstword $(wildcard $(BOARD_PORT)))

with BOARD_PORT defined in Arduino UNO.xconfig by

BOARD_PORT = /dev/tty.usbmodem*

or in Step1.mk otherwise by

ifndef BOARD_PORT

BOARD_PORT = /dev/tty.usb*
endif


Arduino UNO.xconfig has priority over Step1.mk.

Board_port is pulled from the config file fine, but "$(firstword $(wildcard $(BOARD_PORT)))" seems to return nothing, making AVRDUDE_PORT blank. Without $(firstword $(wildcard it works fine.