MPU6050初始化失败
-
/* Get all possible data from MPU6050 * Accelerometer values are given as multiple of the gravity [1g = 9.81 m/s²] * Gyro values are given in deg/s * Angles are given in degrees * Note that X and Y are tilt angles and not pitch/roll. * * License: MIT */ #include "Wire.h" #include <MPU6050_light.h> MPU6050 mpu(Wire); unsigned long timer = 0; void setup() { Serial.begin(115200); Wire.begin(18, 19); byte status = mpu.begin(); Serial.print(F("MPU6050 status: ")); Serial.println(status); while(status!=0){ Serial.println("Initial MPU6050 error!"); delay(1000); } // stop everything if could not connect to MPU6050 Serial.println(F("Calculating offsets, do not move MPU6050")); delay(1000); mpu.calcOffsets(true,true); // gyro and accelero Serial.println("Done!\n"); } void loop() { mpu.update(); if(millis() - timer > 1000){ // print data every second Serial.print(F("TEMPERATURE: "));Serial.println(mpu.getTemp()); Serial.print(F("ACCELERO X: "));Serial.print(mpu.getAccX()); Serial.print("\tY: ");Serial.print(mpu.getAccY()); Serial.print("\tZ: ");Serial.println(mpu.getAccZ()); Serial.print(F("GYRO X: "));Serial.print(mpu.getGyroX()); Serial.print("\tY: ");Serial.print(mpu.getGyroY()); Serial.print("\tZ: ");Serial.println(mpu.getGyroZ()); Serial.print(F("ACC ANGLE X: "));Serial.print(mpu.getAccAngleX()); Serial.print("\tY: ");Serial.println(mpu.getAccAngleY()); Serial.print(F("ANGLE X: "));Serial.print(mpu.getAngleX()); Serial.print("\tY: ");Serial.print(mpu.getAngleY()); Serial.print("\tZ: ");Serial.println(mpu.getAngleZ()); Serial.println(F("=====================================================\n")); timer = millis(); } }
-
需要修改MPU6050默认地址,文件MPU6050_light.h
// #define MPU6050_ADDR 0x68
#define MPU6050_ADDR 0x6a

-
@1223386926 在 MPU6050初始化失败 中说:
需要修改MPU6050默认地址,文件MPU6050_light.h
// #define MPU6050_ADDR 0x68
#define MPU6050_ADDR 0x6a

检测地址
#include "Wire.h" #include <MPU6050_light.h> void setup() { Serial.begin(115200); Wire.begin(18, 19); // 使用您的引脚 delay(1000); Serial.println("I2C Scanner Starting..."); } void loop() { byte error, address; int nDevices = 0; Serial.println("Scanning I2C bus..."); for(address = 1; address < 127; 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(" !"); if (address == 0x68 || address == 0x69) { Serial.println(">>> This is likely an MPU6050! <<<"); } nDevices++; } } if (nDevices == 0) { Serial.println("No I2C devices found!"); } else { Serial.println("Scan complete."); } Serial.println("-------------------"); delay(3000); } -
@1223386926 在 MPU6050初始化失败 中说:
@1223386926 在 MPU6050初始化失败 中说:
需要修改MPU6050默认地址,文件MPU6050_light.h
// #define MPU6050_ADDR 0x68
#define MPU6050_ADDR 0x6a

检测地址
#include "Wire.h" #include <MPU6050_light.h> void setup() { Serial.begin(115200); Wire.begin(18, 19); // 使用您的引脚 delay(1000); Serial.println("I2C Scanner Starting..."); } void loop() { byte error, address; int nDevices = 0; Serial.println("Scanning I2C bus..."); for(address = 1; address < 127; 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(" !"); if (address == 0x68 || address == 0x69) { Serial.println(">>> This is likely an MPU6050! <<<"); } nDevices++; } } if (nDevices == 0) { Serial.println("No I2C devices found!"); } else { Serial.println("Scan complete."); } Serial.println("-------------------"); delay(3000); }
-
@1223386926 改为0x6A虽然不会报错,但无法读取有效的数值。根本原因在于用错了库,不应该使用https://github.com/rfetick/MPU6050_light.git,而是应该https://github.com/fishros/MPU6050_light.git。
。
换完之后,就可以按教程中的代码读取数值:
