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();
}