OSC message trouble with ArdOSC Library

I am using Recontana's ArdOSC library on Arduino IDE 1.0.1 with an Arduino Uno R3 + Offical Ethernet Shield.

What I'm trying to accomplish is, to Serial.print incoming OSC messages, I would like to have something like "push1 1.00 or push1 0.00", and I will eventually have if statements to send certain RF link signals to other Arduino reciever modules. Basically to have an iPod Touch communicate over OSC to Arduino. I have sucessfully gotten Recontana's old OSC library, OSCClass.h to work on IDE 0022 but with the 1.0.1 IDE update, it no longer works and the ArdOSC library is completely different and very confusing to me.
I have started with the SimpleRecieve example provided, but when I print the "getArgInt32(0)" I just get a number like "1616705461" no matter which button I press.
With the old library, I was able to create "String address0 = recMes.getAddress(0)" and use if statements to Serial.print which button was pressed.

Here is my current code that Serial.prints strange a number like "1616705461" no matter which button i press on my iPod with TouchOSC.

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

#include <ArdOSC.h>

byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte myIp[]  = { 192, 168, 100, 125 };
int  serverPort  = 8000;

OSCServer server;
OSCMessage *_mes;
void setup(){ 
  
 Serial.begin(9600);
 
 Ethernet.begin(myMac ,myIp); 
 server.begin(serverPort);
}
  
void loop(){
  if(server.aviableCheck()>0){
    Serial.println("Message Recieved");
    Serial.println(_mes->getArgInt32(0));
  }
}

If anyone has experience with this library, any help would be greatly appreciated,
thank you! :smiley:

OSCMessage *_mes;

Where does this get set to point to something?

Originally the OSCMessage *_mes was in the function at the bottom, but i moved it in the setup so that the _mes->getArgInt32(0) could be in the loop.

The function looked like this,

void func1(OSCMessage *_mes){

  //get 1st argument(int32)
  t = _mes->getArgInt32(0);



}

I hope that answered your question.

No, not really. _mes can, as far as I can see, never get set to anything in your program.

The examples do something like this:

void setup(){
  Ethernet.begin(myMac ,myIp);
  server.begin(serverPort);
  server.addCallback("/ard/aaa",&func1);
 }

Then the callback handler looks like this:

void func1(OSCMessage *_mes){
    Serial.println("Message Recieved");
    Serial.println(_mes->getArgInt32(0));
}

Have you tried using one of the examples, or doing things the way the examples demonstrate?

Maybe start with this: ArdOSC/SImpleRecieve.ino at master · recotana/ArdOSC · GitHub
and work from there.

Originally the ... was in the function at the bottom, but i moved it in the setup so that the ... could be in the loop.

Whatever was calling that function was assigning a value to _msg. Now, you are not assigning it a value. It is a NULL pointer that you are asking to do something. NULL pointers can't do anything. If you don't have a dog, it can't bark for you. If you don't have a bird, it can't sing for you. If you don't have a OSCMessage, it can't give you any of its arguments.

Okay that makes since, i originally started with the example code, and it didn't work, but that was because i forgot to change

server.addCallback("/ard/aaa",&func1);

to

server.addCallback("/1/push1",&func1);

which is what touchOSC outputs its messages in. When it didn't work i started changing everything, and that why I got the code i had.

Thanks for the help :smiley:

Hi guys, im having some problems with this sketch... well the problem is me for sure,
basicaly i want to turn on a LED when i press 1 button, and to send a Analog Out when i move 1 fader... but im having some problem with the data type
this is the sketch so far...

#include <SPI.h>
#include <Ethernet.h>
#include <ArdOSC.h>

byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte myIp[]  = { 192, 168, 0, 177 };
int  serverPort  = 8000;
int destPort=8001;
int ledPin =  9;
int valuepush = 55;
int valuefader = 56;

OSCServer server;
OSCClient client;

