Reading data from MPU6050 (I2C) Please help!

Hey Guys,

I am currently coding for my inverted pendulum. I am using the MPU6050 and I am confused as how to exactly read the data from the sensor. I am obviously using Jeff Rowbergs I2C library, and I ran his example sketch on the uno and it works perfectly. But now I’m trying to take a single sensor reading from the mpu6050 and store it in a variable that I can use to put in my PID control.

How do I take one reading from the sensor and store it as a variable? Never used I2C before.

Thanks Guys!

intialize_senior_project.ino (7.15 KB)

while (digitalRead(LS) == HIGH)
{      //while loop runs only when leveling switches are high (digital pin 5)
  delay(1000);                           
  level = !level;
  break; 
  int angleSP = analogRead(A4);        //angleSP = y axis reading from gyro/acc
  Serial.println(angleSP);              //print data from ac/gyro
  originalSP = angleSP;                 //the original setpoint is given a value and it is the same
                                       //as the initial setpoint.
}

It is pointless to put any code after a break statement.

It is absolutely incomprehensible using delay() in code that is trying to keep an inverted pendulum upright.

Your code is not even reading data from the MPU6050. I can not begin to guess which value you want to store in a variable, or why the usual

   variable = value;

assignment statement isn't sufficient.

I can not begin to guess why you want to do that once only. If you plan to use the value to calculate the length of the braces needed to keep the pendulum from falling over, I guess that might make sense. A plumb bob is simpler though, and then you can use the Arduino for something else.