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

本版积分规则

热门推荐

KittenBot杯第六届开源硬件开发大赛启动啦
KittenBot杯第六届开源硬
大赛简介: 第六届开源硬件开发大赛由Arduino中文社区发起 由KittenBot冠名赞助
Blinker 模拟传感器+数字传感器例程(DHT11 温湿度+气体传感)
Blinker 模拟传感器+数字
才接触1星期,发现Blinker自带了很多例程,已经成功试验了DHT的例程序,并完善了体
一文教你选择Arduino开发板,小白进
一文教你选择Arduino开发
笔者在2016年接触了Arduino,跳了万条坑,行了千里弯,到今天也算是Arduino的一
[发布帖]RPG游戏 无人世界
[发布帖]RPG游戏 无人世界
视频攻略:https://www.bilibili.com/video/av43790997/ (b站正在审核) 剧情:主角是
【人脸识别】ESP-EYE 最新的板子到货了
【人脸识别】ESP-EYE 最新
1.我不会编程,最多抄几个一步一步的网络教程。 2.不知道为啥就是超级喜欢电子元件。
Copyright   ©2015-2016  Arduino中文社区  Powered by©Discuz!   ( 蜀ICP备14017632号-3 )
快速回复 返回顶部 返回列表