Multiple IMUs from arduino to Unity

Hi, I try to move two cube by two IMUs (mpu9250) that I control with an arduino mega. I send the euler angles from arduino to Unity by the serial communication and with the videos of Kapil Goswami in youtube I manage to move one cube with 1 IMU. Now I want to move two different objects with two IMUs but I do not know how I can do. I try to replicate the code that I used for the first object for the second cube but I obtain the error: “IOException: Access denied” because I try to open two times the serial port. I add the code that I udes for one cube. I think I have to control the two objects with the same script but how i can do it? Can someone tell me how I can control different object by the same serial port?
Thanks so much:)

3144905–238768–One_mputest.cs (1.94 KB)

in your arduino script, could just send both IMU values? (so you would then receive also yaw2, pitch2, roll2…)

Yes, I send the euler angles of the two IMUs from the same arduino script but I do not know how I can move the second object. If I create a second object and write a new script for the second object where I read the data from the second IMU I have got the previous error because I try to read two times the same serial port…

ok, then could add reference to your script like this (and assign the transforms in inspector)

public Transform box1;
public Transform box2;

then you can move those transforms from the same script (after you receive both values there)

box1.localEulerAngles = new Vector3 (z, y, x);
box2.localEulerAngles = new Vector3 (z2, y2, x2);

Yes!!! Now it’s work!!! Thanks so much mgear!!!:slight_smile: