1. MPU数据获取
MPU6050 mpu; mpu.testConnection();//测试MPU是否连接成功 mpu.initialize(); mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); //获取加速度和陀螺仪数据 mpu.getAcceleration(&ax, &ay, &az); //获取加速度数据 mpu.getRotation(&gx, &gy, &gz); //获取陀螺仪数据
2. mpu的DMP初始化
MPU6050 mpu; mpu.testConnection();//测试MPU是否连接成功 mpu.initialize(); devStatus = mpu.dmpInitialize(); mpu.setXGyroOffset(220); mpu.setYGyroOffset(76); mpu.setZGyroOffset(-85); mpu.setZAccelOffset(1788); if (devStatus == 0) { mpu.setDMPEnabled(true); attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), dmpDataReady, RISING); mpuIntStatus = mpu.getIntStatus(); dmpReady = true; packetSize = mpu.dmpGetFIFOPacketSize(); }