Arduino to Computer using OSC // Help Wanted

I am looking for a way to use OSC to communicate with my Arduino from my computer, in both directions. Every example Processing/Arduino sketch combo I have tried does not work out of the box.

I have used Arduino many times, as well as Processing, and am getting very stuck. Please help.

I want to do it in the easiest way possible. Just get the simplest message to send. I am using this library called OSCuino: http://cnmat.berkeley.edu/oscuino

Let’s start with sending information from my Arduino to my computer…

I am using this great network OSC sniffer provided here to watch for OSC messages on the appropriate port. I am watching the correct IP address, all the relevant ports, and am not seeing any messages. What am I doing wrong??

I have this code on my Arduino:

/*
    Make an OSC message and send it over UDP

    Adrian Freed
 */
#include <OSCMessage.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>
#include <OSCMessage.h>

EthernetUDP Udp;

//the Arduino's IP
IPAddress ip(128, 32, 122, 252);
//destination IP
IPAddress outIp(169, 254, 166, 0);
const unsigned int outPort = 9999;

byte mac[] = {
  0x90, 0xA2, 0xDA, 0x0F, 0x2B, 0X1E
};   // you can find this written on the board of some Arduino Ethernets or shields

float vvv = 0.0;

void setup() {
  Ethernet.begin(mac, ip);
  Udp.begin(8888);

}


void loop() {
  //the message wants an OSC address as first argument
  OSCMessage msg("/analog/");
  msg.add(vvv);

  Udp.beginPacket(outIp, outPort);
  msg.send(Udp); // send the bytes to the SLIP stream
  Udp.endPacket(); // mark the end of the OSC Packet
  msg.empty(); // free space occupied by message

  delay(20);

  vvv = vvv + 0.1;
}

I am looking for a way to use OSC to communicate with my Arduino from my computer

Then why are you using an Ethernet shield and UDP packets? That implies that it is NOT your computer you want to send the messages to.

  Udp.beginPacket(outIp, outPort);
  msg.send(Udp); // send the bytes to the SLIP stream
  Udp.endPacket(); // mark the end of the OSC Packet
  msg.empty(); // free space occupied by message

The UDP packet is send when Udp.endPacket() is called. Why are you calling msg.send() in between?

Hi Sensebellum

From the library page, looks like OSCuino can use different transport layers, including UDP. So, I assume your PC and your Arduino (with Ethernet shield) are on the same local network? And it looks like you are using one of the example programs from the OSCuino library?

//the Arduino's IP
IPAddress ip(128, 32, 122, 252);

This is the same as the IP address in the example program. I guess you should allocate a static IP address to your Arduino on your router and then put that into your code.

//destination IP
IPAddress outIp(169, 254, 166, 0);

This should be the IP address of your PC. Are you sure it is right? I've usually seen "x.x.x.0" used as the gateway address on a network.

Regards

Ray

I just ran that little sketch and it works fine and sends an OSC messages and these can be observed in the OSC data monitor.
However as Hackscribble has correctly noted the destination IP “outIP” does not look OK.

Also, there is a double #include<OSCmessage.h> in the sketch.

What hardware are you running this on ?

Thanks for the replies.

@Headroom, very nice to hear it may work! Where do you find your iP address listed? Are you on a Mac?

I want to use this with my Mac BookPro. It is the new one with the dual thunderbolts, etc.

The idea is that I like OSC way more than serial. I also plan to have many Arduino Projects connected to a network so that they can all send messages back and forth.

I thought the IpOut was good to go. On a mac, you go System Preferences -> Network -> Thunderbolt/Ethernet. It then states the ip address for that machine. This is how I look it up for say TouchOSC. I will admit I have never used an Arduino with an Ethernet shield. Is this the proper way to look it up?

Double include is probably a typo.

I think we're really close.

Yes, I am on a 27" mid 2010 core i7 iMac, so no Thunderbolt for me :wink:

The way you describe looking up the Ethernet Address sounds correct.

How do you have connected your Arduino to the macbook ?
Is it connected directly from your Ethernet Shiled to your macbook or do you have the Ethernet shield connected to a router that is then also connected to your macbook ?

Some Ethernet shields have the MAC address d printed on the bottom. If thats the case for your Ethernet shield use that one, otherwise you are fine with the one in your sketch.

For now I’d remove the IP parameter from the the Ethernet.begin so it reads:
Ethernet.begin(mac);

This will allow the macbook or router to assign an IP address per DHCP to the Arduino. For sending messages from the Arduino to your macbook, the Arduino’s IP won’t matter. Here’s an updated sketch that will print the IP the Arduino received per DHCP.
The delay(5000); is there so I have enough time to turn on the serial monitor for my Teensy boards.

In general if you are going to use several Arduino’s I’d urge you to look at the Teensy boards.
I’d use either a Teensy 3.1 or Teensy LC. Both of these are much smaller, much less expensive and much more powerful than your regular Arduino Uno or Mega.

For Ethernet I’d use a WIZ820io Embedded Ethernet Module in conjunction with the Teensy WIZ820io adapter

Each Teensy board has a unique burned-in mac address that can be read out in the sketch, which will automatically avoid having collisions.

Also if you want to have these talk to each other you can use the Ethernet Bonjour library on each board to register an OSC service and al the Teensy boards can discover each other automatically per DNS-SD.
In that case you may want to use the Teensy 3.1 as it has much more memory than the Teensy LC.

/*
    Make an OSC message and send it over UDP

    Adrian Freed
 */
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>
#include <OSCMessage.h>

