MPU6050, adapting to work on Teensy 4.1

So I have been working with the mpu6050 using the standard MPU 6050 Library I modified it with a while statement and used micros instead of millis, This code works great on a uno and a mega that I have. But once I got my teensy 4.1 it does not seem to work at all. The gyro values seem to fine expect the setpoint jumps from 0 -4000 randomly. Does anyone have any resources for why the mpu6050 code would not be the same on a teensy, do you have any other recommend libraries?

I also attempted to make an if statement only calling the sensor when .004 seconds have passed but that crashed the Arduino monitor! Any info is greatly apprecieted.
dt=.004


void loop()
{
  
  Vector normAccel = mpu.readNormalizeAccel();
  a_pitch = -(atan2(normAccel.XAxis, sqrt(normAccel.YAxis*normAccel.YAxis + normAccel.ZAxis*normAccel.ZAxis))*180.0)/M_PI;
  a_roll = (atan2(normAccel.YAxis, normAccel.ZAxis)*180.0)/M_PI;
  Vector norm = mpu.readNormalizeGyro();
  g_x =  norm.YAxis;
  g_y =  norm.XAxis;
  g_z =  norm.ZAxis;
  
  

  Serial.println(g_x);
  
  while(micros()-timer < (dt*1000000))
  timer = micros();


}

Can you show the full sketch ?

That is not a standard library and it has bugs.

The Adafruit library for the MPU-6050 has multiple layers. You need to install a few other libraries. I don't know if it works on a Teensy 4.1.

Thank you for the reply, i ended up just using no library for the mpu6050 and following the i2c protocol this has helped me tremendously.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.