极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9508|回复: 3

mpu6050 与arduino链接失败

[复制链接]
发表于 2014-12-20 12:26:48 | 显示全部楼层 |阅读模式
我是按照VCC--VCC GND--GND SCL--A5 SDA--A4链接的啊  但是数据全是0  用HMC5883也读不出数据来  好像不是程序的问题 换了几个都都不出来   大神快来帮帮我啊

本帖子中包含更多资源

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

x
回复

使用道具 举报

 楼主| 发表于 2014-12-20 12:28:12 | 显示全部楼层
代码
  1. // I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class
  2. // 10/7/2011 by Jeff Rowberg <[email][email protected][/email]>
  3. // Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
  4. //
  5. // Changelog:
  6. //     2011-10-07 - initial release

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

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

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

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

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

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

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

  39. int16_t ax, ay, az;
  40. int16_t gx, gy, gz;

  41. #define LED_PIN 13
  42. bool blinkState = false;

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

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

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

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

  56.     // configure Arduino LED for
  57.     pinMode(LED_PIN, OUTPUT);
  58. }

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

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

  65.     // display tab-separated accel/gyro x/y/z values
  66.     Serial.print("a/g:\t");
  67.     Serial.print(ax); Serial.print("\t");
  68.     Serial.print(ay); Serial.print("\t");
  69.     Serial.print(az); Serial.print("\t");
  70.     Serial.print(gx); Serial.print("\t");
  71.     Serial.print(gy); Serial.print("\t");
  72.     Serial.println(gz);

  73.     // blink LED to indicate activity
  74.     blinkState = !blinkState;
  75.     digitalWrite(LED_PIN, blinkState);
  76. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2014-12-20 20:48:39 | 显示全部楼层
看看MPU6050上,SCL和SDA焊好了没,很可能是虚焊
回复 支持 反对

使用道具 举报

发表于 2014-12-21 00:31:22 | 显示全部楼层
先說清楚你用的是什麼板, 不是所有 arudino 板的 SDA/SCL 都是 A4/A5 的.
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-8 14:38 , Processed in 0.047799 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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