Pages: 1 2 [3] 4 5 ... 46   Go Down
Author Topic: Arduino on Xcode Project — Official Thread  (Read 147965 times)
0 Members and 1 Guest are viewing this topic.
SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 137
Posts: 6805
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the "no .pde" problem is as easily solved by renaming your main file.
Easily solved by the typical XCode user.  I don't think you're properly visualizing the level of cluelessness of the would-be consumer of a pre-made Arduino sketch.  "rename main.cpp to foo.pde in a directory name foo, and put all the other file there too" just has SO many things that could go wrong.

Quote
On the other hand what is the benefit of working with pde files in XCode?
given a sketch containing .pde, .ino, .cpp, .c, and .S files, the .cpp, .c, and .S files are all compiled using standard c/c++/assembler conventions, while the .pde and .ino files are concatenated and (potentially)  get special preprocessing and automatic #includes.  Which is just a separate makefile rule, really, although the "preprocess" function doesn't exist.  While there's no big reason not to make .pde files have their own #includes and prototypes so that the preprocessing isn't needed in an XCode environment, excluding the processing of .pde/.ino files from your Xcode processing makes SW developed there "gratuitously incompatible" with the Arduino environment.

It is (I claim) desirable that the XCode Arduino developer be able to pack his Arduino project into a .zip file and ship it to an Arduino IDE user, where it should compile without any changes.  (I suppose that the zip file in question could be a separate XCode "target", but that seems to be unnecesarilly complicated.)
Logged

Antwerp, Belgium
Offline Offline
Jr. Member
**
Karma: 2
Posts: 64
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hmm there's some interesting stuff there...

Quote
Easily solved by the typical XCode user.  I don't think you're properly visualizing the level of cluelessness of the would-be consumer of a pre-made Arduino sketch.  "rename main.cpp to foo.pde in a directory name foo, and put all the other file there too" just has SO many things that could go wrong.
To me, it seems this point of view is a little bit overly cautious towards the "beginner Arduino User".
We were all beginners at a certain time and I think this little challenge of renaming a main.cpp file into a project_folder_name.pde file is only a small step to make you learn something new. Compared to learning about pointers, inheritance or even functions, renaming a file seems like a piece of cake. (mmm.. cake :-))

Before I started this effort to try to make an Arduino project with XCode, I had no knowledge at all about makefiles. Just by doing this I already learned so much about this completely new topic. It's fun! And it's a great way to learn too: trying to take this next step and looking through other people's code trying to make sense of it...
It's great that the Arduino IDE is working so good "out of the box" so beginners can get their hands dirty immediately. But at a certain point, if you want to create more complex programs you'll want to learn about classes, pointers, etc and then it is actually a good thing to have a more advanced software community that can happily program in their "professional" IDEs and assist those people.

But what if the Arduino IDE would allow correctly formatted C/C++ code? Then there would be no compatibility problem anymore, right?

I feel we're getting a little bit off topic here.. this thread was going to be about getting XCode to compile Arduino projects I believe.
So let's first get the templates ready for XCode 3.2.x and XCode 4.x and all the different boards, get them properly working for everybody and then worry about the potentially more complex problem of compatibility with the Arduino IDE.

If you have any suggestions on how to solve this problem, let's hear 'em! Maybe there is a very simple solution that I'm not seeing right now... like a simple text file included in the XCode template that explains what to modify for use in an Arduino IDE and vice versa?

best,
tim

Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 225
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi I've been playing around with this and can compile and upload sketches.  Could you explain exactly how I can include a user-defined library with this template?

Suppose I have a library named foo located in the standard places:

~/Documents/Arduino/libraries/Foo/foo.h
~/Documents/Arduino/libraries/Foo/foo.cpp
~/Documents/Arduino/libraries/Foo/keywords.txt

how can I include it in the Xcode project?


Also, is it necessary to have the "ArduinoProgram" class with setup() and loop() methods, or can I write setup() and loop() functions in main.cpp?

Thanks much
Logged

Antwerp, Belgium
Offline Offline
Jr. Member
**
Karma: 2
Posts: 64
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Professor,

That's a very good question. I suddenly realize that I've made this not so user friendly.
Basically, what you need to do is find the variables CPP_LIBRARIES, INCLUDE_LIBRARIES and CXXSRC and add some things.

I will update the github repository as soon as possible with a new makefile and build settings that allow you to add libraries of your own without needing to touch the makefile. I will report back here when that's uploaded to github.

Meanwhile, here is an example of how you could modify the makefile:
Make sure not to use ~/ for your home path, but the full name : /Users/yourUserName/ ... (because of a mistake I made)
Code:

#.. beginning of makefile...

# loading libraries
LIBRARIES = EEPROM Ethernet/utility SPI \
Firmata LiquidCrystal Matrix Sprite \
SD SD/utility Servo SoftwareSerial \
Stepper Wire Wire/utility

# Here you add the paths to the folders that contains the cpp files of your libraries:
OTHER_LIBRARIES = /Users/yourName/Documents/arduino_sketchbook/library1 \ # << backslash means "continue on next line"
/Users/yourName/Documents/arduino_sketchbook/library2

# make the correct paths for the libraries
INCLUDE_LIBRARIES = $(addprefix -I$(LIB_ROOT)/,$(LIBRARIES))
INCLUDE_LIBRARIES += $(addprefix -I,$(OTHER_LIBRARIES)) #<<<<<<<<<<<<<<<<<<<<<<<<<<<< add this line

