Teensy 3.2 with WIZ820io and OSC

Status
Not open for further replies.

nchandol

Member
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:

View attachment Wavefunction_OSC_software.zip

And here are the pictures of my connections:

IMG_6211.jpgIMG_6209.jpgIMG_6208.jpgIMG_6212.jpg

Thank you for your time :)
 
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);

}
 

Attachments

  • settings.png
    settings.png
    71.3 KB · Views: 86
Last edited:
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

odot.jpg

<pre><code>
----------begin_max5_patcher----------
398.3ocqS00aBBCE8Y3WQSydjwnnB39qrXLE3FWMPgzVbXL9ee8CXtMISlau
Ty8zi2Cmy81S9d37ldPhQOidA44cx2yyBY.7Fp8v0z9hJpzRCy6pyAANvcEq
zB1ju+w3QLMCFuBTV9jAvVpp3UFe2VATnb5kRBWEfVkDFoOiLmwwgQnMWZSS
mZrOwezGAsFTfXKvo4Uf4tng6jpiN.73mhqApisfSR8EHbNkuCi1XXb122bD
LWuCuoc5XyUPux49vFYQdGuTq904xxk2WvPVrzjIoKlYxLS2eeNuFjR5N3Jq
+Di21oPOPlv3YS563a460qrKDo2v1jegs+OG1cksRfWhHqiCIIYgQgwnrrr0
SD.j6cxq+QadxpaM5mXw+SF09mvUL92efaE1f+U2Ka5DEiY1vKZzEoKAohwo
JVC+SbxbblLemqNYyPGyqn+rPiM4GUhbsRtjj11d.DxA1VQzaL6aDlxz.aIi
6JWXKEvA1H+DKBUnG4J87tS3FX8ItkDbcSIH3cL6FhuQ4y9uCTpWIQA
-----------end_max5_patcher-----------
</code></pre>
 
Last edited:
Status
Not open for further replies.
Back
Top