Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Freez

macrumors newbie
Original poster
Feb 9, 2011
15
0
This is a project for myself. I am happy to show or share any code. My goal is to use Xcode to make a Mac OS application to view and save temperature and light data constantly from my Arduino Duemilanove.

Temperature Sensor: TMP36
Connected to Analog Pin 1

Light Sensor: Photo Resistor and 10k Ohm resistor
Connected to Analog Pin 0


Xcode Version 3.2.4 (1708)
Arduino 0022
Mac 10.6.6



My current Arduino processing code:

CODE

Code:
int temperaturePin = 1;
int lightPin = 0;


void setup()
{
  Serial.begin(9600);
}

void loop ()
{
  int lightLevel = analogRead(lightPin);
  lightLevel = map(lightLevel, 0, 900, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);
  
  float temperatureArduino = getVoltage(temperaturePin);
  temperatureArduino = (((temperatureArduino - .5) * 100)* 1.8) + 32;
  
  Serial.print(lightLevel);
  Serial.println();
  
  delay(1000);

  Serial.print(temperatureArduino);
  Serial.println();
}

float getVoltage(int pin)
{
  return (analogRead(pin) * .004882814);
}
/CODE

Example of Serial Monitor results:

88
44.83
87
44.83
88
44.83
89
46.59
88
45.71
86
44.83
86
45.71
87
45.71
88
44.83
89
44.83
88
44.83


Yes it is that (44F) cold in my house.

Ok, I can use Terminal and cat to save a text file of the serial output:

cat /dev/cu.usbserial-A700dXPO > ArduinoStream.txt

The above command makes a text file in my home folder that will capture the temperature and light level constantly and stop recording when I quit the terminal window.


All that is fun but what I need some advice on how to implement a Xcode project that would allow me to practice the most advanced libraries and get a chance to add more sensing devices and control devices in the future.

If I could start with an application window that just allowed me to look at the Temperature and Light serial output. I will move toward using Xcode to upload the code to the Arduino, but for now I just want to view and store the data coming from my Arduino in a simple Mac OS window.

I can make the pretty little window but as far as the Xcoding I am a lost soul with too many roads toward the light.

I would like to use Core Data. Can I just make a data model and then link to my window?

Any help or advice is appreciated.
 
Last edited by a moderator:

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
Please use CODE tags around code and output in your post. It makes it far easier to read.

Just one comment. You may want to make the Arduino output a bit easier for the Mac to parse. As it stands it is human readable, but that is not always the best thing for computers to interpret.

Maybe adopt a plist compatible XML format?

B
 

Freez

macrumors newbie
Original poster
Feb 9, 2011
15
0
Thanks for protocol.

More to the issue I am having.

I can make the Arduino give any output.

The real issue is that I do not know the basics about coding.

Do I make a data model for Temperature data then how do I get the output to the data model?

Thanks.
 

lloyddean

macrumors 65816
May 10, 2009
1,047
19
Des Moines, WA
You'll need to communicate over a serial port from within your application. There are several third party libraries for doing this including SerialManager.

SerialManager contains a working Cocoa project for I/O to a view.
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
Divide and conquer.

Work on the serial port comms bit. Get that working, even if it only replaces your current Terminal approach.

Work on the protocol bit (Arduino code and Mac OS X controller/parser) (*)