EthernetUDP Udp;

//the Arduino's IP
//IPAddress ip(192, 168, 2, 6);
//destination IP
IPAddress outIp(10, 0, 1, 4); //this is the IP adress of your PC
const unsigned int outPort = 8000; //the destination port that OSC messages are sent to
const unsigned int inPort = 9000;   //the port on the Arduino that receives OSC messages

byte mac[] = {
  0x90, 0xA2, 0xDA, 0x0F, 0x2B, 0X1E
};   // you can find this written on the board of some Arduino Ethernets or shields

float vvv = 0.0;

void setup() {

  Serial.begin(9600);
  delay(5000);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while (true);
  }
  // print your local IP address:
  Serial.print("My IP is ");
  Serial.println(Ethernet.localIP());
  Udp.begin(inPort);

}


void loop() {
  //the message wants an OSC address as first argument
  OSCMessage msg("/analog/");
  msg.add(vvv);

  Udp.beginPacket(outIp, outPort);
  msg.send(Udp); // send the bytes to the SLIP stream
  Udp.endPacket(); // mark the end of the OSC Packet
  msg.empty(); // free space occupied by message

  delay(200);

  vvv = vvv + 0.1;
}

@Headroom, what a wealth of information. Thank you.

I am going to try this now and see what I can come up with.

I think I'll be rocking the Arduino for the time being. Until I get this under my belt I think it'll be best to work with the most common denominator platform to allow ease of research/development.

To connect I am using an ethernet to Thunderbolt adapter. I am plugging that right into my thunderbolt port.

I will try that sketch and see how we do!

@Headroom,

I tried that sketch. But I was unable to get any messages to send over. I used the OSC Listener but did not see anything come through.

Does it look like I have everything connected properly?

I am assuming it must be pretty close. I also attached the MAC address picture.

YouTube video: https://youtu.be/eg12sI-40yk

MAC Address image
Google Photos

// Make an OSC message and send it over UDP
// Discussion at http://forum.arduino.cc/index.php?topic=335310.0
// Casey's MAC Address 0x90, 0xA2, 0xDA, 0x0F, 0x2B, 0x1E

#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>
#include <OSCMessage.h>

EthernetUDP Udp;

//the Arduino's IP
//IPAddress ip(192, 168, 2, 6);
//destination IP
IPAddress outIp(169, 254, 228, 174); //this is the IP adress of your PC
const unsigned int outPort = 8000; //the destination port that OSC messages are sent to
const unsigned int inPort = 9000;   //the port on the Arduino that receives OSC messages

byte mac[] = {
  0x90, 0xA2, 0xDA, 0x0F, 0x2B, 0x1E
};   // you can find this written on the board of some Arduino Ethernets or shields

float vvv = 0.0;

void setup() {

  Serial.begin(9600);
  delay(5000);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while (true);
  }
  // print your local IP address:
  Serial.print("My IP is ");
  Serial.println(Ethernet.localIP());
  Udp.begin(inPort);

}


void loop() {
  //the message wants an OSC address as first argument
  OSCMessage msg("/analog/");
  msg.add(vvv);

  Udp.beginPacket(outIp, outPort);
  msg.send(Udp); // send the bytes to the SLIP stream
  Udp.endPacket(); // mark the end of the OSC Packet
  msg.empty(); // free space occupied by message

  delay(200);

  vvv = vvv + 0.1;
}

Have you tried pinging the Arduino from the Mac? Try pinging the 192... address that is currently configured.

Also try changing the Arduino IP address to one on the same subnet as the Mac. First three bytes the same as the Mac, fourth byte different, say 175.

@hackscribble, I tried the ping the other day. I will retry. I will also try setting it to something similar.

I think in the last approach we trued leaving out the ip field and setting only the MAC address. Do you think that's a big influence on this working or not?

I'm afraid I don't know whether, in this peer-peer configuration with no router, the Mac will run DHCP and provide an IP address to the connected device. If it doesn't, I think you will need to configure one on the Arduino.

If you open the serial monitor within the 5 second window provided by the "delay(5000); in the sketch you should see the a message :

"Failed to configure Ethernet using DHCP"

or:

"My IP is xxx.xxx.xxx.xxx"

with the x replaced by the IP address the macbook assigned to the Arduino.

This can take a little while, so be patient. On my configuration with the iMac described above and a Teensy 3.0 with WIZ820io it takes more than 30 seconds until the IP address is assigned.

But again, if you open the serial monitor within the 5 seconds after the upload is done it will print there whether the connection was successful and if so what the IP address is.

If you do get an IP I'd every surprised if you didn't see the messages on the OSC data monitor.
If you don't at least then you can ping the Arduino's IP address from your macbook with the terminal application.

Looking at your video, when you boot up you macbook the Ethernet port tries to connect to a router and asks the router per DHCP for an IP address. If it does not receive an answer it will self-assign an IP address that will be the whether or not you nave an Arduino with ethernet shield connected.

As Hackscribble suggests you can also assign a fixed IP from the same range as the (self-assigned) IP of your macbook. For example in the video your macbook has the IP address 169.254.228.174.
Assign 169.254.228.175 to the Arduino. And change the sketch to not use DHCP, basically back t what you had in the beginning.
Perhaps leave the lines in for the serial monitor so you can print in the serial monitor when an IP address has been assigned. I've just done so and an the Arduino was connected within seconds and sending OSC messages.

@Hackscribble yes, the mac will assigned an IP address to the ethernet shield/Arduino per DHCP. I don't give this kind of advice if I have not tested it myself :wink: