318: serial Arduino to Xcode with Swift

This is a test app that illustrates communication between Arduino and Xcode.

There is a framework called  ORSSerialPort that you can use with the Swift programming language.

I plan on sending X,Y coordinates from two accelerometers on a spring and attaching those values to two physics bodies in Xcode. Once I have the physics bodies, I can send their contact data ( point of contact, force, etc…) back to Arduino to trigger corresponding vibrations in a circular array of  mini motor discs to mimic the contact.



Screen Shot 2016-04-27 at 12.21.43 PM

one of the most important functions that took me a long time to figure out was ->

func serialPortWasOpened(serialPort: ORSSerialPort) {

        let descriptor = ORSSerialPacketDescriptor(prefixString: “!pos”, suffixString: “;”, maximumPacketLength: 8, userInfo: nil)



listeningForPacketsMatchingDescriptor is the part that trims the incoming data where it is supposed to trim—in the Arduino code, you encapsulate the value you want to send between the prefixString: “!pos” and suffixString: “;”.

xVal is the value read from the potentiometer

Screen Shot 2016-04-27 at 12.25.50 PM


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s