Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Teensy 3.2 with WIZ820io and OSC

  1. #1
    Junior Member
    Join Date
    Aug 2015
    Location
    Montreal
    Posts
    6

    Teensy 3.2 with WIZ820io and OSC

    Hi all,

    I would like to use a few teensys with OSC.

    With my current setup, the helpful guidelines, and the attached code, I am able to receive OSC messages on my laptop from the Teensy. But, after fiddling around and looking at the forums, I am still not able to receive OSC messages from my max/patch to my Teensy 3.2(although the IP and port are a match).

    Here is my current setup:

    I have a USB to Ethernet adaptor (from apple) that connects my WIZ820io ethernet module with my computer. I successfully wired the WIZ820io ethernet module with my Teensy 3.2 on a breadboard, according to the guideline on Teensy's website. The teensy is powered through USB and the ethernet module with an external power supply. The grounds are connected.

    I have attached a few images and the code I am currently using to test, in case it is of help.
    I would really appreciate it if anybody has any insights or solutions for the problem I am currently facing.

    Here is the code I am using for the Teensy:

    Code:
    #include <OSCMessage.h>
    #include <Ethernet.h>
    #include <EthernetUdp.h>
    #include <SPI.h>    
    #include <OSCMessage.h>
    #include <OSCBundle.h>
    #include <OSCBoards.h>
    
    #pragma GCC diagnostic ignored "-Wwrite-strings"
    /*******************SETUP OSC********************/
    EthernetUDP Udp;
    //255.255.255.255 is the IP to broadcast to all devices in the network
    IPAddress ip(10, 0, 1, 2);
    IPAddress outIp(10, 0, 1, 1); //destination IP
    const unsigned int outPort = 6789;
    const unsigned int inPort  = 8979;
    byte mac[]                 = { 0x04, 0xE9, 0xE5, 0x03, 0x94, 0x5E }; // you can find this written on the board of some Arduino Ethernets or shields, for Teensy we have custom made code - implement it
    
    void setup() {
      Serial.begin(115200);
      Ethernet.begin(mac,ip);
      Udp.begin(inPort);
    }
    
    
    void loop(){
      //the message wants an OSC address as first argument
      sendOSCMessage("/speed", 2, outIp, outPort);
      OSCMsgReceive();
    }
    
    void sendOSCMessage(char *addr_pattern, int mtr_id, IPAddress ip_, int port_){
    
      OSCMessage msg_recv(addr_pattern);
      msg_recv.add((int32_t)mtr_id);
      msg_recv.add((int32_t)analogRead(A14));
      
      Udp.beginPacket(ip_, port_);
      msg_recv.send(Udp); // send the bytes to the SLIP stream
      Udp.endPacket(); // mark the end of the OSC Packet
      msg_recv.empty(); // free space occupied by message
      
      }
    
    void OSCMsgReceive(){
       OSCBundle bundleIN;
       int size;
    
       //Serial.println(Udp.parsePacket());
       if( (size = Udp.parsePacket())>0)
       {
         while(size--)
           bundleIN.fill(Udp.read());
    
          if(!bundleIN.hasError())
            bundleIN.route("/input", inputfunction);
       }
    }
    
    void inputfunction(OSCMessage &msg, int addrOffset){
      int value = msg.getInt(0);
      Serial.print("Value = : ");
      Serial.println(value);
    }
    Here is the max patch:

    Wavefunction_OSC_software.zip

    And here are the pictures of my connections:

    Click image for larger version. 

Name:	IMG_6211.jpg 
Views:	120 
Size:	109.5 KB 
ID:	8878Click image for larger version. 

Name:	IMG_6209.jpg 
Views:	58 
Size:	128.2 KB 
ID:	8879Click image for larger version. 

Name:	IMG_6208.jpg 
Views:	114 
Size:	94.1 KB 
ID:	8880Click image for larger version. 

