great!
ok, first is to fix data transfer:
did you changed your arduino code and replaced first println by print?
to check on processing side
add println in serialevent to check what serial data are incoming
void serialEvent (Serial myPort) {
// reads the data from the Serial Port up to the character '.' and puts it into the String variable "data".
data = myPort.readStringUntil('\n');
// if you got any bytes other than the linefeed:
if (data != null) {
println("data string",data);
data = trim(data);
// split the string at "/"
String items[] = split(data, '/');
if (items.length > 1) {
println(items);
//--- Roll,Pitch in degrees
roll50 = float(items[0]);
pitch50 = float(items[1]);
yaw50 = float(items[2]);
roll49 = float(items[3]);
pitch49 = float(items[4]);
yaw49 = float(items[5]);
}
}
}
we expect to see something like:
data 0.0/1.0/2.0/3.0/4.0/5.0
0.0 1.0 2.0 3.0 4.0 5.0
i put 0 1 2 3 … but it will be random numbers from your sensors
once you fixed that:
in you draw, you take care of only one sensor :
rotateX(radians(-pitch));
rotateZ(radians(roll));
rotateY(radians(yaw));
but now, you have two, with different naming: (i put 50 and 49 at the end as it is your sensors naming in arduino code)
so you need to process both sensors
rotations according to first one are now:
rotateX(radians(-pitch50));
rotateZ(radians(roll50));
rotateY(radians(yaw50));
and second
rotateX(radians(-pitch49));
rotateZ(radians(roll49));
rotateY(radians(yaw49));
but all rotations in processing are cumulatives so you need to do first sensors moves, then go gack to default position and draw second sensors
this is the purpose of pushMatrix() and popMatrix() in this code:
import processing.serial.*;
import java.awt.event.KeyEvent;
import java.io.IOException;
Serial myPort;
String data="";
float roll50, pitch50,yaw50;
float roll49, pitch49, yaw49;
void setup() {
size (1200, 600, P3D);
myPort = new Serial(this, "COM5", 115200); // starts the serial communication
myPort.bufferUntil('\n');
}
void draw() {
background(233);
textSize(22);
pushMatrix(); //save current default position
///// firt sensor
translate(width/4, height/2, 0); //move to left half of the screen
text("Roll: " + int(roll50) + " Pitch: " + int(pitch50), -100, 265);
// Rotate the object
rotateX(radians(-pitch50));
rotateZ(radians(roll50));
rotateY(radians(yaw50));
fill(0, 76, 153);
box (386, 40, 200); // Draw box
popMatrix(); // go back to default position
///// second sensor
translate(width*3/4, height/2, 0); //move to right half of the screen
text("Roll: " + int(roll49) + " Pitch: " + int(pitch49), -100, 265);
// Rotate the object
rotateX(radians(-pitch49));
rotateZ(radians(roll49));
rotateY(radians(yaw49));
fill(100, 76, 153);
box (386, 40, 200); // Draw box
textSize(25);
fill(255, 255, 255);
text(" Cody Galley", -183, 10, 101);
println( roll50, pitch50 , yaw50, "-", roll49 , pitch49, yaw49 );
//delay(10);
//println("ypr:\t" + angleX + "\t" + angleY); // Print the values to check whether we are getting proper values
}
// Read data from the Serial Port
void serialEvent (Serial myPort) {
// reads the data from the Serial Port up to the character '.' and puts it into the String variable "data".
data = myPort.readStringUntil('\n');
// if you got any bytes other than the linefeed:
if (data != null) {
data = trim(data);
// split the string at "/"
String items[] = split(data, '/');
if (items.length > 1) {
//--- Roll,Pitch in degrees
roll50 = float(items[0]);
pitch50 = float(items[1]);
yaw50 = float(items[2]);
roll49 = float(items[3]);
pitch49 = float(items[4]);
yaw49 = float(items[5]);
}
}
}
you where close, tell me if some parts of this code is still obscur