Processing to arduino serial question?

The Arduino is not talking to PD and Processing, is it? It only has one serial port that is connected to the PC via the USB cable. It can only talk to one application on the PC end.

No I have Processing acting as a middleman of sorts to communicate between the two. PD is pulling data from processing and processing is using the processing serial to work with arduino.

I wouldn't understand the PD side, but seeing the Arduino code might provide some clues as to how to help you.

I have the PD side mostly finished but the arduino code I am using is based on a hardware debounce but I am now using an optical encoder for more stability and I have yet to rectify the code. I still must take out unnecessary attaches and detaches as well as using CHANGE instead of RISE and FALL.

The Arduino sketch:

int pulses, A_SIG=0, B_SIG=1;
int digitalInput5 = 5;  
int value5 = '0'; // switch setup to reset encoder values



void setup(){
  attachInterrupt(0, A_RISE, RISING);
  attachInterrupt(1, B_RISE, RISING);
  pinMode(digitalInput5,OUTPUT);

  Serial.begin(9600);
}//setup


void loop(){
  value5 = digitalRead(5);
   if (value5 ){
pulses=0; //pulses reset to zero
}
  
  
}

void A_RISE(){
 detachInterrupt(0);
 A_SIG=1;
 
 if(B_SIG==0)
 pulses++;//moving forward
 if(B_SIG==1)
 pulses--;//moving reverse
 Serial.println(pulses);
 attachInterrupt(0, A_FALL, FALLING);
}

void A_FALL(){
  detachInterrupt(0);
 A_SIG=0;
 
 if(B_SIG==1)
 pulses++;//moving forward
 if(B_SIG==0)
 pulses--;//moving reverse
 Serial.println(pulses);
 attachInterrupt(0, A_RISE, RISING);  
}

void B_RISE(){
 detachInterrupt(1);
 B_SIG=1;
 
 if(A_SIG==1)
 pulses++;//moving forward
 if(A_SIG==0)
 pulses--;//moving reverse
 Serial.println(pulses);
 attachInterrupt(1, B_FALL, FALLING);
}

void B_FALL(){
 detachInterrupt(1);
 B_SIG=0;
 
 if(A_SIG==0)
 pulses++;//moving forward
 if(A_SIG==1)
 pulses--;//moving reverse
 Serial.println(pulses);
 attachInterrupt(1, B_RISE, RISING);
}

The processing then sketch trims off unnecessary white space and sends the data to PD as floats using the OSC messages and finally Pd recieves this data using a localhost connection.

The Processing sketch:

import processing.serial.*;
 
import oscP5.*;
import netP5.*; 
// The serial port:
Serial myPort;

OscP5 oscP5;
NetAddress myRemoteLocation;


 
void setup() {
   size(400,400);
  frameRate(25);
  // List all the available serial ports:
  println(Serial.list());
 
  myPort = new Serial(this, Serial.list()[0], 9600);
  
    oscP5 = new OscP5(this,12000);
  
  myRemoteLocation = new NetAddress("127.0.0.1",12000);
     
}

 
void draw() {
      background(0);  

      String pulses_raw = myPort.readStringUntil('\n'); //read until the new line, like print ln
  
  if (pulses_raw != null) {
    
    // trim off any whitespace:
    pulses_raw = trim(pulses_raw);
    
    float pulses = float(pulses_raw); 
 

println(pulses);

  // preparing message to send to PD   
 OscMessage myMessage = new OscMessage("/hello");
  //Attaches pulse values to send
  myMessage.add(pulses);
  //sends pulse data to PD
    oscP5.send(myMessage, myRemoteLocation); 
    
  }
}

What happened to that idea? Seems more logical to me.

That was the original plan but I have been having a really hard time figuring how to use the encoder along with another sensor to print to serial so I can use the different values in PD. The answer may be staring me straight in the face and I may have needlessly complicated things for myself but I cannot seem to figure it out.