Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
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/
3 Answers
11 years, 2 months ago.
Using different Library:
https://mbed.org/users/Sissors/code/MPU6050/
/media/uploads/christopher_kayley/connection_successful.bmp
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 28 Oct 2013Assuming you have this one, or similar: https://www.sparkfun.com/products/11028, what did you connect Vdd to?
posted by 28 Oct 2013Did you try one of the other MPU6050 libraries? Just to be sure if it is the code or the hardware?
posted by 30 Oct 2013I have tried your own Library: https://mbed.org/users/Sissors/code/MPU6050/
In this instance the Connection test fails.
posted by 30 Oct 2013When the MPU_6050 address is changed to 0x68 it succesfully makes connection but then continues to output 0, see below for screenshot.
posted by 30 Oct 2013Yeah 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 30 Oct 20133.29V measured on both Vdd and Vio. Ive done a continuity test on the other pins.
posted by 31 Oct 2013
Which library are you using?
posted by Erik - 25 Oct 2013http://mbed.org/users/garfieldsg/code/mpu6050_test/
posted by chris kayley 25 Oct 2013