Accelerometer MPU-6050 marks timeout in Unity I've been having this problem, that I am trying to use an accelerometer MPU-6050 to get the rotation and pass that information to Unity. 

I also have some buttons in the same Arduino. I'm using an Arduino Uno. With those buttons, everything works well, but the moment I put something related to the accelerometer in the Arduino code, Unity marks a time out. When I run it on Arduino it sends me all the info I'm asking, so I don't really know what's the problem. I really appreciate if someone could help me.

Here is code on Arduino:

#include&lt;Wire.h&gt;
#define A_R 16384.0
#define G_R 131.0
 #define RAD_A_DEG = 57.295779
const int MPU_addr=0x68;  // I2C address of the MPU-6050
int AcX,AcY,AcZ,GyX,GyY;

float Acc[2];
float Gy[2];
float Angle[2];
int button = 0;
int button2 = 0;
int button3 = 0;

float arriba=0, abajo=0,mouse=0;

void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  pinMode(7, INPUT); // declare pushbutton as input
pinMode(6, INPUT);
pinMode(5,INPUT);
  Serial.begin(9600);
}

void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  //Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers

  AcX=Wire.read()&lt;&lt;8|Wire.read();  // 0x3B (ACCEL_XOUT_H) &amp; 0x3C (ACCEL_XOUT_L)    
  AcY=Wire.read()&lt;&lt;8|Wire.read();  // 0x3D (ACCEL_YOUT_H) &amp; 0x3E (ACCEL_YOUT_L)
 AcZ=Wire.read()&lt;&lt;8|Wire.read();

  Acc[1] = atan(-1*(AcX/A_R)/sqrt(pow((AcY/A_R),2) + pow((AcZ/A_R),2)))*RAD_TO_DEG;
   Acc[0] = atan((AcY/A_R)/sqrt(pow((AcX/A_R),2) + pow((AcZ/A_R),2)))*RAD_TO_DEG;


  GyX=Wire.read()&lt;&lt;8|Wire.read();  // 0x43 (GYRO_XOUT_H) &amp; 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()&lt;&lt;8|Wire.read();  // 0x45 (GYRO_YOUT_H) &amp; 0x46 (GYRO_YOUT_L)

  Angle[0] = 0.98 *(Angle[0]+Gy[0]*0.010) + 0.02*Acc[0];
   Angle[1] = 0.98 *(Angle[1]+Gy[1]*0.010) + 0.02*Acc[1];

        button = digitalRead(7);
  button2 = digitalRead(6);
  button3 = digitalRead (5);

   //Mostrar los valores por consola
   if(button == HIGH){
 arriba=1;
  }else if(button==LOW){
  arriba=0;
  }

  if(button2 == HIGH){
    abajo=1;
  }else if(button2==LOW){
    abajo=0;
  }

  if(button3 == HIGH){  //boton 3
    mouse=1;
  }else if(button3==LOW){
    mouse=0;
  }
  Serial.print(arriba);
  Serial.print(",");
  Serial.print(abajo);
  Serial.print(",");
  Serial.print(mouse);
   Serial.print(",");

   Serial.print(Angle[0]); 
   Serial.print(",");
   Serial.println(Angle[1]);

  delay(200);
}


I know this isn't an Unity forum, but here is the code in Unity. The only thing it does, is read it and put the results in an array.

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO.Ports;
using System.Globalization;
using System;

using UnityEngine;

public class ConectarArduino: MonoBehaviour
{
    string Recibidos;
    public string Linea, Linea1,Linea2;
    public int Arrib, Abajo,Boton;
    SerialPort stream;
    // Use this for initialization

    void Start()
    {
        stream = new SerialPort("COM3", 9600);
        //  stream.
        stream.Open();
        stream.ReadTimeout = 300;

    }

    // Update is called once per frame
    void Update()
    {
        try
        {
            Recibidos = stream.ReadLine();
            Debug.Log(Recibidos);
        }
        catch (System.Exception e)
        {
            Debug.Log(e.Message);
            throw;
        }

        string[] Values = Recibidos.Split(',').Select(str =&gt; str.Trim()).ToArray();
        Linea = Values[0];
        Linea1 = Values[1];
        Linea2 = Values[2];
Running MPU-6050 at 57600bps seemed to be the good rate for me:

  pinMode(5,INPUT);
  Serial.begin(57600);
}


It worked for me and I found these guys for whom it was the good rate :

From MPU-6050-simple-library, specifically MPU6050_test.ino:


void setup() {
  Serial.begin(57600);
  MPU6050mgr.begin(); // Initializes IMU module 
}



From Another Arduino as external i2c device for MPU6050:


void setup() {
  Wire.begin(0x1E);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(57600);           // start serial for output
}



From Library for Arduino and MPU-6050 communication:


void setup() {
  Serial.begin(57600);
  MPU6050mgr.begin(); // Initializes IMU module 
}



You may also find this link useful: MPU-6050 Redux: DMP Data Fusion vs. Complementary Filter.