void setup(){ 
 pinMode(ledPin, OUTPUT);  
  
 Serial.begin(9600);
 Ethernet.begin(myMac ,myIp); 
 server.begin(serverPort);
 
 
 //set callback function & oscaddress
 server.addCallback("/1/push1",&push1);
 server.addCallback("/1/fader1",&fader1);
 }
  
  
void loop(){
   if(server.aviableCheck()>0){
     //Serial.println("DataRecived"); 
 }}
 
 
void push1(OSCMessage *_mes){
  int valueA = _mes->getArgInt32(0);
  Serial.println("push1");
  Serial.println(_mes->getArgInt32(0));
  Serial.println(valueA);
  }
  
  void fader1(OSCMessage *_mes){
  int valueB = _mes->getArgInt32(0);
  Serial.println("fader1");
  Serial.println(_mes->getArgInt32(0));
  Serial.println(valueB);
  }

Thats works, when i press the button1 or mode the fader1 ( im using touchosc, beatmachine template ) i receive on the serial port this 6 lines, 3 for each state,,, when i press, and when i release...

push1
1065353216
0
push1
0
0

so i guess that the problem is here

void push1(OSCMessage *_mes){
  int valueA = _mes->getArgInt32(0);
  Serial.println("push1");
  Serial.println(_mes->getArgInt32(0));
  Serial.println(valueA);
  }

in bouth scenarios valueA is 0... i can see that the osc data changed from o to 1065353216 , so i was thinking, it works, but i need to use a map value,,, but if i move the slider from one end to another i get this...

fader1
0
0
fader1
0
0
fader1
1031926529
-3327
fader1
1035333071
-4657
fader1
1036695687
-18297
fader1
1038398958
-18962
fader1
1040102228
-19628
fader1
1040996446
22622
fader1
1041848081
22289
fader1
1043210697
8649
fader1
1044913968
7984
fader1
1046276585
-5655
fader1
1047979855
-6321
fader1
1048874072
-29608
fader1
1049555381
-3659
fader1
1050321852
-23620
fader1
1050917997
-17299
fader1
1051684469
28277
fader1
1052536104
27944
fader1
1053643230
20958
fader1
1054750356
13972
fader1
1055857482
6986
fader1
1056794281
26281
fader1
1057347844
-9980
fader1
1057858825
-23287
fader1
1058412388
5988
fader1
1058923369
-7319
fader1
1059391769
2329
fader1
1059775005
-7651
fader1
1060200822
24950
fader1
1060669222
-30938
fader1
1061095039
1663
fader1
1061520857
-31271
fader1
1061989256
-21624
fader1
1062542819
7651
fader1
1063138964
13972
fader1
1063735109
20293
fader1
1064458999
23287
fader1
1065012562
-12974
fader1
1065353216
0
fader1
1065353216
0
fader1
1065353216
0

so i guess that the data type is not correct... i want to use that numbers as numbers, so i can use the map value
and sometimes the values are negative,,, so im lost here

any ideas?

  int valueA = _mes->getArgInt32(0);

32 bits are hardly going to fit in an int. They will fit in a long.

Hi my friend C4..... thats the solution to your problem...

