Arduino, Processing, Serial, OSC! problem.

edited October 2013 in Arduino

Hello,

I am using a arduino (with some sensors) and processing on the computer, after the processing receives the serial information, I need to send it via OSC protocol to another arduino-based hardware ( named Albatross on my processing code). The Albatross and my computer (MacbookPro OS10.7.3) are connected wireless via Wi-Fi router. But I cant use the serial communication between them.

For example, I know that my Arduino sends the serial "estalo" ( showed below), but on the serialEvent (line 38), it doesnt work. I know that the OSC is working, because if I press 'w', it happens what is supposed to do (line 32).

This is the part of my arduino code that I send the Serial.

       if((MuscVS > 150) && (MuscVI > 100))

              {
                  delay(50);        

                 Serial.print("estalo");

                 Serial.print("\n");
              } 

And this is my processing code.

import processing.serial.*;
import g4p_controls.*;
import oscP5.*;
import netP5.*;


OscP5 oscP5;
NetAddress Albatross;

Serial serial;


OscMessage Record = new OscMessage ("/RoboCore/IR/record");
OscMessage Botao1 = new OscMessage ("/RoboCore/IR/send/botao1/3");
OscMessage Botao2 = new OscMessage ("/RoboCore/IR/send/botao2/3");
OscMessage Botao3 = new OscMessage ("/RoboCore/IR/send/botao3/3");
OscMessage Botao4 = new OscMessage ("/RoboCore/IR/send/botao4/3");
OscMessage Stop = new OscMessage ("/RoboCore/IR/STOP");

public void setup(){
  size(480, 320, JAVA2D);
  createGUI();
  customGUI();
  frameRate(25);
  oscP5 = new OscP5 (this, 12000);
  Albatross = new NetAddress ("192.168.1.99", 4444);
  serial = new Serial(this, "COM9", 115200);
  serial.bufferUntil('\n');
}

void keyPressed(){
  if (key == 'w') oscP5.send(Botao1, Albatross);
  if (key == 's') oscP5.send(Botao2, Albatross);
  if (key == 'a') oscP5.send(Botao3, Albatross);
  if (key == 'd') oscP5.send(Botao4, Albatross);}


void serialEvent (Serial myPort){
    String leitura;
   leitura = serial.readStringUntil('\n');
    if (leitura == "estalo") oscP5.send(Botao1, Albatross);
}

public void draw(){
  background(230);

}


public void button1_click1(GButton source, GEvent event) { 
  println("button1 - GButton event occured " + System.currentTimeMillis()%10000000 );
  //OscMessage Record = new OscMessage ("/RoboCore/IR/Record");
  oscP5.send(Record, Albatross);

}


public void button2_click1(GButton source, GEvent event) { 
  oscP5.send(Botao1, Albatross);
  oscP5.send(Stop, Albatross);
  } 

public void button3_click1(GButton source, GEvent event) { 
  oscP5.send(Botao2, Albatross);
  oscP5.send(Stop, Albatross);
  } 

public void button4_click1(GButton source, GEvent event) { 
  oscP5.send(Botao3, Albatross);
  oscP5.send(Stop, Albatross);
  } 

public void button5_click1(GButton source, GEvent event) {
  oscP5.send(Botao4, Albatross);
  oscP5.send(Stop, Albatross);
  }



public void customGUI(){

}

void oscEvent(OscMessage theOscMessage) {
  /* print the address pattern and the typetag of the received OscMessage */
  print("### received an osc message:");
  print(theOscMessage.addrPattern());
  //print(" addrpattern: "+theOscMessage.addrPattern());
  //println(" typetag: "+theOscMessage.typetag());
}

Can someone help me? I dont know what else to do.

Sign In or Register to comment.