Part

Nine-axis IMU, MPU-9250

An MPU6050 with a compass inside: set BYPASS_EN and the AK8963 answers at 0x0C. Drag it to tip it.

See every part
  • 10 pins
  • 4 settings
  • In 1 project
Drawn live by the editor's own code, at the size you see it.
Nine-axis IMU, MPU-9250 as drawn in the Mokxi simulator
At a glance

The Nine-axis IMU, MPU-9250 in brief

What it is, and every setting the properties panel gives it.

The MPU-9250 packs three sensors into one small package, usually sold on the GY-9250 board: an accelerometer, a gyroscope and a compass. The first two are the same design as the MPU6050 and answer at 0x68. The compass, an AK8963, is a second chip inside the package, hidden behind the first; a sketch sets the bypass bit and it appears on the same two wires at 0x0C. That is why an I2C scan of a fresh module shows only one address. In Mokxi you drag the board on the canvas to tip it and move a slider to turn it, so the accelerometer sees gravity shift between its axes and the compass sees the Earth’s field turn. The model gives WHO_AM_I as 0x71, reads the magnetometer at its datasheet scale, applies its sensitivity adjustment and leaves out the DMP, the FIFO, hard and soft iron effects and magnetic declination.

Family
Sensors
Pins
10
pitch
0
roll
0
heading
0
temperature
25
Pins

10 pins

Named as the editor names them, so a wire lands where you expect it.

Pin
Role
What it does
VCC
Input or output
Supply, 3.3 to 5 V (the board has a regulator).
GND
Input or output
Ground.
SCL
Input or output
The I2C bus. The accelerometer and gyroscope answer at 0x68.
SDA
Input or output
The I2C bus. The accelerometer and gyroscope answer at 0x68.
EDA
Input or output
The chip's auxiliary bus. Leave them.
ECL
Input or output
The chip's auxiliary bus. Leave them.
AD0
Input or output
High moves the address to 0x69. Pulled low on the board.
INT
Output
The interrupt output.
NCS
Input or output
SPI select and frame sync. Leave them.
FSYNC
Input or output
SPI select and frame sync. Leave them.
How to use it

How to read the MPU-9250 compass and tilt on an Arduino

The tilt compass project runs on a Mega, because asukiaaa’s library, its floating point and atan2() together outgrow what Mokxi allows an Uno example. Four wires: VCC to 5 V (the board has a regulator), GND to GND, SDA to the Mega’s SDA (pin 20) and SCL to SCL (pin 21). AD0 stays unwired, so the motion sensor is at 0x68.

imu.beginAccel() starts the accelerometer, and imu.beginMag() sets the bypass so the AK8963 answers. Each loop, accelUpdate() and magUpdate() return 0 when they have fresh numbers. Pitch and roll come from atan2 of the accelerometer axes; magHorizDirection() is the angle of north from the chip’s X axis. Drag the heading slider and the direction follows. Then tip the board: the heading changes too, because the Earth’s field also points down into the ground, and only a tilt-compensated calculation, using the accelerometer, removes that.

Part pin
Board pin
VCC
5 V
GND
GND
SDA
SDA (pin 20 on the Mega)
SCL
SCL (pin 21 on the Mega)
AD0
Not wired: address 0x68

On an ESP32 the same sketch fits with room to spare; Wire uses GPIO 21 and 22 unless you name other pins.

Arduino Mega: MPU-9250 tilt compasslive0.000 s 0.00x
Click to open it in the editor
This is the simulator itself, running here. Click anything to open it in the editor.
Tilt and heading, from the tilt compass sketch
imu.setWire(&Wire);
imu.beginAccel(ACC_FULL_SCALE_2_G);
imu.beginMag();               // sets the bypass: the AK8963 at 0x0C

if (imu.accelUpdate() == 0) {
  float pitch = atan2(-imu.accelX(), imu.accelZ()) * 180.0 / PI;
}
if (imu.magUpdate() == 0) {
  float heading = imu.magHorizDirection();
}
Common errors

Common Nine-axis IMU, MPU-9250 errors and fixes

What goes wrong
The fix
An I2C scan finds only 0x68, and the magnetometer reads nothing.
The AK8963 is behind the motion sensor until BYPASS_EN, bit 1 of register 0x37, is set. beginMag() in asukiaaa’s library does it; with raw Wire calls, write that bit first.
The heading drifts when the board is not flat.
magHorizDirection() assumes a level board. Hold it flat, or compensate the magnetometer reading with pitch and roll from the accelerometer.
Nothing answers at 0x68.
Check AD0. Pulled high it moves the chip to 0x69, and the library has to be told.
The compass points a few degrees off true north.
The chip measures magnetic north. Add your local declination in code; the model does not apply one.
Questions

Questions and answers

What is the difference between the MPU-9250 and the MPU6050?

The MPU-9250 adds a three-axis magnetometer, so it can find north as well as down. Its accelerometer and gyroscope registers match the MPU6050’s, and WHO_AM_I reads 0x71 instead of 0x68.

Which Arduino library reads the MPU-9250 here?

asukiaaa’s MPU9250 library, included as MPU9250_asukiaaa.h, is the one the tilt compass uses. Any library that reaches the compass through the bypass, as most do, finds it the same way.

Does the simulator run the MPU-9250’s DMP?

No. The digital motion processor, the FIFO and the chip’s own auxiliary I2C master are left out; sketches read the raw registers and do the math themselves.

Why does the tilt compass project use a Mega and not an Uno?

The library, floating point and atan2() make the program larger than Mokxi allows a built-in Uno example. A real Uno can run a trimmed version; the wiring is the same.

How it is modeled

What is true about the Nine-axis IMU, MPU-9250, here

In its help article’s own words: what the simulation gets right, and where it stops.

Modeled

From the MPU-9250 register map: the MPU-6050's accelerometer, gyroscope and temperature registers, WHO_AM_I reading 0x71, and the chip awake at power-up. From the AK8963 datasheet: WIA 0x48, the field low byte first at 0.15 uT a count (0.6 at 14 bits), DRDY, single and continuous modes, ST2 ending a read, and the fuse ROM's sensitivity adjustment. The magnetometer's axes are turned from the accelerometer's as the register map draws them, and the Earth's field is 20 uT north and 45 uT down.

Not modeled

The DMP and the FIFO, the auxiliary I2C master (use the bypass, as every Arduino library does), SPI, self test, noise, bias, hard and soft iron, and magnetic declination. The adjustment values are 128, a factor of one.

From MPU-9250 nine-axis IMU, in full.

Projects

See the Nine-axis IMU, MPU-9250 in a project

One built-in project uses it. It opens in the editor, already wired.

Boards

The boards it is shown on

This board has a built-in project with the Nine-axis IMU, MPU-9250 in it.

Wire up the Nine-axis IMU, MPU-9250

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.