乐鑫技术交流
直播中

周煌煦

8年用户 1066经验值
私信 关注
[问答]

MPU6050读取问题求解

首先我初始化它
代码:全选uint8_t MPU6050_Init(uint8_t slave_addr)
{
    uint8_t result;

    Wire.setClock(400000);
    Wire.begin();
     
    // initialize device
    Serial.println("Initializing MPU6050...");
    mpu.initialize();

    // verify connection
    result = mpu.testConnection();
    if (result)
        Serial.println("Connection successful");
    else
    {
        Serial.println("Connection failed");
        return result;
    }

    // load and configure the DMP
    Serial.println("Initializing DMP...");
    result = mpu.dmpInitialize();

    //At this point I get
    //            X Accel  Y Accel  Z Accel   X Gyro   Y Gyro   Z Gyro
    //OFFSETS    -3484,   -5361,     768,      33,     -36,      31
    // supply your own gyro offsets here, scaled for min sensitivity
    mpu.setXGyroOffset(33);
    mpu.setYGyroOffset(-36);
    mpu.setZGyroOffset(-31);
    mpu.setXAccelOffset(-3484);
    mpu.setYAccelOffset(-5361);
    mpu.setZAccelOffset(768); // 1688 factory default for my test chip

    // make sure it worked (returns 0 if so)
    if (result == 0)
    {
        // Calibration Time: generate offsets and calibrate our MPU6050
        mpu.CalibrateAccel(6);
        mpu.CalibrateGyro(6);
        mpu.PrintActiveOffsets();
        // turn on the DMP, now that it's ready
        Serial.println("Enabling DMP...");
        mpu.setDMPEnabled(true);

        result = mpu.getIntStatus();

        // set our DMP Ready flag so the main loop() function knows it's okay to use it
        Serial.println("DMP ready! Waiting for first interrupt...");
        dmpReady = true;

        // get expected DMP packet size for later comparison
        packetSize = mpu.dmpGetFIFOPacketSize();
    }
    else
    {
        // ERROR!
        // 1 = initial memory load failed
        // 2 = DMP configuration updates failed
        // (if it's going to break, usually the code will be 1)
        Serial.print("DMP Initialization failed (code ");
        Serial.print(result);
        Serial.println(")");
    }

    return result;
}


更多回帖

发帖
×
20
完善资料,
赚取积分