我正在为我的项目使用mpu6050,但它显示了以下错误测试设备连接...MPU6050连接失败仅当iI尝试使用MPU6050的对象时才显示此错误,但当我不使用MPU6050的实例而使用Wire库时(如follow),它可以工作-
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);请帮帮我
发布于 2021-05-26 18:00:48
我也有同样的问题。
问题来自MPU6050.cpp文件中的这些行。您可以在sketchbook文件夹中找到它。为此:打开Arduino IDE,然后选择File > Preferences > Sketchbook location。
//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函数
//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函数以返回true,这对我来说很有效。
//I2Cdev device library code is placed under the MIT license
//Copyright (c) 2012 Jeff Rowberg
bool MPU6050::testConnection() {
return true;
}发布于 2022-02-03 00:23:52
问题是设备标识符不是0x34 (在我的例子中是0x39)。为了不“作弊”,我做了以下更改:注释掉这一行:
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");并插入以下代码行:
Serial.print("DeviceID: ");
Serial.println(accelgyro.getDeviceID());因此,程序将写入设备标识符,而不是给出它没有找到设备0x34的响应。
https://stackoverflow.com/questions/67681830
复制相似问题