void fader1(OSCMessage *_mes){
// int valueB = _mes->getArgInt32(0); //thats wrong, because you don't use an integer value....
float valueB = _mes->getArgFloat(0); //you must use a float value instead.... 
Serial.println(valueB);

sorry for apache's english...

Thank you PaulS and alenokia, now it works just fine
i use the example of buttontogle to make a togle switch with the bang imput , so the led stays on or off...
this code works just fine!

#include <SPI.h>
#include <Ethernet.h>
#include <ArdOSC.h>

byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte myIp[]  = { 192, 168, 0, 177 };
int  serverPort  = 8000;
int destPort=8001;
int ledPina =  13;
int ledPinb =  9;
int vala = 0;     // val will be used to store the state
int valb = 0;     // val will be used to store the state
int statea = 0;   // 0 = LED off while 1 = LED on 
int stateb = 0;   // 0 = LED off while 1 = LED on 


OSCServer server;
OSCClient client;

void setup(){                // setup
 pinMode(ledPina, OUTPUT);  
 pinMode(ledPinb, OUTPUT);  
  Serial.begin(9600);
  Serial1.begin(4800);  
 Ethernet.begin(myMac ,myIp); 
 server.begin(serverPort);
 server.addCallback("/1/push1",&push1);   //set callback function & oscaddress // Define comandos OSC y funciones
 server.addCallback("/1/push2",&push2);   //set callback function & oscaddress // Define comandos OSC y funciones
 server.addCallback("/1/fader1",&fader1)  ;//set callback function & oscaddress // Define comandos OSC y funciones
}
  
  
void loop(){                    // setup general, print Rx de OSC
   if(server.aviableCheck()>0){
  // Serial.println("DataRecived"); 
 }}
 
 
void push1(OSCMessage *_mes){ // llama a push1 definido como comando OSC
  float push1 = _mes->getArgFloat(0);
  //Serial.println("push1");
  Serial.println(push1);
  
  vala = digitalRead(push1);
       if (vala == HIGH) { 
       statea = 1 - statea; 
       } 
       if (statea == 1) {      
       digitalWrite(ledPina, HIGH); // turn LED ON 
       } else { 
       digitalWrite(ledPina, LOW); }} // turn LED Off 
  
  void push2(OSCMessage *_mes){ // llama a push1 definido como comando OSC
  float push2 = _mes->getArgFloat(0);
  Serial.println("push2");
  Serial.println(push2);
  valb = digitalRead(push2);
       if (valb == HIGH) { 
       stateb = 1 - stateb; 
       } 
       if (stateb == 1) {      
       digitalWrite(ledPinb, HIGH); // turn LED ON 
       } else { 
       digitalWrite(ledPinb, LOW); }} // turn LED Off 
       
  
void fader1(OSCMessage *_mes){
  float fader1 = _mes->getArgFloat(0);
  Serial.println("fader1");
  Serial.println(fader1);  }

i had to create a second ledpin variable, state variable, and val variable in order to make it work fine,,, a friend told me that it will be better to start using array insted of controc / controlv on the code for each possible button,,, can anybody provide me any array example or documentacion of how to use it ?

Edit :

i found something funny, here...

void push1(OSCMessage *_mes){ // llama a push1 definido como comando OSC
  float push1 = _mes->getArgFloat(0);
  //Serial.println("push1");
  Serial.println(push1);
  vala = digitalRead(push1);
       if (vala == HIGH) { 
       statea = 1 - statea; 
       } 
       if (statea == 1) {      
       digitalWrite(ledPina, HIGH); // turn LED ON 
       } else { 
       digitalWrite(ledPina, LOW); }} // turn LED Off

if i take the line
Serial.println(push1);
off the code, it works as a pianno, and not as a toggle... why ?

Why you use the same pointer name or var for an output (serial.println push1) and for the input.... (digitalRead push1).....
change pointer name and try "one more time" baby.... (use Digital Button Example... might work...)

float push1 = _mes->getArgFloat(0);
Serial.println(push1);
vala = digitalRead(push1);

Why you use the same pointer name or var for an output (serial.println push1) and for the input.... (digitalRead push1).....

If the value being read from the OSC message is a pin number, that's a perfectly reasonable thing to do. Well, except for the part about sending the pin number as a float, instead of an int.

Ok i started from scratch... here is the question

void push1(OSCMessage *_mes){
  int push1 = _mes->getArgFloat(0);
  Serial.println("push1");
  Serial.println(push1); 
  button1 = push1;
  if (button1 == HIGH) {
    digitalWrite(ledPin1, HIGH);
  }
  else{
    digitalWrite(ledPin1, LOW);
  }
}

with that code i can turn on/off a led as a Piano, i want to make a toggle, but im not able to apply any of the digital button or debouce sketches
any sugestion of any toggle sketch that can work under a funtion like this one ?

void push1(OSCMessage *_mes){
  int push1 = _mes->getArgFloat(0);

Is push1 a variable or a function? Both is the wrong answer.

Why are you storing a float in an int? If the value isn't really a float, why are you sending it as one?

  button1 = push1;
  if (button1 == HIGH) {

What is button1? It's really a lousy name. Is push1 supposed to be a pin number (pushPin would be a better name) or a state (pushState would be a better name)? Why is it necessary to use a local variable in this function?

i want to make a toggle

I don't know what this means. Do you mean that sending 0 multiple times should cause a pin to be turned on the first time, and then off, and then back on?

but im not able to apply any of the digital button or debouce sketches

Why aren't you?

First of all thank all for the help!
i have little/none knoledge of what im doing, im following several tutorials of arduino to achive my project, i´m not expeting any solved project due to a forum thread, so one more time thank you all for the time on helping me doing this.

With the code as i show it, when i send the osc command i got the led on, but when i release the button the led goes back off.
What i need is to leave the led on ( this i what i mean when i say toggle, 1 push and 1 release, the led should stay on, another push and another release the led goes off.

I PaulsS i was reading the difference between float and int, basicaly the led have 1 states, on/off, but im storing it as a float because faders goes from 0 to 1 with decimal values. Is this wrong ?
i want to have all the switchs/faders on the same data type.

The reason because im not able to do it is the following,,,
in my code the void loop is only this

void loop(){
   if(server.aviableCheck()>0){
     //Serial.println("DataRecived"); 
 }}

so i guess im not understanding the basic of void loop and void push1... or the basic of wich code runs firts.
On all the examples that i saw regarding the digital debounce, the code run inside the loop, and on this examples the loop its almost empty, and the code runs only inside the void push1/push2/fader1 when osc data is present. Thats why im kind of lose here.

Im working with a 20x4 i2c LCD now, this is the void of push2

// PUSH 02 ////////////////////////////////////////////////////////////
void push2(OSCMessage *_mes){ // this code works when i recive a osc message with the name /push2 rigth ?
  float push2state = _mes->getArgFloat(0); //  i store the data from the funtion push2 on the float variable push2state . This goes from 0 to 1
  lcd.setCursor(0,1); // p
  lcd.print("/push2             "); // print this message on the lcd screen
  lcd.setCursor(9,1);
  lcd.print(push2state ); //  print the variable push2state  on the lcd screen
}
// PUSH 02 END ////////////////////////////////////////////////////////

when i press the button on the touchosc i get the message push1 1, when i release the button on the lcd i see push1 0 , the idea is to turn it on with 1 press of the button
and turn it off with another press of the button. I can do it with 2 buttons, one for on and onther one for off, but i want to use only one.

Please dont loose too much time against my lack of knowledge , if you can just leave me a few links on the subjects that i need to understand first and i will try to figure it out myself

one more time thank you for you time!

PaulsS i was reading the difference between float and int, basicaly the led have 1 states, on/off, but im storing it as a float because faders goes from 0 to 1 with decimal values. Is this wrong ?

I think it is. A fader is the wrong kind of object to use for an on/off switch. If you like the look of the fader, fine. But, perhaps, you should interpret 0.00 to 0.50 to mean off, and 0.51 to 1.00 to mean on, rather than 0.000000 to 0.999999 to mean off and 1.000000 to mean on.

That code snippet alone does not tell the whole story. What triggers a call to that function?

i want to have all the switchs/faders on the same data type.

Personally, I don't think that that is a good idea. Switches are digital (on/off). Faders are analog.

when i press the button on the touchosc i get the message push1 1, when i release the button on the lcd i see push1 0 , the idea is to turn it on with 1 press of the button
and turn it off with another press of the button.

So, you want to ignore the push1 0 messages (they mean that the push1 item was released). Each push1 1 message should toggle a variable:

pinState = !pinState;

Then, simply write pinState to the pin:

digitalWrite(pin, pinState);