title: Is there a way to convert raw MPU-6050 data to a 0-359 rotational data
body: <p>Im building a Oculus Quest this week. Its meant to be a fun (cheap) project to work on And I figured out how to calculate limb displacement if a constant(foot placement) position is tracked positonaly. I have already to manage to add more than 2 MPU-6050s on the same arduino at once. The problem comes when I want to take the serial data from the MPU and put it into unity. The rotational data is very wrong it looks like this:</p>
  
  <pre><code>gyro    -8.00   -171.00 -148.00  |||    gyro    117.00  -639.00 -1105.00    
  gyro    -4.00   -160.00 -125.00  |||    gyro    -20.00  -640.00 -1081.00    
  gyro    -9.00   -160.00 -128.00  |||    gyro    -86.00  -694.00 -1074.00    
  gyro    13.00   -141.00 -120.00  |||    gyro    -309.00 -713.00 -1040.00    
  gyro    -8.00   -136.00 -134.00  |||    gyro    -184.00 -683.00 -1045.00    
  gyro    -6.00   -150.00 -158.00  |||    gyro    -214.00 -696.00 -1058.00    
  gyro    -12.00  -143.00 -147.00  |||    gyro    -5.00   -644.00 -1086.00    
  gyro    16.00   -157.00 -140.00  |||    gyro    42.00   -662.00 -1153.00    
  gyro    -9.00   -151.00 -136.00  |||    gyro    54.00   -644.00 -1154.00    
  gyro    8.00    -143.00 -143.00  |||    gyro    81.00   -662.00 -1149.00    
  gyro    -17.00  -124.00 -134.00  |||    gyro    -126.00 -698.00 -1088.00    
  gyro    -11.00  -150.00 -138.00  |||    gyro    -28.00  -703.00 -1169.00    
  gyro    -1.00   -129.00 -161.00  |||    gyro    -187.00 -744.00 -1125.00    
  gyro    -23.00  -145.00 -133.00  |||    gyro    -43.00  -713.00 -1117.00    
  gyro    1.00    -143.00 -139.00  |||    gyro    -7.00   -662.00 -1160.00    
  gyro    11.00   -156.00 -136.00  |||    gyro    20.00   -697.00 -1178.00    
  gyro    21.00   -132.00 -116.00  |||    gyro    168.00  -651.00 -1162.00    
  gyro    -1.00   -133.00 -153.00  |||    gyro    -41.00  -688.00 -1151.00    
  gyro    -5.00   -174.00 -144.00  |||    gyro    107.00  -699.00 -1157.00    
  gyro    2.00    -144.00 -146.00  |||    gyro    -177.00 -710.00 -1105.00    
  gyro    -31.00  -134.00 -133.00  |||    gyro    -124.00 -687.00 -1091.00    
  gyro    -8.00   -169.00 -121.00  |||    gyro    -114.00 -695.00 -1133.00    
  gyro    -11.00  -178.00 -151.00  |||    gyro    -132.00 -662.00 -1074.00    
  gyro    -20.00  -154.00 -132.00  |||    gyro    62.00   -659.00 -1136.00    
  gyro    22.00   -142.00 -135.00  |||    gyro    -88.00  -665.00 -1116.00    
  gyro    -30.00  -148.00 -131.00  |||    gyro    51.00   -683.00 -1144.00    
  gyro    -2.00   -163.00 -129.00  |||    gyro    -111.00 -699.00 -1119.00    
  gyro    -9.00   -164.00 -128.00  |||    gyro    -58.00  -706.00 -1114.00    
  gyro    4.00    -146.00 -146.00  |||    gyro    -52.00  -699.00 -1121.00    
  gyro    12.00   -149.00 -138.00  |||    gyro    -147.00 -707.00 -1092.00    
  gyro    -24.00  -146.00 -131.00  |||    gyro    -2.00   -701.00 -1164.00    
  gyro    -7.00   -135.00 -142.00  |||    gyro    -38.00  -700.00 -1137.00    
  gyro    -2.00   -169.00 -139.00  |||    gyro    92.00   -636.00 -1156.00    
  gyro    -12.00  -160.00 -145.00  |||    gyro    -52.00  -658.00 -1094.00    
  gyro    -12.00  -145.00 -131.00  |||    gyro    -27.00  -689.00 -1137.00    
  gyro    -22.00  -139.00 -134.00  |||    gyro    -42.00  -723.00 -1122.00    
  gyro    0.00    -149.00 -133.00  |||    gyro    -54.00  -682.00 -1096.00    
  gyro    -15.00  -173.00 -124.00  |||    gyro    24.00   -688.00 -1127.00    
  gyro    9.00    -163.00 -139.00  |||    gyro    -117.00 -682.00 -1080.00    
  gyro    -21.00  -151.00 -128.00  |||    gyro    21.00   -662.00 -1137.00    
  gyro    20.00   -101.00 -159.00  |||    gyro    -96.00  -636.00 -1051.00    
  gyro    -5.00   -166.00 -132.00  |||    gyro    -135.00 -693.00 -1128.00    
  gyro    -10.00  -149.00 -123.00  |||    gyro    -173.00 -699.00 -1112.00    
  gyro    14.00   -165.00 -135.00  |||    gyro    -91.00  -723.00 -1134.00    
  gyro    -12.00  -163.00 -151.00  |||    gyro    255.00  -670.00 -1163.00    
  gyro    -10.00  -158.00 -144.00  |||    gyro    95.00   -612.00 -1163.00    
  gyro    0.00    -150.00 -130.00  |||    gyro    17.00   -693.00 -1195.00    
  gyro    -18.00  -159.00 -146.00  |||    gyro    -59.00  -728.00 -1161.00    
  gyro    2.00    -183.00 -114.00  |||    gyro    -40.00  -740.00 -1148.00    
  gyro    3.00    -164.00 -107.00  |||    gyro    80.00   -729.00 -1201.00    
  gyro    -17.00  -148.00 -128.00  |||    gyro    -141.00 -682.00 -1147.00    
  gyro    14.00   -158.00 -147.00  |||    gyro    112.00  -696.00 -1145.00    
  gyro    -1.00   -139.00 -136.00  |||    gyro    -116.00 -731.00 -1091.00    
  gyro    -11.00  -136.00 -128.00  |||    gyro    -64.00  -735.00 -1111.00    
  gyro    -2.00   -150.00 -133.00  |||    gyro    -151.00 -757.00 -1092.00    
  gyro    -21.00  -136.00 -129.00  |||    gyro    -156.00 -714.00 -1139.00    
  gyro    -20.00  -163.00 -111.00  |||    gyro    42.00   -738.00 -1116.00    
  gyro    -16.00  -160.00 -141.00  |||    gyro    -141.00 -681.00 -1108.00    
  gyro    -8.00   -176.00 -129.00  |||    gyro    80.00   -691.00 -1142.00    
  gyro    -6.00   -167.00 -159.00  |||    gyro    -52.00  -725.00 -1119.00    
  gyro    -10.00  -178.00 -135.00  |||    gyro    -62.00  -706.00 -1069.00    
  gyro    -16.00  -173.00 -136.00  |||    gyro    -129.00 -735.00 -1112.00    
  gyro    9.00    -147.00 -158.00  |||    gyro    -203.00 -734.00 -1132.00    
  gyro    12.00   -152.00 -131.00  |||    gyro    -12.00  -720.00 -1158.00    
  gyro    -24.00  -163.00 -146.00  |||    gyro    -76.00  -737.00 -1141.00    
  gyro    27.00   -153.00 -128.00  |||    gyro    190.00  -676.00 -1162.00    
  gyro    1.00    -150.00 -129.00  |||    gyro    23.00   -669.00 -1123.00    
  gyro    -14.00  -146.00 -131.00  |||    gyro    51.00   -672.00 -1180.00    
  gyro    0.00    -134.00 -115.00  |||    gyro    -4.00   -706.00 -1171.00    
  gyro    -6.00   -145.00 -139.00  |||    gyro    -160.00 -730.00 -1147.00    
  gyro    -16.00  -165.00 -152.00  |||    gyro    -82.00  -705.00 -1112.00    
  gyro    14.00   -152.00 -147.00  |||    gyro    -246.00 -696.00 -1089.00    
  gyro    -14.00  -162.00 -137.00  |||    gyro    33.00   -705.00 -1162.00    
  gyro    -22.00  -174.00 -152.00  |||    gyro    -31.00  -664.00 -1161.00    
  gyro    -1.00   -138.00 -131.00  |||    gyro    137.00  -642.00 -1141.00    
  gyro    4.00    -173.00 -134.00  |||    gyro    165.00  -652.00 -1168.00    
  gyro    9.00    -152.00 -133.00  |||    gyro    -23.00  -666.00 -1111.00    
  gyro    -12.00  -146.00 -134.00  |||    gyro    64.00   -697.00 -1128.00    
  gyro    -20.00  -132.00 -141.00  |||    gyro    -221.00 -695.00 -1046.00    
  gyro    -7.00   -143.00 -141.00  |||    gyro    -122.00 -684.00 -1116.00    
  gyro    -7.00   -118.00 -150.00  |||    gyro    -188.00 -699.00 -1097.00    
  gyro    -9.00   -148.00 -126.00  |||    gyro    -56.00  -686.00 -1107.00    
  gyro    6.00    -169.00 -130.00  |||    gyro    132.00  -665.00 -1152.00    
  gyro    -1.00   -150.00 -119.00  |||    gyro    22.00   -615.00 -1144.00    
  gyro    12.00   -157.00 -120.00  |||    gyro    212.00  -678.00 -1163.00    
  gyro    5.00    -156.00 -153.00  |||    gyro    -42.00  -745.00 -1169.00    
  gyro    -2.00   -143.00 -130.00  |||    gyro    22.00   -732.00 -1171.00    
  gyro    3.00    -129.00 -142.00  |||    gyro    -145.00 -730.00 -1123.00    
  gyro    -2.00   -132.00 -154.00  |||    gyro    -147.00 -705.00 -1140.00    
  gyro    -9.00   -120.00 -132.00  |||    gyro    -85.00  -691.00 -1143.00    
  gyro    -12.00  -156.00 -153.00  |||    gyro    -157.00 -696.00 -1087.00    
  gyro    -11.00  -149.00 -141.00  |||    gyro    67.00   -681.00 -1095.00    
  gyro    -21.00  -167.00 -140.00  |||    gyro    -72.00  -673.00 -1100.00    
  gyro    19.00   -156.00 -138.00  |||    gyro    76.00   -687.00 -1139.00    
  gyro    -17.00  -135.00 -144.00  |||    gyro    -55.00  -693.00 -1107.00    
  gyro    -6.00   -136.00 -129.00  |||    gyro    -72.00  -721.00 -1091.00    
  gyro    26.00   -146.00 -146.00  |||    gyro    -42.00  -681.00 -1084.00    
  gyro    5.00    -133.00 -125.00  |||    gyro    -135.00 -694.00 -1101.00    
  gyro    -1.00   -152.00 -124.00  |||    gyro    5.00    -674.00 -1173.00    
  gyro    1.00    -144.00 -116.00  |||    gyro    -81.00  -676.00 -1110.00    
  gyro    -8.00   -140.00 -127.00  |||    gyro    32.00   -671.00 -1144.00    
  gyro    17.00   -144.00 -144.00  |||    gyro    60.00   -682.00 -1163.00    
  gyro    8.00    -169.00 -122.00  |||    gyro    16.00   -671.00 -1151.00    
  gyro    16.00   -163.00 -128.00  |||    gyro    134.00  -703.00 -1200.00    
  gyro    -16.00  -178.00 -133.00  |||    gyro    -62.00  -671.00 -1127.00    
  gyro    -2.00   -157.00 -141.00  |||    gyro    128.00  -738.00 -1190.00    
  gyro    -32.00  -147.00 -134.00  |||    gyro    -189.00 -664.00 -1139.00    
  </code></pre>
  
  <p>To my eyes it seems as if the 2 MPU-6050s are having their data calulated diferently,(they are supposed to not have any functions applied to them right now). In the end I want it to be rotational data mapped to 0-359. I know Jeff Rowberg has a great library for this but I want to do this myself so I understand it for the future so I can modify it. My code:</p>
  
  <pre><code>#include &lt;Wire.h&gt;
  
  long accelX, accelY, accelZ;
  float gForceX, gForceY, gForceZ, gyroX, gyroY, gyroZ,rotX, rotY, rotZ;
  long accelX2, accelY2, accelZ2;
  float gForceX2, gForceY2, gForceZ2;
  
  void setup(){
    //write all ADO's to high to raise thieR adress to 0x69
    pinMode(22, OUTPUT);
    digitalWrite(22, HIGH);
    pinMode(23, OUTPUT);
    digitalWrite(23, HIGH);
    pinMode(24, OUTPUT);
    digitalWrite(24, HIGH);
  
    Wire.begin();
    Wire.beginTransmission(0x69);
    Wire.write(0x6B);
    Wire.write(0b00000000);
    Wire.endTransmission();  
    Wire.beginTransmission(0x69);
    Wire.write(0x1B);
    Wire.write(0x00000000);
    Wire.endTransmission(); 
    Wire.beginTransmission(0x69);
    Wire.write(0x1C);
    Wire.write(0b00000000);
    Wire.endTransmission(); 
  
    Wire.begin();
    Wire.beginTransmission(0x68);
    Wire.write(0x6B);
    Wire.write(0b00000000);
    Wire.endTransmission();  
    Wire.beginTransmission(0x68);
    Wire.write(0x1B);
    Wire.write(0x00000000);
    Wire.endTransmission(); 
    Wire.beginTransmission(0x68);
    Wire.write(0x1C);
    Wire.write(0b00000000);
    Wire.endTransmission(); 
  
    Serial.begin(115200);
  }
  
  void loop(){
    GetMpuValue(22);
    Serial.print("\t ||| \t");
    GetMpuValue(23);
    Serial.println("\t");
  }
  
  void GetMpuValue(int pin){
    digitalWrite(pin, LOW);
    Wire.beginTransmission(0x68); 
    Wire.write(0x3B);
    Wire.endTransmission();
    Wire.requestFrom(0x68,6);
  
    Wire.beginTransmission(0x68);
    Wire.write(0x43);
    Wire.endTransmission();
    Wire.requestFrom(0x68,6);
    while(Wire.available() &lt; 6);
    gyroX = Wire.read()&lt;&lt;8|Wire.read();
    gyroY = Wire.read()&lt;&lt;8|Wire.read();
    gyroZ = Wire.read()&lt;&lt;8|Wire.read(); 
    digitalWrite(pin, HIGH);
  
    Serial.print("gyro\t");
    Serial.print(gyroX);
    Serial.print("\t");
    Serial.print(gyroY);
    Serial.print("\t");
    Serial.print(gyroZ);
  }
  </code></pre>
  
  <p>Ty you guys in advance!</p>