Name:	IMG_6212.jpg 
Views:	44 
Size:	111.6 KB 
ID:	8881

    Thank you for your time

  2. #2
    Junior Member
    Join Date
    Aug 2015
    Location
    Montreal
    Posts
    6
    Hi all again

    So here was my answer to my beginers problem:

    I added in my network settings a router IP and after that it worked like a charm!


    Here is the slightly modified sample code that I used to receive the messages:

    Code:
    #include <Ethernet.h>
    #include <EthernetUdp.h>
    #include <SPI.h>    
    
    #include <OSCBundle.h>
    #include <OSCBoards.h>
    
    EthernetUDP Udp;
    IPAddress ip(10, 0, 1, 253);
    const unsigned int inPort  = 8988;
    const unsigned int destPort = 6789;
    byte mac[]                 = { 0x04, 0xE9, 0xE5, 0x03, 0x94, 0x5E }; // you can find this written on the board of some Arduino Ethernets or shields, for Teensy we have custom made code - implement it
    int inputState = 0;
    
    void setup() {
      //setup ethernet part
      Ethernet.begin(mac,ip);
      
    
      delay(1000);
      Serial.begin(9600);
      Serial.println("Receive OSC");
    
      if(Udp.begin(inPort)){
        Serial.println("Succesful connection");
      }
      else{
        Serial.println("there are no sockets available to use");
        }
    
    }
    
    //reads and dispatches the incoming message
    void loop(){ 
       OSCBundle bundleIN;
       int size;
     
       if( (size = Udp.parsePacket())>0)
       {
         while(size--)
           bundleIN.fill(Udp.read());
    
          if(!bundleIN.hasError())
            bundleIN.route("/input", InputReceived);
      }
    }
    
    void InputReceived(OSCMessage &msg, int addrOffset){
      inputState =  msg.getInt(0);
      //OSCMessage msgOUT("/input");
      Serial.print("Input received: "); Serial.println(inputState);
    
    }
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	settings.png 
Views:	24 
Size:	71.3 KB 
ID:	8884  
    Last edited by nchandol; 11-25-2016 at 05:37 PM.

  3. #3
    Junior Member
    Join Date
    Jan 2018
    Posts
    6
    Just a quick update on this. First of all thanks @nchandol for organizing your information so well.

    It appears that some devices/software will accept OSC messages sent directly from [udpsend] in max/msp and some will not. As the old [OpenSourceControl] object which nchandol was using is 32bit you'll need to use the CNMAT-odot externals in 64bit. There may be better ways but [o.oscbundle] is working for me. There's at least one little mistake in nchandols sketch (the .hasError() part is missing brackets) but it will work (tested on TeensyLC with an aliexpress W5500 board). Here's a current (feb 2019) link to the odot externals, a screenshot and my max patch.

    https://cnmat.berkeley.edu/downloads
    https://github.com/CNMAT/CNMAT-odot

    Name:  odot.jpg
Views: 39
Size:  18.5 KB

    <pre><code>
    ----------begin_max5_patcher----------
    398.3ocqS00aBBCE8Y3WQSydjwnnB39qrXLE3FWMPgzVbXL9ee 8CXtMISlau
    Ty8zi2Cmy81S9d37ldPhQOidA44cx2yyBY.7Fp8v0z9hJpzRCy 6pyAANvcEq
    zB1ju+w3QLMCFuBTV9jAvVpp3UFe2VATnb5kRBWEfVkDFoOiLm wwgQnMWZSS
    mZrOwezGAsFTfXKvo4Uf4tng6jpiN.73mhqApisfSR8EHbNkuC i1XXb122bD
    LWuCuoc5XyUPux49vFYQdGuTq904xxk2WvPVrzjIoKlYxLS2ee NuFjR5N3Jq
    +Di21oPOPlv3YS563a460qrKDo2v1jegs+OG1cksRfWhHqiCII YgQgwnrrr0
    SD.j6cxq+QadxpaM5mXw+SF09mvUL92efaE1f+U2Ka5DEiY1vK ZzEoKAohwo
    JVC+SbxbblLemqNYyPGyqn+rPiM4GUhbsRtjj11d.DxA1VQzaL 6aDlxz.aIi
    6JWXKEvA1H+DKBUnG4J87tS3FX8ItkDbcSIH3cL6FhuQ4y9uCT pWIQA
    -----------end_max5_patcher-----------
    </code></pre>
    Last edited by chaosmoon; 02-10-2019 at 10:30 PM. Reason: found [o.oscbundle] simpler to use than [o.compose]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •