Pages: [1]   Go Down
Author Topic: Send OSC messages through W5100 ethernet shield  (Read 1101 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi There!

A little help might be useful. I'm trying to run a simple arduino sketch that sends an OSC message (so I can read it on Processing) over UDP. I'm using Arduino UNO and W5100 Ethernet shield.

As you can see at the end of the code I'm printing something just to know when it has sent a message but the code does never reach the print instruction. IP addresses and port are correct and DHCP works just fine. The problem seems to be when I try to beginPacket, send the OSC message and endPacket.

Here goes the source code (most interesting part is at the end):

Code:
#include <OSCMessage.h>

/*
Make an OSC message and send it over UDP
 */
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>   
#include <OSCMessage.h>
#include <stdlib.h>
EthernetUDP Udp;

//the Arduino's IP
IPAddress ip(192, 168, 0, 121);
//destination IP
IPAddress outIp(192, 168, 0, 124);
const unsigned int outPort = 9999;

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // you can find this written on the board of some Arduino Ethernets or shields
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  // this check is only needed on the Leonardo:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // 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:
    for(;;)
      ;
  }
  // print your local IP address:
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print(".");
  }
  Serial.println();
}


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

//PROBLEM SEEMS TO OCCUR HERE. When I comment the following 3 lines, it runs.
  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
  Serial.print("\nosc message sent");

  delay(20);
}

This is what is printed on serial monitor
Code:
My IP address: 192.168.0.141.

By the way, no errors printed. Network running file, I can exchange messages between Pure Data and Processing using the same IPs and ports. Any hints on how to send a simple osc message from arduino?

Thanks!!
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't see a UDP.begin(localPort) call in setup. That will cause a fail.
http://arduino.cc/en/Reference/EthernetUDPBegin
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 33
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

We fixed that bug a while ago, please take a fresh look at
this: https://github.com/CNMAT/OSC
Logged

Pages: [1]   Go Up
Jump to: