查看: 5078|回复: 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 | 显示全部楼层
您好,我的情况和您差不多,请问您现在解决了么?
您需要登录后才可以回帖 登录 | 立即注册  

本版积分规则

热门推荐

学习记录2,Blinker读取温湿度
学习记录2,Blinker读取温
开关现在是使用得很6了,准备进行下一步,读取数据。 找了下官方的例程,发现用的是w
学生智能打卡系统(接入blinker)
学生智能打卡系统(接入bl
【项目名称】学生智能打卡系统(接入blinker) 一.感谢各位大佬 首先感谢社区的管理员
关于红外控制空调的模块选型
关于红外控制空调的模块选
想问问这中模块能支持arduino吗
LCD1602只亮 不显示
LCD1602只亮 不显示
#include // initialize the library by associating any needed LCD interface pin
18脚的8x8LED点阵如何使用??
18脚的8x8LED点阵如何使用
本帖最后由 Creeper666 于 2018-8-14 12:24 编辑 这个点阵模块上面一排有12个脚,
Copyright   ©2015-2016  Arduino中文社区  Powered by©Discuz!   ( 蜀ICP备14017632号-3 )
快速回复 返回顶部 返回列表