查看: 5674|回复: 1

GY-521 MPU6050模块读不出数据了,求教!

[复制链接]

该用户从未签到

发表于 2016-10-10 13:06 | 显示全部楼层 |阅读模式
之前用Arduino MEGA2560板子单独测试GY-521,是能测试出来的值,在Arduino串口监视器上可以读出加速度和角速度,代码是下载的资料里给的例子,如下:
// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class
// 10/7/2011 by Jeff Rowberg <jeff@rowberg.net>
// 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);
}

后来我把超声波模块以及马达等都连在Arduino MEGA2560板子上,自己编写了一段代码,GY-521就读不出来数据了。即使现在单独连接测试GY-521也读不出来数据了,串口监视器一直显示Initializing I2C devices...,下面就跑不下去了,好像是初始化出了问题。PS:我连线都是正确的,电压用的3.3V,现在GY-521上的灯是亮的,可就是读不出来加速度和角速度值了,求懂得大神给帮帮看看!谢谢了!

该用户从未签到

发表于 2018-2-21 16:56 | 显示全部楼层
您好,我的情况和您差不多,请问您现在解决了么?
您需要登录后才可以回帖 登录 | 立即注册  

本版积分规则

热门推荐

OLED 128*64自制可达10000000个选项的菜单(已更新)
OLED 128*64自制可达10000
OLED 128*64自制可达10000000个选项的菜单 温馨提示: 建议占个楼再食用本帖子
这个怎么整?标点都是英文的
这个怎么整?标点都是英文
a=a+1改成a++也不行
[WiFiduino-8266开发板测试]三、测试IO口
[WiFiduino-8266开发板测
首先测试IO口的关系,板载正面的D0~D15[D14,D15没有,相同的位置写的是D4,D5],反面
求助,arduino nano发热严重
求助,arduino nano发热严
我有一块arduino nano板,装在一个扩展板上(如下图),用扩展板上的外接电源接口(资
[限时福利]5分钟带你快速了解新一代开发板:M5STACK
[限时福利]5分钟带你快速
一、什么是M5Stack M5Stack是一种模块化、可堆叠扩展的开发板,每个模块
Copyright   ©2015-2016  Arduino中文社区  Powered by©Discuz!   ( 蜀ICP备14017632号-3 )
快速回复 返回顶部 返回列表