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)

Controlling an Arduino with Cocoa (Mac OS X) or C# (Windows)
 No I'm not talking about controlling an Arduino with a chocolate bar or cocoa powder. I'm talking about the programming language, Objective-C. So what is cocoa? Cocoa is a set of frameworks written in the programming language of Objective-C for Mac OS X. No there isn't a test at the steps so you don't have to worry about remembering all of this. Just know that when I talk about cocoa I'm not trying to make you hungry.

 Now I understand some people are probably wondering why you would want to use Cocoa instead of Processing, the reason I have is: if you use Cocoa over Processing you can have a full Computer Application(e.g. Safari, Mail, iCal) that can have a physical output. (e.g. Lights, motors, servos)

So Have Fun, Work hard, & Play nice! Please ask any questions you have!

Notes:
- This will only work for Mac OS X & Windows
- The source code is attached below.
- If you don't want to code the app, or you don't have xcode, you can find the app for OS X in the source below under: 'Build -> Debug'
- The instructions for Windows are in step 7
 
Remove these adsRemove these ads by Signing Up
 

Step 1Stuff you need:

Stuff you need:
Hardware:
- Arduino
- A-B USB Cable
- Computer with Mac OS X

Software:
- Xcode
- Arduino IDE
« Previous StepDownload PDFView All StepsNext Step »
23 comments
May 8, 2012. 1:18 AMeloya says:
Hello, well i have a problem, when I click in the button ON it doesnt turn on the led, so i think the problem is in the Baud because it need to be in 9600, so I want to know if you know how to change the Baud in the popen() function.
Oct 17, 2011. 3:01 PMA-Nony-Mus says:
I'm trying to modify this for picaxe (using the same code for cocoa), and I keep getting an error message in Xcode: sh: /dev/tty.usbserial-000013FD: Resource busy. Any idea what I should do?
Jun 24, 2011. 4:53 AMudawatabhimanyu4 says:
Very informative. I find "Processing" very interesting in interfacing and controlling the serial port of an Arduino by Mac.
Oct 10, 2010. 9:50 PMkevinfilteau says:
I pass through your article when I was seeking a simple way to communicate with my Arduino from the Internet. After many days of unsecessful reseach, I decided to make one application of my own.

So I made up a Mac application that can relay strings send from the Internet to a connected serial device and vice versa. I now think I must share because this app is very useful for me. So maybe you'll find that too!
May 11, 2011. 3:10 AMrom_ says:
interesting, I'm sure I'll find a use for this. Thanks
May 11, 2011. 3:09 AMrom_ says:
Greatly appreciated.
My Arduino is in the post, can't wait to get started.
Feb 7, 2011. 2:46 AMmelonfullofrainbowdinos says:
dude i love you
Jun 22, 2010. 6:41 PMjsklein says:
Thanks! It worked great but I had to change the serial port number from the one you gave (A6006hmi) to my Arduino's own serial port number. It took my a while so maybe you could write in that you have to use your serial port number and not the one you give. Thanks again!
May 29, 2010. 7:33 AMD5quar3 says:
 does it matter what version OS X i have
Feb 8, 2010. 11:11 AMadamohern says:
Thanks for the great info! Is it just as easy to get info back from the Arduino to display on the screen? I want to make a bicycle computer that displays all of its info in Mac OS X... does that seem like something that would be relatively easy using this method?
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.
Nov 5, 2009. 6:44 PMandrew101 says:
cool code, only thing is, when i use the serial monitor to send an i or o to the arduino it works, but the program wont...

i needed to change the com port to com4 because thats what my arduino uses, and when i press on or off the RX light goes on for a short time but it doesnt trigger...

any ideas?
Nov 5, 2009. 6:46 PMandrew101 says:
oh, nevermind, after a quick arduino reset it recognizes it. nice :)
Oct 19, 2009. 6:42 PMRadiosity says:
  Very nice! I'm going to try this next chance I get. Thanks!
Oct 21, 2009. 9:37 PMRadiosity says:
I just tried this and it worked great, but I just have one suggestion:

In your code you used the serial port "/dev/tty.usbserialA6006hmi", but this is dependent on which computer you are using. In my case I had to replace both instances of that with "/dev/tty.usbserialA4001KMJ" (which was the port I had selected in the Arduino IDE) in order for my application to properly send data to my arduino. I suggest to add a step in which you find out which serial port you are using and add it into the code. (Just to prevent any confusion for somebody else reading this instructable)

Other than that great instructable and you have my vote!
Oct 19, 2009. 8:18 PMguschabal says:
Thanks men! I write a similar program using WPF Application and your code for C#(Windows)!

Thanks a lot!!
Oct 15, 2009. 10:37 AMjeff-o says:
Very neat.  How would you go about building a standaloneapplication that interfaces to the Arduino, but doesn't require theArduino IDE to be running?

Or is that the subject for a whole Instructable in itself?
Oct 16, 2009. 5:23 AMjeff-o says:
OS X.  Not that I'm much of a programmer - I just thought it would be nice to build matching hardware and software.  Could it be a driver issue?  As in, a driver that is only loaded when the IDE is running?
Oct 19, 2009. 5:51 AMjeff-o says:
Ah, well, maybe that will be fixed someday if enough people complain.  ;)

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!
43
Followers
15
Author:computergeek