MPU 9250 IMU sensor reading

The MPU-9250 is a System in Package (SiP) that combines two chips: the MPU-6500, which contains a 3-axis gyroscope, a 3-axis accelerometer, and an onboard Digital Motion Processor (DMP) capable of processing complex MotionFusion algorithms; and the AK8963, the market leading 3-axis digital compass.

The sensor can be controlled via the I2C interface. The wiring between the sensor and the Arduino is as follow:

Image from:

Sensor reading implementation is pretty forward since library for Arduino is already available. Example:

#include <Wire.h>

#include <MPU9250.h>

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for SparkFun breakout and InvenSense evaluation board)
// AD0 high = 0x69
MPU9250 mpu;

void setup() 
    Wire.setClock(400000); // 400kHz I2C clock.
    int status = mpu.initialize();
    status = mpu.initialize();
    if (status == MPU_OK)
        log(LOG_INFO, "IMU is initialized. Calibrating accel + gyro. Dont move the robot");
        log(LOG_ERR, "Cannot initialize IMU device, status: %d", status);

void loop()
    // read mpu raw data
    float gx = mpu.getGyro(0);
    float gy = mpu.getGyro(1);
   float gz = mpu.getGyro(2);

    float ax = mpu.getAcc(0);
    float ay = mpu.getAcc(1);
    float az = mpu.getAcc(2);

    float mx = mpu.getMag(0);
    float my = mpu.getMag(1);
    float mz = mpu.getMag(2);

Detail implementation can be found in the Arduino JETTY.ino code base. The IMU sensor data is a part of the 47 bytes COBS data frame which will be bring up to ROS for high level control.


The comment editor supports Markdown syntax. Your email is necessary to notify you of further updates on the discussion. It will be hidden from the public.
Powered by antd server, (c) 2019 - 2024 Dany LE