Page 1 of 2

Problem while using MPU6050

Posted: Thu May 24, 2012 11:52 am
by sapan
Hi,

I have designed my own board. It has MPU6050 connected on I2C1 bus (No other sensors are connected on this bus). I am able to connect and communicate through I2C1 with sensor, but it seems that I am not getting value as per expected. Getting value exactly half of expected output.

This is start up part. Have set accelerometer range as +/-2g. So Z axis output should be around 16000 count. But I am getting exactly half of that. Tried changing range as well but same problem at rest of configuration as well.

Code: Select all

#define MPU_addr         0b1101001
void set_mpu_i2c(void){
   uint8_t sampling_rate = 0x19, config = 0x1A, gyro_config = 0x1B, accel_config = 0x1C,txbuf[20],rxbuf[20];
   txbuf[0] = 0x74;
   //int16_t val1 = 0, val2 =0, val3 = 0, val4 = 0, val5 = 0, val6 = 0;

/*   chprintf((BaseChannel *)&SD1, "abcd");


   i2cMasterTransmit(&I2CD1, MPU_addr, txbuf, 1, rxbuf, 2);
   chprintf((BaseChannel *)&SD1, "Who AM I %x, %x \r\n", rxbuf[0], rxbuf[1]);
   chThdSleepMilliseconds(10);
*/

   txbuf[0] = 0x6B;//pwr management 1;
   txbuf[1] = 0x01;
   i2cMasterTransmit(&I2CD1, MPU_addr, txbuf, 2, rxbuf, 0);
   chThdSleepMilliseconds(1000);

   txbuf[0] = 0x1B;//Gyro Config;
   txbuf[1] = 0x00;
   i2cMasterTransmit(&I2CD1, MPU_addr, txbuf, 2, rxbuf, 0);
   chThdSleepMilliseconds(1000);

   txbuf[0] = 0x1C;//Accel Config;
   txbuf[1] = 0x00;
   i2cMasterTransmit(&I2CD1, MPU_addr, txbuf, 2, rxbuf, 0);
   chThdSleepMilliseconds(1000);


   txbuf[0] = 0x19;//sampling_rate;
   txbuf[1] = 0x09;
   i2cMasterTransmit(&I2CD1, MPU_addr, txbuf, 2, rxbuf, 0);
   chThdSleepMilliseconds(1000);


   txbuf[0] = 0x19;
   i2cMasterTransmit(&I2CD1, MPU_addr, txbuf, 1, rxbuf, 4);
   chprintf((BaseChannel *)&SD1, "Reading config I %x, %x, %x, %x \r\n", rxbuf[0], rxbuf[1], rxbuf[2], rxbuf[3]);
   chThdSleepMilliseconds(1000);


}


Following function I am using to fetch data from MPU.

Code: Select all

void read_mpu_data_i2c(void)
{
   uint8_t txbuf[20], rxbuf[20],i=0,j=0 ;
   int16_t val[10];
   txbuf[0] = 0x3B;
   for(i=0;i<20;i++)rxbuf[i] = 0x00;
   i2cMasterTransmit(&I2CD1, MPU_addr, txbuf, 1, rxbuf, 14);
   val[0] = (rxbuf[0] << 8) + rxbuf[1];
   val[1] = (rxbuf[2] << 8) + rxbuf[3];
   val[2] = (rxbuf[4] << 8) + rxbuf[5];

   /*added on 25th April 12*/
   val[3] = (rxbuf[6] << 8) + rxbuf[7];
   val[4] = (rxbuf[8] << 8) + rxbuf[9];
   val[5] = (rxbuf[10] << 8) + rxbuf[11];
   val[6] = (rxbuf[12] << 8) + rxbuf[13];

   chprintf((BaseChannel *)&SD1, " MPU values are:");
   j = 0;
   for(i=0;i<7;i++){
      //chprintf((BaseChannel *)&SD1, " \t%x \t%x", rxbuf[j], rxbuf[j+1]);
      chprintf((BaseChannel *)&SD1, "\t%d ", val[i]);
      j = j+2;
   }
   chprintf((BaseChannel *)&SD1, "\r\n");


   chThdSleepMilliseconds(100);

}


Any idea what am I doing wrong?

Re: Problem while using MPU6050

Posted: Thu May 24, 2012 12:07 pm
by sapan
Got the problem. Seems that I have got Engineering samples. Found discussion here

http://forum.sparkfun.com/viewtopic.php?f=14&t=30624

I purchased them from CDIweb and they didnt mention that these would be engineering samples. It is marked ES on chip and has separate document no.

Re: Problem while using MPU6050

Posted: Thu May 24, 2012 12:49 pm
by Badger
I also noticed some strange behaviour on my MPU6050, does the ES at the end of MPU6050 indicate engineering sample?

Image

Re: Problem while using MPU6050

Posted: Thu May 24, 2012 2:13 pm
by sapan
Yup its engineering. Mentioned ES on mine as well. Apart from resolution it works fine. I am doing initialization as shown in my code. Its giving correct data for accelerometer. Havent checked with gyro yet. Need to perform some floating point calculation for that and I am having problem with Floating point in chibios

Re: Problem while using MPU6050

Posted: Thu May 31, 2012 7:15 pm
by Badger
Sparkfun are sending me a replacement MPU6050 :D hopefully with this one I will be able to use the full acceleration options.

Re: Problem while using MPU6050

Posted: Tue Jun 05, 2012 12:20 am
by trunet
I'm receiving only 0 values.

Code: Select all

MPU values are:        0       0       0       0       0       0       0 
 MPU values are:        0       0       0       0       0       0       0
 MPU values are:        0       0       0       0       0       0       0
 MPU values are:        0       0       0       0       0       0       0
 MPU values are:        0       0       0       0       0       0       0
 MPU values are:        0       0       0       0       0       0       0
 MPU values are:        0       0       0       0       0       0       0
 MPU values are:        0       0       0       0       0       0       0
 MPU values are:        0       0       0       0       0       0       0
 MPU values are:        0       0       0       0       0       0       0
 MPU values are:        0       0       0       0       0       0       0


Any clue?

Re: Problem while using MPU6050

Posted: Tue Jun 05, 2012 1:54 am
by trunet
Answering my own question, the device address was wrong. AD0 is tied to GND so address is 0x68.

Working fine now, but getting tons of negative values(even temperature).

Re: Problem while using MPU6050

Posted: Tue Jun 05, 2012 5:15 am
by sapan
Can you post your codes where you are converting data? Also you can check accelerometer outputs in different orientations.

Re: Problem while using MPU6050

Posted: Wed Jun 06, 2012 1:41 am
by trunet
sapan wrote:Can you post your codes where you are converting data? Also you can check accelerometer outputs in different orientations.

I'm receiving:
MPU values are: 604 -252 13360 20957260 -862 -70 586

Accelerometer/gyroscope are OK I think. If I rotate on differente axis the values are updated linearly to plus or minus.

but the temperature, I'm receiving around -2700 if I warm a little the sensor I get -2300 linearly. The value above I'm trying to convert using the formula:

Code: Select all

temp = (-521 + ((mpu_rxbuf[6] << 8) + mpu_rxbuf[7])) * 340;

Re: Problem while using MPU6050

Posted: Wed Jun 06, 2012 8:06 am
by sapan
As per datasheet, Sensitivity of sensor is 340 LSB/degree and output at 35 degree is -521. So your formula is,

Temperature (in Degree) = ( raw temperature output / 340) + offset

Where, offset = 35 + (521/340) = 36.5323