MPU6050 - Occasionally weird raw values

Hi all,

I’m working on an IMU with different sensors and basically everything works nearly perfectly. But I have a weird problem with the MPU6050. It turns out that the raw data lies at the heart of the problem. The raw data of the accelerometer sometime suddently spits out “2214 2213 2212”. I have no idea why:)! Sensor is leveled and not moved. Sometimes those values did not appear for a longer time.

See extract of my data below:
ax_raw ay_raw az_raw
[…]
-82 70 16784
-126 110 16714
-86 88 16698
-120 86 16804
-88 96 16784
2214 2213 2212
-114 106 16720
-82 104 16716
2214 2213 2212
2214 2213 2212
-86 96 16754
-162 82 16768
-112 70 16730
2214 2213 2212
-74 104 16754
[…] (about 50 data rows)
-76 68 16756
2214 2213 2212
-132 102 16752
2214 2213 2212
-90 68 16768
-94 128 16744
[…] (and so on)

The update rate is about 15ms. This is the detail of my code to read the raw data and how my MPU6050 is configured:

void readAccelData(int16_t *destination)
{
  uint8_t rawData[6];  // x/y/z accel register data stored here
  readBytes(MPU6050_ADDRESS, ACCEL_XOUT_H, 6, &rawData[0]);  // Read the six raw data registers into data array
  destination[0] = ((int16_t)rawData[0] << 8) | rawData[1] ;  // Turn the MSB and LSB into a signed 16-bit value
  destination[1] = ((int16_t)rawData[2] << 8) | rawData[3] ;  
  destination[2] = ((int16_t)rawData[4] << 8) | rawData[5] ; 
}

void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest){  
  Wire.beginTransmission(address);   // Initialize the Tx buffer
  Wire.write(subAddress);            // Put slave register address in Tx buffer
  Wire.endTransmission(false);       // Send the Tx buffer, but send a restart to keep connection alive
  uint8_t i = 0;
  Wire.requestFrom(address, count);  // Read bytes from slave register address 
  while (Wire.available()) {
    dest[i++] = Wire.read(); 
  }         // Put read results in the Rx buffer
}



void initMPU6050()
{  
 // wake up device
  writeByte(MPU6050_ADDRESS, MPU6050_PWR_MGMT_1, 0x00); // Clear sleep mode bit (6), enable all sensors 
  delay(100); // Delay 100 ms for PLL to get established on x-axis gyro; should check for PLL ready interrupt  

 // get stable time source
  writeByte(MPU6050_ADDRESS, MPU6050_PWR_MGMT_1, 0x01);  // Set clock source to be PLL with x-axis gyroscope reference, bits 2:0 = 001
  delay(200);
  
 // Configure Gyro and Accelerometer
 // Disable FSYNC and set accelerometer and gyro bandwidth to 44 and 42 Hz, respectively; 
 // DLPF_CFG = bits 2:0 = 011; this sets the sample rate at 1 kHz for both
 // Minimum delay time is 4.9 ms which sets the fastest rate at ~200 Hz
 /*
 *          |   ACCELEROMETER    |           GYROSCOPE
 * DLPF_CFG | Bandwidth | Delay  | Bandwidth | Delay  | Sample Rate
 * ---------+-----------+--------+-----------+--------+-------------
 * 0        | 260Hz     | 0ms    | 256Hz     | 0.98ms | 8kHz
 * 1        | 184Hz     | 2.0ms  | 188Hz     | 1.9ms  | 1kHz
 * 2        | 94Hz      | 3.0ms  | 98Hz      | 2.8ms  | 1kHz
 * 3        | 44Hz      | 4.9ms  | 42Hz      | 4.8ms  | 1kHz
 * 4        | 21Hz      | 8.5ms  | 20Hz      | 8.3ms  | 1kHz
 * 5        | 10Hz      | 13.8ms | 10Hz      | 13.4ms | 1kHz
 * 6        | 5Hz       | 19.0ms | 5Hz       | 18.6ms | 1kHz
 * 7 RESERVED
 */
  writeByte(MPU6050_ADDRESS, MPU6050_CONFIG, 0x03);  
 
 // Set sample rate = gyroscope output rate/(1 + SMPLRT_DIV)
  writeByte(MPU6050_ADDRESS, MPU6050_SMPLRT_DIV, 0x04);  // Use a 200 Hz rate; the same rate set in CONFIG above
 
 // Set gyroscope full scale range
 // Range selects FS_SEL and AFS_SEL are 0 - 3, so 2-bit values are left-shifted into positions 4:3
  uint8_t c =  readByte(MPU6050_ADDRESS, MPU6050_GYRO_CONFIG);
  writeByte(MPU6050_ADDRESS, MPU6050_GYRO_CONFIG, c & ~0xE0); // Clear self-test bits [7:5] (0xE0 = 0b11100000)
  writeByte(MPU6050_ADDRESS, MPU6050_GYRO_CONFIG, c & ~0x18); // Clear AFS bits [4:3]       (0x18 = 0b00011000)
  writeByte(MPU6050_ADDRESS, MPU6050_GYRO_CONFIG, c | Gscale << 3); // Set full scale range for the gyro
   
 // Set accelerometer configuration
  c =  readByte(MPU6050_ADDRESS, MPU6050_ACCEL_CONFIG);
  writeByte(MPU6050_ADDRESS, MPU6050_ACCEL_CONFIG, c & ~0xE0); // Clear self-test bits [7:5] 
  writeByte(MPU6050_ADDRESS, MPU6050_ACCEL_CONFIG, c & ~0x18); // Clear AFS bits [4:3]
  writeByte(MPU6050_ADDRESS, MPU6050_ACCEL_CONFIG, c | Ascale << 3); // Set full scale range for the accelerometer 

  // Configure Interrupts and enable I2C_BYPASS_EN so additional chips 
  // can join the I2C bus and all can be controlled by the Arduino as master
  writeByte(MPU6050_ADDRESS, MPU6050_INT_PIN_CFG, 0x02);  // Enable bypass 
  writeByte(MPU6050_ADDRESS, MPU6050_USER_CTRL, 0x00);  //Disable the MPU6050 as Master --> I2C Bus control by Arduino
}

Any ideas? Anyone had the same problem. I’m just very curious.

Thanks and all the best
Tim