极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 75219|回复: 41

MPU6050加速度传感器,所有数据显示均为0,求助

[复制链接]
发表于 2013-1-23 17:14:02 | 显示全部楼层 |阅读模式
我按照帖子(http://www.geek-workshop.com/for ... thread&tid=1017)上面的教程连接Anduino (Arduino Nano 3.0 ATmega328开发板 mini版)与MPU6050,编程代码应该没问题,直接copy的,运行时没出现错误,但是测试时数据全为零。连接电路时我是这样连接的:
VCC-----------5v
XDA-----------
XCL-----------
ADO-----------
INT-----------
SDA-----------A4
SCL-----------A5
GND-----------GND,
应该也没问题,但是输出的数据全为零,哪位大神知道这是怎么回事么?求助呀,谢谢!·

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2013-1-23 17:19:48 | 显示全部楼层
你有没有让传感器产生一定的加速度呢?这是加速度传感器啊!
回复 支持 反对

使用道具 举报

发表于 2013-1-23 17:32:23 | 显示全部楼层
除得太多了吧
回复 支持 反对

使用道具 举报

发表于 2013-1-23 20:14:23 | 显示全部楼层
MPU的LED灯亮没?没亮就是有可能坏了,我的就是。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-23 21:03:25 | 显示全部楼层
戊辰寒 发表于 2013-1-23 20:14
MPU的LED灯亮没?没亮就是有可能坏了,我的就是。

谢谢。我的灯是亮着的,但是最终运行显示“MPU6050 connection failed”。可是连接问题我没发现,也不知道哪里出错了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-23 21:04:03 | 显示全部楼层
FoieDEEEE_仲敬 发表于 2013-1-23 17:19
你有没有让传感器产生一定的加速度呢?这是加速度传感器啊!

我使劲晃动,还是没有数据,还是〇呀
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-23 21:05:54 | 显示全部楼层
pww999 发表于 2013-1-23 17:32
除得太多了吧

可是我换了另一个程序没有除数据,却还是那样的,不知道怎么回事呀,程序截图在下楼
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-23 21:08:07 | 显示全部楼层

我换了一个自带的程序,没有除数据,结果却还是〇

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2013-1-23 21:48:11 | 显示全部楼层
用论坛里的IIC地址扫描程序,可以扫描到地址吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-23 22:18:01 | 显示全部楼层
弘毅 发表于 2013-1-23 21:48
用论坛里的IIC地址扫描程序,可以扫描到地址吗?

谢谢。那个自带的程序是我买mpu6050时,卖家发给我的。我对比了一下,不同的地方就在于8楼所说的,其他都是一样的,待会我把程序传上来,您看一下。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-23 22:26:08 | 显示全部楼层
// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class
// 10/7/2011 by Jeff Rowberg <[email protected]>
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
//
// Changelog:
//     2011-10-07 - initial release

/* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2011 Jeff Rowberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include "Wire.h"

// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050.h"

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;

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

#define LED_PIN 13
bool blinkState = false;

void setup() {
    // join I2C bus (I2Cdev library doesn't do this automatically)
    Wire.begin();

    // initialize serial communication
    // (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
    // it's really up to you depending on your project)
    Serial.begin(38400);

    // initialize device
    Serial.println("Initializing I2C devices...");
    accelgyro.initialize();

    // verify connection
    Serial.println("Testing device connections...");
    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");

    // configure Arduino LED for
    pinMode(LED_PIN, OUTPUT);
}

void loop() {
    // read raw accel/gyro measurements from device
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

    // these methods (and a few others) are also available
    //accelgyro.getAcceleration(&ax, &ay, &az);
    //accelgyro.getRotation(&gx, &gy, &gz);

    // display tab-separated accel/gyro x/y/z values
    Serial.print("a/g:\t");
    Serial.print(ax); Serial.print("\t");
    Serial.print(ay); Serial.print("\t");
    Serial.print(az); Serial.print("\t");
    Serial.print(gx); Serial.print("\t");
    Serial.print(gy); Serial.print("\t");
    Serial.println(gz);

    // blink LED to indicate activity
    blinkState = !blinkState;
    digitalWrite(LED_PIN, blinkState);
}
回复 支持 反对

使用道具 举报

发表于 2013-1-23 22:27:28 | 显示全部楼层
  Serial.begin(38400);  ??
  Serial.begin(9600);  ??
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-23 23:13:35 | 显示全部楼层
pww999 发表于 2013-1-23 22:27
Serial.begin(38400);  ??
  Serial.begin(9600);  ??

这个要看您选择哪个了,相应的改一下对应位置就好了,输出数据的右下角不是有个地方可以改么
回复 支持 反对

使用道具 举报

发表于 2013-1-24 11:07:27 | 显示全部楼层
FoieDEEEE_仲敬 发表于 2013-1-23 17:19
你有没有让传感器产生一定的加速度呢?这是加速度传感器啊!

...人家是9轴的,除了3轴加速度还有3轴角度,3轴磁定向.....并且附带温度
角度这个数据肯定会出来的.
回复 支持 反对

使用道具 举报

发表于 2013-1-24 11:14:31 | 显示全部楼层
mengmengzhang 发表于 2013-1-23 22:18
谢谢。那个自带的程序是我买mpu6050时,卖家发给我的。我对比了一下,不同的地方就在于8楼所说的,其他都 ...

链接错误,估计就是IIC地址错误,
另外你的INT这个口空着么?
我记得我的10轴模块(3角度,3加速,三轴角度+气压) 是要接INT的,这个是给单片机中断信号的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 09:07 , Processed in 0.048056 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表