Search Unity

Multiple IMUs from arduino to Unity

Discussion in 'Formats & External Tools' started by Alessia93, Jul 14, 2017.

  1. Alessia93

    Alessia93

    Joined:
    Jun 22, 2017
    Posts:
    6
    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:)
     

    Attached Files:

  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    in your arduino script, could just send both IMU values? (so you would then receive also yaw2, pitch2, roll2..)
     
  3. Alessia93

    Alessia93

    Joined:
    Jun 22, 2017
    Posts:
    6
    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....
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    ok, then could add reference to your script like this (and assign the transforms in inspector)

    Code (CSharp):
    1. public Transform box1;
    2. public Transform box2;
    ..

    then you can move those transforms from the same script (after you receive both values there)
    Code (CSharp):
    1. box1.localEulerAngles = new Vector3 (z, y, x);
    2. box2.localEulerAngles = new Vector3 (z2, y2, x2);
     
  5. Alessia93

    Alessia93

    Joined:
    Jun 22, 2017
    Posts:
    6
    Yes!!! Now it's work!!!! Thanks so much mgear!!!!!!!!:)