机智的小学生 发表于 2014-4-8 18:45:49

请教mpu6050的一个问题

最近在研究四轴飞行器的问题,仔细看了几篇帖子,然后用弘毅老师的这个代码做实验,发现一个很奇怪的现象,就是mpu6050刚开始的一段时间输出的数据还很正常,但是到了后面输出就会全部变成0。代码如下,请不吝赐教!
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"

MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;

char str;

void setup() {
    Wire.begin();
    Serial.begin(9600);
    accelgyro.initialize();
}

void loop() {
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    sprintf(str, "%d,%d,%d,%d,%d,%d,%d", ax, ay, az, gx, gy, gz);
    Serial.print(str);
    Serial.write(byte(10));
    delay(50);
}

机智的小学生 发表于 2014-4-8 20:45:17

我擦 原来是int脚接触不良:Q:Q:Q

Super169 发表于 2014-4-9 12:15:37

机智的小学生 发表于 2014-4-8 20:45 static/image/common/back.gif
我擦 原来是int脚接触不良

我也買了一片 MPU6050 在測試中.
由於找不到有關的接線資料, 在庫中也沒有接線的設定, 我以為只是照 I2C 的接線把 VCC,GND, SCL, SDA 接了就可以.
而且執行測試程式也有數值回傳, 但並未有驗證, 只測試了轉動時數值在改變.

看到樓主說 "是int脚接触不良", 請問這片 MPU6050 中, XCL, XDA, ADD 及 INT 是否需要接上? 接到那裡?

机智的小学生 发表于 2014-4-9 13:25:34

Super169 发表于 2014-4-9 12:15 static/image/common/back.gif
我也買了一片 MPU6050 在測試中.
由於找不到有關的接線資料, 在庫中也沒有接線的設定, 我以為只是照 I2C ...

xcl xda add都不用接只需要把int接入d2就可以了

Super169 发表于 2014-4-9 14:59:42

机智的小学生 发表于 2014-4-9 13:25 static/image/common/back.gif
xcl xda add都不用接只需要把int接入d2就可以了

你的source code 中是用 polling 的方式向 6050 要求資料, INT pin 應該是不需要, 我也沒有連接的.

請問你是否 GY-521 板的?跟據 arduino.cc 的資料 ( http://playground.arduino.cc/Main/MPU-6050 ) :
GY-521

This sensor board has a voltage regulator. When using 3.3V to the VCC the resulting voltage (after the onboard voltage regulator) might be too low for a good working I2C bus. It is preferred to apply 5V to the VCC pin of the sensor board. The board has pull-up resistors on the I2C-bus. The value of those pull-up resistors are sometimes 10k and sometimes 2k2. The 2k2 is rather low. If it is combined with other sensor board which have also pull-up resistors, the total pull-up impedance might be too low.
This schematic is hard to find, so here is a copy: http://playground.arduino.cc/uploads/Main/MPU6050-V1-SCH.jpg
I designed this part in Fritzing, I hope you find it useful: http://fritzing.org/projects/mpu-6050-board-gy-521-acelerometro-y-giroscopio

有可能需要加上 pull-up resistors.

机智的小学生 发表于 2014-4-9 21:47:08

Super169 发表于 2014-4-9 14:59 static/image/common/back.gif
你的source code 中是用 polling 的方式向 6050 要求資料, INT pin 應該是不需要, 我也沒有連接的.

...

我得不是这个我得模块上的芯片就是6050 不是你这个你这个芯片里面其实是集成了6050还有另外一个磁力计吧

Super169 发表于 2014-4-9 23:45:32

机智的小学生 发表于 2014-4-9 21:47 static/image/common/back.gif
我得不是这个我得模块上的芯片就是6050 不是你这个你这个芯片里面其实是集成了6050还有另外一个磁力计 ...

oh, 那我不太清楚了, 在淘寶上十多元的 MPU6050, 都是 GY-521 板子的.另一塊 带卡尔曼滤波 要四十多元, 是用串口的.

由於你用的是 I2C 庫, 所以我猜想你用的是 同一個版本.

观智360 发表于 2014-4-10 01:49:12

智能技术交流群 142398562 喜欢的可以加一下的哦~互相学习。
页: [1]
查看完整版本: 请教mpu6050的一个问题