Work on the Core Data bit (there are a number of resoruces to mine for this, including http://www.cocoadevcentral.com/articles/000085.php

Work on the UI, which you seem comfortable with.

(*) I would also recommend that the Arduino only send data when it is requested, even if that request is only receipt of a line feed over the serial lines.

B
 

Freez

macrumors newbie
Original poster
Feb 9, 2011
15
0
Small, baby steps.

Yes, I will invest some time on learning. I can make a CoreData simple program but to attach the serial output to the data is my stopping point. The idea of only getting data when requested is clearly better. I am lost because there are lots of routes to capture serial data and I just want to make a simple App that uses optimized libraries. Thanks for your patience.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,750
8,422
A sea of green
I can make the pretty little window but as far as the Xcoding I am a lost soul with too many roads toward the light.

If you don't know any programming languages that run on the Mac, you'll have to learn one.

Or it's possible that something like Processing would work:
http://processing.org/

The Arduino sketchbook is based on Wiring, which is related to Processing:
http://en.wikipedia.org/wiki/Processing_(programming_language)


I would like to use Core Data. Can I just make a data model and then link to my window?
Only if elves magically write all the code.

What do you think Core Data is? It's not a DB forms generator. If you haven't read any intros or summaries of what Core Data is, you should do that first.
 

Freez

macrumors newbie
Original poster
Feb 9, 2011
15
0
Darn!

Chown33 thanks for the time it took to read and then post a reply.

No programming language is an issue. I am more of a get things done type of person and learning an entire language has always seemed more esoteric than focus on the specific issue.

I just need some help getting the data from arduino hooked up to an app. Sure I can learn the entire language, or I could learn to express that I can get the Arduino with Processing to send information, in any format, great.

I can make a Core Data app, great.

Any specific advice or specific code examples of a Mac OS X app that will read and save the data coming from Arduino that has been pre-programmed.

And if YOU were going to start from scratch what data structure would use and what specific serial communication protocol do you recommend.

Thanks for comments.
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
I just need some help getting the data from arduino hooked up to an app.
It sure doesn't sound that way. It sounds like you don't have a plan of attack, and that is (IMHO) deadly.

I have no direct Arduino experience, but I have done a lot of work in this space where some bits of code run on a microcontroller/DSP and other bits run on a PC. Planning it all out, and defining the interface between the two sets of code is usually what drives these projects.

I am certainly not implying that you need to be a Cocoa/Objective-C expert to get this done, but you do need to know some about how the individual bits work before you try to put them together. As chown33 points out you don't seem to have that well defined in your mind.

Once you get a building block that takes you from serial communication to variables, dealing with Core Data is no different than a string of random numbers from a text file. So if you think the Core Data bit is your problem, focus on that. If you think the Serial Communications part is your problem focus on that using the sample code provided in the link earlier, ...

B
 

chown33

Moderator
Staff member
Aug 9, 2009
10,750
8,422
A sea of green
No programming language is an issue. I am more of a get things done type of person and learning an entire language has always seemed more esoteric than focus on the specific issue.

I just need some help getting the data from arduino hooked up to an app. Sure I can learn the entire language, or I could learn to express that I can get the Arduino with Processing to send information, in any format, great.
If that's your approach, then you need to focus on possibilities that don't involve any programming languages. I'm not sure what that would be, or if such a thing exists, but you should probably start by searching the processing.org site for Arduino references, or any of various Arduino sites for Processing references. Befriend google.

Any specific advice or specific code examples of a Mac OS X app that will read and save the data coming from Arduino that has been pre-programmed.
If you're going to hook up Arduino to Processing, you should probably focus on websites that specialize in Arduino and/or Processing.

Another possibility is to scour Arduino sites for information related to serial-port communication on Mac OS X, then use whatever Mac-based tool that article uses.

Pick any two of the things (Arduino, serial, Processing, Mac OS X) and see what you find about the combination.

I don't know of any apps or tools that would perform the desired serial-port communication, yet which don't involve programming.

And if YOU were going to start from scratch what data structure would use and what specific serial communication protocol do you recommend.
Not sure what you mean by "from scratch". I already know several programming languages, and am familiar with serial ports. What I would do hardly seems relevant to what you would do. The data structure seems like the least of the concerns. In any case, you haven't said what you intend to do with the data, so advising on a data structure would just be guessing.

If by "from scratch" you mean starting from the same position you're in, I don't think you've described your experience or skills well enough for me to say. I'd have to guess at what you know and don't know, your experience in data design, etc. The fact that you don't know a programming language means you'd either have to limit yourself to things that don't require a programming language, or you'd have to learn a programming language. On the latter, almost anything that runs on the Mac would suffice: they all have access to serial-port devices in some way. I could do what you're asking using a shell script if I had to: it's just a question of complexity.
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
No programming language is an issue. I am more of a get things done type of person and learning an entire language has always seemed more esoteric than focus on the specific issue.

If that's your approach, then you need to focus on possibilities that don't involve any programming languages.

I interpreted that quite differently from you chown33.

I took it "programming language is not an issue" i.e. Freez didn't see any programming language as a barrier since Freez would only learn as much as needed to get the immediate task at hand done. You seem to have interpreted it as "the fact that I don't know a programming language is an issue" which seems incompatible with the rest of Freez's posts.

B
 

Freez

macrumors newbie
Original poster
Feb 9, 2011
15
0
Bliss

I guess that I am in over my head here.

Thanks for the effort.
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
I guess that I am in over my head here.
Just like anything else. Plan your attack and chip at it step by step.

You don't climb Everest on a whim in a day. Plan your route and take one step at a time and you'll get there soon enough.

B
 

Freez

macrumors newbie
Original poster
Feb 9, 2011
15
0
Yes

Here is not the place for me.

Thanks for your motivation.

Good Day.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.