11 years, 2 months ago.

MPU 6050 Accelerometer only outputs 0

When i run my code all i get returned from the accelerometer is 0s. I am sure the device is wired correctly.

I get the following output in Real Term: /media/uploads/christopher_kayley/test_passed.bmp

MPU6050

#include "mbed.h"
#include "MPU6050.h"
 
DigitalOut myled(LED1);
Serial pc(USBTX, USBRX);
MPU6050 mpu;
DigitalOut power(p30);
 
int16_t ax, ay, az;
int16_t gx, gy, gz;
int8_t Data;
int main()
{

    power =1; //Light LED
    //pc.baud(38400);
    pc.printf("MPU6050 test\n\n\r");
    pc.printf("MPU6050 initialize \n\r");
 
    mpu.initialize();
    pc.printf("MPU6050 testConnection \n\r");
 
    bool mpu6050TestResult = mpu.testConnection();
    if(mpu6050TestResult) {
        pc.printf("\r\nMPU6050 test passed \n\r");
    } else {
        pc.printf("\r\nMPU6050 test failed \n\r");
    }
    while(1) {
        wait(1);
        mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
        //pc.printf("Address: %d", &ax);
        //writing current accelerometer and gyro position 
        pc.printf("%d;%d;%d;%d;%d;%d\n\r",ax,ay,az,gx,gy,gz);
        pc.printf("%d\n\r",mpu.getTemperature());
        
    }
    
}

Edit: Library I am using is: http://mbed.org/users/garfieldsg/code/mpu6050_test/

Which library are you using?

posted by Erik - 25 Oct 2013

3 Answers

11 years, 2 months ago.

the question here is where mpu should be connected to pin 9,10 or 28,27?! amd that a reason why it should give zeros

11 years, 2 months ago.

Considering it tells him connection was okay the communication goes fine.

Now the 'normal' reason this problem happens with the MPU6050 is they decided to put the default mode as sleep, so it doesn't do any conversions, or anything else. However that code should disable sleep mode.

Question then, how did you connect your device. Specifically what does your power pin do?

Power Pin used to light an external LED I have on my breadboard. It is connected to pins 28, 27 with Vio connected to 3.3V.

posted by chris kayley 28 Oct 2013

Assuming you have this one, or similar: https://www.sparkfun.com/products/11028, what did you connect Vdd to?

posted by Erik - 28 Oct 2013

Yes that is the board I have. Vdd is connected to 3.3v also

posted by chris kayley 30 Oct 2013

Did you try one of the other MPU6050 libraries? Just to be sure if it is the code or the hardware?

posted by Erik - 30 Oct 2013

I have tried your own Library: https://mbed.org/users/Sissors/code/MPU6050/

In this instance the Connection test fails.

posted by chris kayley 30 Oct 2013

When the MPU_6050 address is changed to 0x68 it succesfully makes connection but then continues to output 0, see below for screenshot.

posted by chris kayley 30 Oct 2013

Yeah I really should do something about that address. However doing nothing anymore with it, and I only published it to help someone else long time ago :P.

But at least we now can be sure it isn't a software error. Two options I see: Either a wiring error, or your MPU6050 is broken. Last option can happen, but I would first try to rule out option A. Can you measure with a multimeter the voltage on all pins? And especially Vdd and Vio?

posted by Erik - 30 Oct 2013

3.29V measured on both Vdd and Vio. Ive done a continuity test on the other pins.

posted by chris kayley 31 Oct 2013

Can you using my library do [mpu-name].read(MPU6050_PWR_MGMT_1_REG);, and check the return value? It should be zero.

If that is the case, I would contact your vendor that you got a defective board.

posted by Erik - 31 Oct 2013

It returned 1

posted by chris kayley 12 Nov 2013

Thats weird, then it shouldn't be in sleep mode, but its clock is set to a non-default value.

posted by Erik - 12 Nov 2013