【问题标题】:MPU6050, No I2C devices found, arduino nanoMPU6050,未找到 I2C 设备,arduino nano
【发布时间】:2018-08-25 10:22:31
【问题描述】:

我收到了一个传感器(加速度计 mpu6050),但我无法使用它。经过几次测试,我尝试用它做一个基本测试,看看 I2C 扫描器是否可以看到它,而我知道它的地址是 0x68 或 0x69。

但是,我收到了这条消息:

Scanning... No I2C devices found

我正在使用 arduino Nano

Mpu6050 -> Arduino Nano

VCC -> 5V(但我也试过 3.3V)

GRND -> GRND

SCL -> A5

SDA -> A4

ADO -> GRND

INT -> D2

我使用的代码(基本代码在网上找了好几次)

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
// 
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#define ADXL_SCL A5
#define ADXL_SDA A4
#include <Wire.h>


void setup()
{
  Wire.begin();
  digitalWrite(ADXL_SDA, LOW);
  digitalWrite(ADXL_SCL, LOW);
  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ ) 
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4) 
    {
      Serial.print("Unknown error at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

如有必要,这里是我用来尝试使 mpu6050 工作的代码(也是基本代码):

// MPU-6050 Short Example Sketch
// By Arduino User JohnChi
// August 17, 2014
// Public Domain
#include<Wire.h>
const int MPU_addr=0x69;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(9600);
}
void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)    
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
  Serial.print("AcX = "); Serial.print(AcX);
  Serial.print(" | AcY = "); Serial.print(AcY);
  Serial.print(" | AcZ = "); Serial.print(AcZ);
  Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
  Serial.print(" | GyX = "); Serial.print(GyX);
  Serial.print(" | GyY = "); Serial.print(GyY);
  Serial.print(" | GyZ = "); Serial.println(GyZ);
  delay(333);
}

结果:

AcX = -1 | AcY = -1 | AcZ = -1 | Tmp = 36.53 | GyX = -1 | GyY = -1 | GyZ = -1
AcX = -1 | AcY = -1 | AcZ = -1 | Tmp = 36.53 | GyX = -1 | GyY = -1 | GyZ = -1
AcX = -1 | AcY = -1 | AcZ = -1 | Tmp = 36.53 | GyX = -1 | GyY = -1 | GyZ = -1
AcX = -1 | AcY = -1 | AcZ = -1 | Tmp = 36.53 | GyX = -1 | GyY = -1 | GyZ = -1
AcX = -1 | AcY = -1 | AcZ = -1 | Tmp = 36.53 | GyX = -1 | GyY = -1 | GyZ = -1
AcX = -1 | AcY = -1 | AcZ = -1 | Tmp = 36.53 | GyX = -1 | GyY = -1 | GyZ = -1

非常感谢您的帮助和反馈,因为这真的很令人沮丧。我正在使用在许多教程中都可以使用的知名程序代码。

谢谢。

【问题讨论】:

    标签: arduino arduino-uno mpu6050


    【解决方案1】:

    来自官方datasheet

    6.4 电气规格,续

    您将 AD0 接地,从而将设备的地址更改为 0x68 而不是 0x69。将代码中的 i2c_addr 更改为 0x68,一切都必须按预期工作。

    此外,数据表显示此传感器的工作电压为 2.375V - 3.46V。我不知道您使用的是带有内置电压调节器的电路板,但如果没有 - 给这个传感器施加 5V 电压绝对不是一个好主意。可能您已经烧毁了传感器。

    【讨论】:

    • 确实我把它烧了...我买了 2 个新传感器。我使用了相同的代码,并且首先使用了 3.3 伏电压,并且成功了。这个传感器似乎没有调节器。谢谢大家!
    【解决方案2】:

    我看到你没有做Wire.setClock()。我在使用这个传感器时遇到了同样的问题,直到我在代码中添加以下内容之前,我无法让它工作,就在 Wire.begin() 之前:

    Wire.setClock(100000);

    试试看它是否有效。如果没有,也尝试 400000 代替。

    【讨论】:

      猜你喜欢
      • 2020-08-16
      • 2022-07-03
      • 1970-01-01
      • 2022-07-11
      • 2017-04-21
      • 2019-07-11
      • 2014-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多