Latest Updates: oscP5 RSS

  • Unity + Processing Demo

    Ellen 10:11 on July 2, 2012 | 4 Permalink | Reply
    Tags: osc, oscP5, ,

    Test your Unity project with the Processing Osc Demo. Send your events through the Processing app and see them appear in the Unity project. There is also a timer in Processing sending events at all time changing the width of a cube in Unity. Download the Unity OSC example here.

  • Unity + Processing + Arduino

    Ellen 10:32 on May 31, 2012 | 17 Permalink | Reply
    Tags: , , oscP5, ,

    I did a test connecting Arduino and Unity with the help of Processing and a Open Sound Control library. When I am pushing the Flexi Force sensor the values affect a cube within Unity. To get this setup do the following:

    Load the Standard Firmdata on to your Arduino. Check out a full Arduino + Processing tutorial to get the setup.

    Download the oscP5 processing library and put it in your Processing sketch folder in the folder libraries.

    Initialize oscP5 library and broadcast data to port 12000. The port Unity will listen to.
    Add the remote location to listen to on port 3200. If Unity would broadcast event in this example, the broadcast port would be set to 3200. Initialise Arduino to be used later on.

    oscP5 = new OscP5(this,12000);
      myRemoteLocation = new NetAddress("",3200);
      arduino = new Arduino(this, Arduino.list()[0], 57600);

    In the draw function we read the analoge pin 0 to get sensor values from the Flexi Force sensor. Set the OSC message to flexiforce. Unity will listen to this label. Add the message of the sensor value into the osc message with add method. This method can take numbers, strings and byte data.

    float flexiforceSensor = arduino.analogRead(0);
    OscMessage oscMess = new OscMessage("/flexiforce");

    oscP5.send(oscMess, myRemoteLocation);

    The entire Processing sketch can be seen here.

    In Unity you can import the Osc.cs and UDPPacketIO.cs to broadcast and listen to UDP data.

    Set up the corresponding host and ports in your Unity script.

    public var OSCHost : String = "";
    public var SendToPort : int = 3200;
    public var ListenerPort : int = 12000;

    Import the UDPPacketIO and Osc components and feed in the host and ports. Add your specific label of your osc message and what method to call when receiving this event from Processing.

    var udp : UDPPacketIO = GetComponent("UDPPacketIO");
    udp.init(OSCHost, SendToPort, ListenerPort);
    handler = GetComponent("Osc");
    handler.SetAddressHandler("/flexiforce", AffectObject);

    In the receiving method you can print out the label and message values. In this case the sensor value from the Flexi Force. The cube will change width when getting a new value from Processing.

    public function AffectObject(oscMessage : OscMessage) : void
            Debug.Log("Event name: " + Osc.OscMessageToString(oscMessage));
            Debug.Log("Event data: " + oscMessage.Values[0]);
            var myCube = GameObject.Find("Cube");
            var boxWidth:int = 8 - ( oscMessage.Values[0]);
            myCube.transform.localScale = Vector3(boxWidth,5,5);

compose new post
next post/next comment
previous post/previous comment
show/hide comments
go to top