9DOF to OSC

Hello,

here my specs:
Arduino Nano
Nano V3 Ethernet Shield W5500 (V3)
9DOF Sensor

Status:
Sending OSC Values over Ethernet Works
Sending Acceleration values over Serial USB Works
Sending Acceleration values over Ethernet OSC doesnt work

I tried so many different variations and can't find the mistake.

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

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_9DOF.h>

 /* Assign a unique ID to the sensors */
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified   mag   = Adafruit_LSM303_Mag_Unified(30302);
Adafruit_L3GD20_Unified       gyro  = Adafruit_L3GD20_Unified(20);

EthernetUDP Udp;

//the Arduino's IP
IPAddress ip(192, 168, 8, 177);
//destination IP
IPAddress outIp(192, 168, 8, 62);
const unsigned int outPort = 8000;

byte mac[] = {  
 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // you can find this written on the board of some Arduino Ethernets or shields
void setup() {
 Ethernet.begin(mac,ip);
 Udp.begin(8888);
}

void loop(){
 //declare the bundle

   OSCBundle bndl;
   sensors_event_t event;
    mag.getEvent(&event);


   //BOSCBundle's add' returns the OSCMessage so the message's 'add' can be composed together

   bndl.add("/analog/0").add((float)event.magnetic.x);
   bndl.add("/analog/1").add((float)analogRead(1));
   
  // bndl.add("/digital/5").add((digitalRead(5)==HIGH)?"HIGH":"LOW");
   //bndl.add("/mouse/step").add((float)analogRead(0)).add((float)analogRead(1));
   //bndl.add("/units").add("pixels");


   Udp.beginPacket(outIp, outPort);
       bndl.send(Udp); // send the bytes to the SLIP stream
   Udp.endPacket(); // mark the end of the OSC Packet
   bndl.empty(); // empty the bundle to free room for a new on


   delay(100);
}

Any Ideas for this?

bndl.add("/analog/0").add((float)event.magnetic.x);

the magnetic.x Value is not added in the bundle

Thanks <3 Christian

Reading the 9DOF Sensor Works:

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_9DOF.h>

/* Assign a unique ID to the sensors */
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified   mag   = Adafruit_LSM303_Mag_Unified(30302);
Adafruit_L3GD20_Unified       gyro  = Adafruit_L3GD20_Unified(20);

void displaySensorDetails(void)
{
sensor_t sensor;

accel.getSensor(&sensor);
Serial.println(F("----------- ACCELEROMETER ----------"));
Serial.print  (F("Sensor:       ")); Serial.println(sensor.name);
Serial.print  (F("Driver Ver:   ")); Serial.println(sensor.version);
Serial.print  (F("Unique ID:    ")); Serial.println(sensor.sensor_id);
Serial.print  (F("Max Value:    ")); Serial.print(sensor.max_value); Serial.println(F(" m/s^2"));
Serial.print  (F("Min Value:    ")); Serial.print(sensor.min_value); Serial.println(F(" m/s^2"));
Serial.print  (F("Resolution:   ")); Serial.print(sensor.resolution); Serial.println(F(" m/s^2"));
Serial.println(F("------------------------------------"));
Serial.println(F(""));

gyro.getSensor(&sensor);
Serial.println(F("------------- GYROSCOPE -----------"));
Serial.print  (F("Sensor:       ")); Serial.println(sensor.name);
Serial.print  (F("Driver Ver:   ")); Serial.println(sensor.version);
Serial.print  (F("Unique ID:    ")); Serial.println(sensor.sensor_id);
Serial.print  (F("Max Value:    ")); Serial.print(sensor.max_value); Serial.println(F(" rad/s"));
Serial.print  (F("Min Value:    ")); Serial.print(sensor.min_value); Serial.println(F(" rad/s"));
Serial.print  (F("Resolution:   ")); Serial.print(sensor.resolution); Serial.println(F(" rad/s"));
Serial.println(F("------------------------------------"));
Serial.println(F(""));

mag.getSensor(&sensor);
Serial.println(F("----------- MAGNETOMETER -----------"));
Serial.print  (F("Sensor:       ")); Serial.println(sensor.name);
Serial.print  (F("Driver Ver:   ")); Serial.println(sensor.version);
Serial.print  (F("Unique ID:    ")); Serial.println(sensor.sensor_id);
Serial.print  (F("Max Value:    ")); Serial.print(sensor.max_value); Serial.println(F(" uT"));
Serial.print  (F("Min Value:    ")); Serial.print(sensor.min_value); Serial.println(F(" uT"));
Serial.print  (F("Resolution:   ")); Serial.print(sensor.resolution); Serial.println(F(" uT"));  
Serial.println(F("------------------------------------"));
Serial.println(F(""));
delay(500);
}

void setup(void)
{
Serial.begin(115200);
Serial.println(F("Adafruit 9DOF Tester")); Serial.println("");

/* Initialise the sensors */
if(!accel.begin())
{
  /* There was a problem detecting the ADXL345 ... check your connections */
  Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!"));
  while(1);
}
if(!mag.begin())
{
  /* There was a problem detecting the LSM303 ... check your connections */
  Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
  while(1);
}
if(!gyro.begin())
{
  /* There was a problem detecting the L3GD20 ... check your connections */
  Serial.print("Ooops, no L3GD20 detected ... Check your wiring or I2C ADDR!");
  while(1);
}

/* Display some basic information on this sensor */
displaySensorDetails();
}

void loop(void)
{
/* Get a new sensor event */
sensors_event_t event;
 
/* Display the results (acceleration is measured in m/s^2) */
accel.getEvent(&event);
Serial.print(F("ACCEL "));
Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print("  ");
Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print("  ");
Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print("  ");Serial.println("m/s^2 ");

/* Display the results (magnetic vector values are in micro-Tesla (uT)) */
mag.getEvent(&event);
Serial.print(F("MAG   "));
Serial.print("X: "); Serial.print(event.magnetic.x); Serial.print("  ");
Serial.print("Y: "); Serial.print(event.magnetic.y); Serial.print("  ");
Serial.print("Z: "); Serial.print(event.magnetic.z); Serial.print("  ");Serial.println("uT");


/* Display the results (gyrocope values in rad/s) */
gyro.getEvent(&event);
Serial.print(F("GYRO  "));
Serial.print("X: "); Serial.print(event.gyro.x); Serial.print("  ");
Serial.print("Y: "); Serial.print(event.gyro.y); Serial.print("  ");
Serial.print("Z: "); Serial.print(event.gyro.z); Serial.print("  ");Serial.println("rad/s ");  


Serial.println(F(""));
delay(1000);
}

Sending OSC works with this

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

EthernetUDP Udp;

//the Arduino's IP
IPAddress ip(128, 32, 122, 252);
//destination IP
IPAddress outIp(128, 32, 122, 125);
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() {
Ethernet.begin(mac,ip);
Udp.begin(8888);
}

void loop(){
//declare the bundle
  OSCBundle bndl;

  //BOSCBundle's add' returns the OSCMessage so the message's 'add' can be composed together
  bndl.add("/analog/0").add((int32_t)analogRead(0));
  bndl.add("/analog/1").add((int32_t)analogRead(1));
  bndl.add("/digital/5").add((digitalRead(5)==HIGH)?"HIGH":"LOW");

  Udp.beginPacket(outIp, outPort);
      bndl.send(Udp); // send the bytes to the SLIP stream
  Udp.endPacket(); // mark the end of the OSC Packet
  bndl.empty(); // empty the bundle to free room for a new one

  delay(1000);
}

Please edit your posts to add code tags.

jremington:
Please edit your posts to add code tags.

thanks, alright

    mag.getEvent(&event);

The getEvent() method returns a bool validity flag - you should be checking if the result is valid:

    if (!mag.getEvent(&event))
    {
      Serial.println ("Failed to read magnetometer") ;
      return;
    }

Perhaps this is why you're not seeing data?

@markT

YES!!! Thanks so much!!!! that's is it!!!!!

:smiley: ;D :smiley: :smiley: :smiley: :smiley: :smiley: :smiley:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.