3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Controlling an Arduino with Cocoa (Mac OS X) or C# (Windows)

Step 6How this works

In the cocoa application there are 2 methods, ledOn & ledOff, that are activated by the pushing of the buttons. Within each of those methods there is a line of code that looks like this:
popen("echo i > /dev/tty.usbserial-A6006hmi", "r");
This code sends the letter i to the Serial port: /dev/tty.usbserial-A6006hmi which is received by the arduino

With in the arduino program there is the code:
if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
    if(incomingByte == 105){
      digitalWrite(ledPin, HIGH);
    }
    else if(incomingByte == 111){
      digitalWrite(ledPin, LOW);
    }
This takes the decimal value from the sent character on the serial port connection. If it is a i then it turns the led on if it is a o it turns it off. 

For the Arduino to receive the signal from the cocoa app the serial monitor in the Arduino IDE needs to be open.

If this doesn't make sense it's fine. This is kind of a reference if you want to expand the functionality of the program.

« Previous StepDownload PDFView All StepsNext Step »
1 comment
Nov 9, 2009. 4:22 PMbeak90 says:
I wrote up a wiki page about how to do this a while ago located here: http://www.arduino.cc/playground/Interfacing/Cocoa
It looks like its been changed a little since I wrote it, but I wrote up the part on using Popen().

Also, you have to change the part in the code after the tty.usbserial to whatever port your Arduino is on. So you have to look in the Arduino program under Tools/Serial Port then replace the "/dev/tty.usbserial-A6006hmi" thats in this code to the selected serial port in the Arduino program. Read my post for more info about this.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
42
Followers
15
Author:computergeek