簡體   English   中英

Mpu6050 連接失敗

[英]Mpu6050 Connection failed

我正在為我的項目使用 mpu6050,但它顯示以下錯誤 - 測試設備連接... MPU6050 連接失敗此錯誤僅在我嘗試使用 MPU6050 的 object 但當我不使用 MPU6050 實例並使用 Wire 庫時顯示相反(如跟隨)它有效 -

Wire.begin();                      // Initialize communication
Wire.beginTransmission(MPU);       // Start communication with MPU6050 // MPU=0x68
Wire.write(0x6B);                  // Talk to the register 6B
Wire.write(0x00);                  // Make reset - place a 0 into the 6B register
Wire.endTransmission(true);        //end the transmission

但我想使用這段代碼 -

 mpu.initialize(); //start MPU
 Serial.println(F("Testing device connections...")); //debugging serial statement
 Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));
// supply your own gyro offsets here, scaled for min sensitivity
  mpu.setXGyroOffset(0);
  mpu.setYGyroOffset(0);
  mpu.setZGyroOffset(0);
  mpu.setZAccelOffset(1688);

請幫我

我有同樣的問題。

問題來自 MPU6050.cpp 文件中的那些行。 你可以在你的速寫本文件夾中找到它。 為此:打開 Arduino IDE 然后文件 > 首選項 > 速寫本位置。

//I2Cdev device library code is placed under the MIT license
//Copyright (c) 2012 Jeff Rowberg

/** Verify the I2C connection.
 * Make sure the device is connected and responds as expected.
 * @return True if connection is valid, false otherwise
 */
bool MPU6050::testConnection() {
    return getDeviceID() == 0x34;
}

這是getDeviceId function

//I2Cdev device library code is placed under the MIT license
//Copyright (c) 2012 Jeff Rowberg

/** Get Device ID.
 * This register is used to verify the identity of the device (0b110100, 0x34).
 * @return Device ID (6 bits only! should be 0x34)
 * @see MPU6050_RA_WHO_AM_I
 * @see MPU6050_WHO_AM_I_BIT
 * @see MPU6050_WHO_AM_I_LENGTH
 */
uint8_t MPU6050::getDeviceID() {
    I2Cdev::readBits(devAddr, MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, buffer);
    return buffer[0];
}

我剛剛修改了 testConnection function 以返回 true,它對我有用。

//I2Cdev device library code is placed under the MIT license
//Copyright (c) 2012 Jeff Rowberg

bool MPU6050::testConnection() {
    return true;
}

問題是設備標識符不是 0x34(在我的例子中是 0x39)。 為了不“作弊”,我做了以下更改: 注釋掉這一行: // Serial.println(accelgyro.testConnection()? "MPU6050 connection successful": "MPU6050 connection failed");

並插入這些行: Serial.print("DeviceID: "); Serial.println(accelgyro.getDeviceID());

因此程序將寫入設備標識符,而不是給出未找到設備 0x34 的響應。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM