MPU-6050 Extremely Slow Sample Rate?

EDIT - SOLUTION: Sending '0' to the power management (0x6B) register was the problem, as this is the asci character for zero, rather than the binary character. To correctly wake up the IMU, send 0, the binary character for 0, not '0', the asci character for zero. This solution was provided by jremington.

Hi, all!

I'm trying to read from five MPU6050's, specifically the GY-521 modules. However, the device is updating measurements extremely slowly. We're talking less than 1hz. I can read values from the register and send them through serial at an acceptable speed, but it takes a literal second for those values to change. In the meantime, it just keeps sending the same value, over and over. The interesting thing is that when I attach an MPU9250, the code works perfectly, even alongside the MPU6050's. Each value from the MPU9250 is a new, updated value.

I've tried updating the SMPLRT_DIV register, 0x19, and it seems to have no effect. in fact, this register also has no effect on the MPU9250, which makes me wonder if I'm using the register incorrectly. Also, I'm wondering if setting the PWR_MGMT register, 0x6B, to 0 is having some effect - but if it does, it's not affecting the MPU9250.

Here's the serial output that I'm working with. The middle (3rd) value of each line is an MPU9250. Notice that it changes each time, whereas the others only change infrequently.

<17198.67, 15703.79, 15978.93, 14820.22, 15008.79>
<17198.67, 15703.79, 16115.32, 14820.22, 15008.79>
<17198.67, 15703.79, 16057.18, 14820.22, 15008.79>
<17198.67, 15623.56, 15990.02, 14820.22, 15008.79>
<17198.67, 15623.56, 16043.09, 14820.22, 15008.79>
<17198.67, 15623.56, 16024.11, 14820.22, 15008.79>
<17198.67, 15623.56, 15975.18, 14820.22, 15008.79>
<17198.67, 15623.56, 16019.18, 14820.22, 15008.79>
<17198.67, 15623.56, 15970.61, 14820.22, 15008.79>
<17198.67, 15623.56, 16031.11, 14820.22, 15008.79>
<17198.67, 15623.56, 15957.02, 14820.22, 15008.79>
<17198.67, 15623.56, 15906.65, 14820.22, 15008.79>
<17198.67, 15623.56, 15969.58, 14820.22, 15008.79>
<17198.67, 15623.56, 15940.03, 14820.22, 15008.79>

The code for the setup is attached. The wiring is standard I2C, and I'm relatively sure it's correct because the MPU9250 works perfectly when replacing an MPU6050. Still, if you'd like to see it, I can upload a picture.

Anyone have any tips/tricks/suggestions on how to increase this sample rate? I'm not looking for anything extraordinary, even 60hz would be fine. Thanks a bunch! Your time is most appreciated.

Wind_Chimes_Testing.ino (10.1 KB)

1.st: When reading: read(request) 6 bytes once, not 1 byte 6 times. This will speed up and clean up som code

Here is how to read out 3 acceleration values at once from the MPU-6050:

// minimal MPU-6050 tilt and roll (sjr)
// works perfectly with GY-521, pitch and roll signs agree with arrows on sensor module 7/2019
// tested with eBay Pro Mini, **no external pullups on SDA and SCL** (works with internal pullups!)

// If external pullups are used, they must be connected to 3.3V.

#include<Wire.h>
const int MPU_addr1 = 0x68;
float xa, ya, za, roll, pitch;

void setup() {

  Wire.begin();                                      //begin the wire communication
  Wire.beginTransmission(MPU_addr1);                 //begin, send the slave adress (in this case 68)
  Wire.write(0x6B);                                  //make the reset (place a 0 into the 6B register)
  Wire.write(0);
  Wire.endTransmission(true);                        //end the transmission
  Serial.begin(9600);
}

void loop() {

  Wire.beginTransmission(MPU_addr1);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr1, 6, true); //get six bytes accelerometer data

  xa = Wire.read() << 8 | Wire.read();
  ya = Wire.read() << 8 | Wire.read();
  za = Wire.read() << 8 | Wire.read();
// formula from https://wiki.dfrobot.com/How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing
  roll = atan2(ya , za) * 180.0 / PI;
  pitch = atan2(-xa , sqrt(ya * ya + za * za)) * 180.0 / PI; //account for roll already applied

  Serial.print("roll = ");
  Serial.print(roll,1);
  Serial.print(", pitch = ");
  Serial.println(pitch,1);
  delay(400);
}

Thanks for the tips! I wasn't aware that I could do that. However, the problem still doesn't seem to be solved. I'm still getting the same phenomenon where the value is not updating faster than a second or so. Any other ideas? I've attached the code, with your suggestions implemented. Thanks again!

Wind_Chimes_Optimizing.ino (11.7 KB)

Who knows what sending the ASCII character for zero to the sleep register does?

  Wire.write('0'); //write a zero to the sleep register

Remove the single quotes to send a binary zero, as required.

jremington:
Who knows what sending the ASCII character for zero to the sleep register does?

  Wire.write('0'); //write a zero to the sleep register

Remove the single quotes to send a binary zero, as required.

Asked and answered! Removing the quotes was the solution, and the IMU's now work as intended. Thank you very much, your eagle-eyed help is most appreciated!