# find .cpp files in libraries
CPP_LIBRARIES = $(foreach lib,$(LIBRARIES),$(wildcard $(LIB_ROOT)/$(lib)/*.cpp))
CPP_LIBRARIES += $(foreach lib,$(OTHER_LIBRARIES),$(wildcard $(lib)/*.cpp))  #<<<<<<<<<<<<<<<<<<<<<<<<<<<< add this line

# main file
TARGET = main

# find .c files in arduino directory
SRC = $(wildcard $(ARDUINO)/*.c)

# .cpp files from libraries and arduino directory
CXXSRC = $(wildcard $(ARDUINO)/*.cpp) $(CPP_LIBRARIES) $(SOURCES)
CXXSRC += $(wildcard $(OTHER_LIBRARIES)/*.cpp) #<<<<<<<<<<<<<<<<<<<<<<<<<<<< add this line


#.... rest of makefile...

You are right about ArduinoProgram, you don't really need it. It's only my preferred way of working.
Here's an example of main.cpp without the ArduinoProgram class:
Code:
#include "WProgram.h"

// Arduino doesn't know about new and delete, so let's teach 'm :
#include <stdlib.h> // for malloc and free
void* operator new(size_t size) { return malloc(size); }
void operator delete(void* ptr) { free(ptr); }
// from: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230935955


// you'll need to add function prototypes now...
void setup();
void loop();


// functions

void setup(){
Serial.begin(9600);
Serial.println("this a test without ArduinoProgram");
delay(100);
}

void loop(){
Serial.println("we are looping...");
delay(100);
}


int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}



I also have a question for you: What OS are you on and what board did you use to test?

Thanks for the feedback professor! Let me know if there is something else we can make better / easier to use...

best,
tim.
« Last Edit: November 17, 2011, 05:59:39 am by timKnapen » Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 225
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Tim - I'll try this out this evening.

I an running Snow Leopard (10.6.smiley-cool and loading to a Duemilanove.
Logged

France
Offline Offline
God Member
*****
Karma: 11
Posts: 647
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

Things seem a more complicated with Xcode 4.2 running on Lion 10.7.2.

I had a look at Ino: maybe some ideas to grab?

I'm using 2 boards: Arduino UNO and chipKIT UNO32, with only one IDE Mpide 0022.


Logged


Antwerp, Belgium
Offline Offline
Jr. Member
**
Karma: 2
Posts: 64
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Chaos & Avenue,

I have uploaded a new version of the XCode3.2 template to github. The adding of external libraries has been simplified a lot and it has (hopefully) clear instructions now in the README file. Get it here: https://github.com/timknapen/Arduino-With-XCode and let me know what you think :-)

I have also made a working XCode 4 project in Lion, but it seems that making templates is still a little too obscure. I haven't done too much research yet (just installed Lion today) so it might not be as hard as it looks.

At the moment, I think it might be better to not go for a project template, but do it the way openFrameworks does it: creating a blank project that has everything setup and just copy the whole project folder to start a new Arduino project in XCode 4

Thanks for the info Chaos, I will check the box on Duemilanove :-)

What are .ino files?

best,
tim.
Logged

Antwerp, Belgium
Offline Offline
Jr. Member
**
Karma: 2
Posts: 64
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've added a first version of an example XCode 4 project to the github repository.
Not a template, a blank project that you can copy and start from. When documentation on XCode 4 templates starts appearing I might have a go at it...

I'm not working in OSX Lion myself, so I'm going to wait for complaints/suggestions before I continue working on the XCode 4 project.

best,
tim.
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 225
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Very cool Tim - I followed the instructions in the new Readme and was able to compile a sketch with the Streaming and Flash libraries under Xcode 3.2.6!

Thanks!
Logged

France
Offline Offline
God Member
*****
Karma: 11
Posts: 647
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Congratulations Tim for your hard work!

Here's a minimal template for Xcode 4 you could use as inspiration.

http://blog.boreal-kiss.net/2011/03/11/a-minimal-project-template-for-xcode-4/
https://github.com/borealkiss/Minimal-Template

Best regards,
Logged


Antwerp, Belgium
Offline Offline
Jr. Member
**
Karma: 2
Posts: 64
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Avenue,

I had checked that blog post, but it doesn't really give a lot more information than what you can find in the templates that Apple provides with XCode.

For now, I'm going to wait until there is decent documentation on XCode4 templates. There are just too many things that we'd have to find by trial&error...

But if anyone is up for the task, don't let my laziness stop you! :-)

best,
tim.
Logged

Antwerp, Belgium
Offline Offline
Jr. Member
**
Karma: 2
Posts: 64
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Very cool Tim - I followed the instructions in the new Readme and was able to compile a sketch with the Streaming and Flash libraries under Xcode 3.2.6!

Thanks!


ah that's great news, I'm glad it's starting to become useable!

best,
tim.
Logged

France
Offline Offline
God Member
*****
Karma: 11
Posts: 647
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What we "need" is a command-line mode of the Arduino app that does the Arduino-style preprocessing on a set of .pde (or .ino) files.
Having to figure out exactly what it does (slightly differently) with each Arduino release is a pain, and makes implementing Arduino program builds in other IDEs an exercise in chasing not-fully-documented behaviors. :-(

I fully agree. Learning Makefile is just horrendous.

Another big benefit is to ensure consistency of the code between the Arduino IDE and alternative IDEs.

So a command-line mode of the Arduino app should be great!
Logged


France
Offline Offline
God Member
*****
Karma: 11
Posts: 647
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Some interesting info about command-line usage of Arduino.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I've just tried Tim's Xcode project on Xcode 4.2.1 running on Lion *.

Trying to compile it i get

Code:
make: *** No rule to make target `/Applications/Arduino.app/Contents/Resources/Java/hardware/Sanguino/cores/arduino/pins_arduino.o', needed by `bin/core.a'.  Stop.
Command make failed with exit code 2

Any ideas how to solve this issue?

Thanks

* EDIT: I'm using UNO.
Logged

Pages: 1 2 [3] 4 5 ... 46   Go Up
Jump to: