Arduino to Mac OS X Serial Communication

Uncategorizedon June 1st, 2009

I ran into a snag when trying to get an xcode project to talk to an Arduino in April. After a bit of researching, I finally got things working with AMSerialPort from Andreas Mayer. I had to tweak it a bit…the method to change the baud rate didn’t work at first, but it’s fixed now. Also, the part of AMSerialPort that waits in the background thread for incoming data was modified a bit to play nice with Arduino serial messages. I re-packaged everything into a new Xcode project with a simple interface that let’s a user select an attached serial device and then send messages to it as well. My code has the incoming messages just go straight to the console instead of being displayed in the view. I could have done otherwise, but each implementation of this will require vastly different interfaces when completed. I know that I will never need to display the incoming messages on the screen, so I didn’t bother.

The modification the background-thread-waiting is by my design. It waits for a newline character, or more specifically, a serial message that is sent with

Serial.println()

So Serial.print() can be used several times without the Xcode project reporting any incoming data. What it is really doing is storing up the data until a newline character. Just end your bout of serial messages with a Serial.println() for the message to come through to the console. If you’d prefer every message to come through, just always use Serial.println().

The project is hosted here on Google Code.