Arduino, Xcode, Mac OS application.

Discussion in 'Mac Programming' started by Freez, Feb 9, 2011.

  1. Freez, Feb 9, 2011
    Last edited by a moderator: Feb 9, 2011

    Freez macrumors newbie

    Joined:
    Feb 9, 2011
    #1
    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.
     
  2. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
    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
     
  3. Freez thread starter macrumors newbie

    Joined:
    Feb 9, 2011
    #3
    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.
     
  4. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #4
    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.
     
  5. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #5
    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
     
  6. Freez thread starter macrumors newbie

    Joined:
    Feb 9, 2011
    #6
    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.
     
  7. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #7
    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)


    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.
     
  8. Freez thread starter macrumors newbie

    Joined:
    Feb 9, 2011
    #8
    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.
     
  9. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #9
    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
     
  10. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #10
    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.

    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.

    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.
     
  11. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #11
    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
     
  12. Freez thread starter macrumors newbie

    Joined:
    Feb 9, 2011
    #12
    Bliss

    I guess that I am in over my head here.

    Thanks for the effort.
     
  13. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #13
    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
     
  14. Freez thread starter macrumors newbie

    Joined:
    Feb 9, 2011
    #14
    Yes

    Here is not the place for me.

    Thanks for your motivation.

    Good Day.
     

Share This Page