Controlling 2 servos and a digital output form processing

Hello
I built a pan and tilt for my camera, for create some nice time lapse, and for test my electronic part, i wish to control my arduino from processing.
So i need to send 3 data : the angle of pan for the first servo, the angle of tilt for the second servo, the launch of the shot on the camera.
How i can send multiple data to the arduino form processing, i looked at example and at each time is only one data to send.
Regards
Gilles

How i can send multiple data to the arduino form processing, i looked at example and at each time is only one data to send.

How do you want to send the data? Like “<P:20; T:35; S>”? The pan value would be 20, the tilt value would be 35, and the shutter would be triggered.

Or, do you want to send “<P:20>” to pan to 20 degrees, then send “<T:35>” to tilt to 35 degrees, and then send “” to snap a picture?

Showing the Processing and Arduino code you have now would be a good starting point.

My problem is only one servo move :frowning:
So for now i got this both code :
the processing one :

import processing.serial.*;
Serial myPort;


int panAngle;
int tiltAngle;
int startPan;
int startTilt;
int endPan;
int endTilt;
int nbStep;
int step;

void setup(){
  size(800,600);
  frameRate(30);
  smooth();
    String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
  startPan=30;
  endPan=120;
  startTilt=90;
  endTilt=120;
  nbStep=200;
}
void draw(){
  background(0);
  
  step++;
  tiltAngle=(int)constrain(map(step,0,nbStep,startTilt,endTilt),startTilt,endTilt);
  panAngle=(int)constrain(map(step,0,nbStep,startPan,endPan),startPan,endPan);
  myPort.write(panAngle);
  myPort.write(tiltAngle);
  text("angle Pano : "+ panAngle,10,10);
  text("angle Tilt : "+ tiltAngle,10,30);
  text("step : "+ step,10,50);
  delay(1000);
  if(step==nbStep)noLoop();
}

The arduino one :

#include <Servo.h> 
 
Servo myservo;
Servo myservo1;                 
     byte panByte;
    float panFloat;
    byte tiltByte;
    float tiltFloat;

void setup() 
{ 
  Serial.begin(9600);
  myservo.attach(9);
myservo1.attach(10);  // attaches the servo on pin 9 to the servo object 
} 
 
 
void loop() 
{ 


  // So i look if i receive more than one value, then i copied them in both byte, one for tilt one for pan
  if (Serial.available()>1) {
    
   panByte = Serial.read();
   tiltByte = Serial.read();

    panFloat = float(panByte);
    tiltFloat= float(tiltByte);
    myservo.write(panFloat); 
    myservo1.write(tiltFloat); 
  }
                            
           
  }

I'd highly recommend that you simply echo the characters received by the Arduino, and read and show them in the processing application, until you understand how serial data transmission works.

You need to determine just what Processing is putting on the serial port. An int in Processing is 4 bytes. When you send that int to the Arduino, there are two possible ways for that to get transferred. One is to send each byte in binary to the serial port.

The other is to convert the value to a string, and send that string.

Your Arduino application is not handling either case.

The Servo library on the Arduino expects an int as input to the Servo::write() method, not a float.

Where do you snap the shutter?

How are you planning to handle the case where serial data gets lost/corrupted? Always expecting 2 bytes is not a realistic thing to do.