Communicating with custom USB hardware

What is the status between Unity3D and custom USB Hardware input devices (eg.arduino,phidget ) on the Mac platform? From the various forum posts it appears to not work.

You can use the System.IO.Ports.SerialPort class for handling serial input. I recently made a blogpost on connecting an Arduino and Unity.

You can find it here

Following show an excerpt from my post `

using UnityEngine;

using System.Collections;

using System.IO.Ports;

public class NewBehaviourScript : MonoBehaviour {

SerialPort serial;  
void Start () {
    serial = new SerialPort("COM3", 9600);
}   

void Update () {
    Debug.Log(serial.ReadLine());
}

} `

I have had a play around in the release version of Unity 3.0 today and it seems that the problem with System.IO.Ports.SerialPort and the OS X environment still exists. What I have been doing as a work around on projects is to use an intermediary to gather the serial data from the arduino then send the data to Unity using OSC. (I am using max/msp for this but processing or PD should be suitable free alternatives)

as an aside: As far as I can tell the issue with System.IO.Ports.SerialPort is a mono rather than Unity issue, though I thought I read somewhere that it was fixed in mono 2.6 but this does not seem to have carried through to Unity's version of mono for 3.0

I can confirm that the serial port code for mono on Mac OS X is still broken on Unity 3.1 as of today. I did manage to bring it up yesterday at Unite. There have been at least 2 bug reports filed that I know of. This will hold up OSC, Arduino and other control experiments on Mac until it is fixed.

Here's the fix.

Going back through the forums I found something I had missed. Someone got it working on Mac with 3.0 (and I just got it working with 3.1) with this tip:

"I just changed line 2 of UDPPacketIO.cs to remove the .Ports from the end so that it just says using System.IO; and it seems to work."

Someone please try this and confirm that it works for them as well.

I know this quite old, but for anyone else who stumbles across this page, there is now a plugin that allows you to connect to the Arduino in Unity3D =) It’s called Uniduino, check out this site for more info: www.uniduino.com