I wrote a simple Arduino sketch to get accelerometer and gyro data from both the MPU-6050 and the MPU-9150. I need something of small size that will fit in the less than 32K of memory available on my microcontroller. Everything works as I expect until I rotate the sensor about the y-axis; then, the accelerometer reports the same reading for all axes and the device stops updating and appears to be frozen. I have seen this behavior on every one of the several MPU-6050 and MPU-9150 devices I own. Here is the initialization I am using:
void initMPU6050()
{
// reset device
writeRegister(PWR_MGMT_1, 0x80); // Write a one to bit 7 reset bit; toggle reset device
delay(100);
// wake up device
writeRegister(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
writeRegister(PWR_MGMT_1, 0x01); // Set clock source to be PLL with x-axis gyroscope reference, bits 2:0 = 001
// 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
byte c = readRegister(GYRO_CONFIG);
writeRegister(GYRO_CONFIG, c & ~0xE0); // Clear self-test bits [7:5]
writeRegister(GYRO_CONFIG, c & ~0x18); // Clear AFS bits [4:3]
writeRegister(GYRO_CONFIG, c | Gscale << 3); // Set full scale range for the gyro
// Set accelerometer configuration
c = readRegister(ACCEL_CONFIG);
writeRegister(ACCEL_CONFIG, c & ~0xE0); // Clear self-test bits [7:5]
writeRegister(ACCEL_CONFIG, c & ~0x18); // Clear AFS bits [4:3]
writeRegister(ACCEL_CONFIG, c | Ascale << 3); // Set full scale range for the accelerometer
// Disable FSYNC and set accelerometer and gyro bandwidth to 44 and 42 Hz, respectively;
// DLPF_CFG = bits 2:0 = 010; this sets the sample rate at 1 kHz for both
writeRegister(CONFIG, 0x02);
// Set sample rate = gyroscope output rate/(1 + SMPLRT_DIV)
writeRegister(SMPLRT_DIV, 0x07); // Use a 1000 Hz rate; the same rate set in CONFIG above
// Set up interrupt pin
// Set interrupt pin active high, push-pull, and clear on read of INT_STATUS, enable I2C_BYPASS_EN so additional chips
// can join the I2C bus and all can be controlled by the Arduino as master
writeRegister(INT_PIN_CFG, 0x10); // Set interrupt pin active high, push-pull, and clear on read of INT_STATUS
writeRegister(INT_ENABLE, 0x01); // Enable data ready (bit 0) interrupt
}
I have successfully used Jeff Rowberg's Library (or Hack, as Invensense refers to it) to get these devices to work without exhibiting this problem. I would like to understand how to make these devices work myself. I must be missing some motion control disable action to prevent the latchup of the devices but I am at a loss to understand what I have missed. I studied the latest Motion Apps main.c and can't seem to find what I might be missing. I would greatly appreciate any help you could provide toward solving this problem. Thank you in advance for your help.
- Log in to post comments
phpbb Topic ID
16074