Reefwing MPU6000/MPU6500 IMU Arduino Library

David Such
5 min readJul 10, 2023

While testing our updated Attitude and Heading Reference System (AHRS) library with a variety of IMUs, we found that there were not a lot of options for the MPU6500. The most popular library appears to be fastIMU, which supports a LOT of different IMU sensors. Unfortunately for us, this library includes a Quaternion structure which clashes with our Quaternion class in imuTypes. Also, it doesn’t provide a time stamp for each sensor reading which we use when displaying the data using the xIMU3 application. So we decided to publish our own version. The Reefwing MPU-6x00 Library can be downloaded via the Arduino IDE Library Manager or directly from our GitHub Repository.

Figure 1. The Arduino Portenta H7 Flight Stack

In an effort to not reinvent the wheel, our library is a fork of the MPU6x00 Library by Simon D. Levy. This is a simple, header-only Arduino library for the InvenSense/TDK MPU6000 and MPU6500 inertial measurement units (IMU) using the SPI bus.

It has been modified to use the Reefwing imuTypes library header to make it compatible with the Reefwing AHRS Library and allow easy graphing of IMU values via the Reefwing xIMU3 data visualisation library. We have also added a method to get the sensor temperature, imu.getTemp(), since it was already being read when imu.readSensor() is called. The other methods added include:

  • bool dataAvailable() — Can be used to poll the IMU and detect if new sensor readings are available. This is useful if you haven’t wired up the IMU interrupt pin.
  • void getTemp(float & t) — Loads the IMU chip temperature in celsius into t).
  • void getCalibratedGyro(float & gx, float & gy, float & gz) — Loads the calibrated gyro values for the x, y, and z-axis into gx, gy, and gz. You need to call calibrateAccelGyro() first.
  • void getCalibratedAccel(float & ax, float & ay, float & az) — Loads the calibrated accelerometer values for the x, y, and z-axis into ax, ay, and az. You need to call calibrateAccelGyro() first.
  • BiasOffsets getGyroOffsets() — Returns the x, y…

--

--

David Such

Reefwing Software · Embedded Systems Engineer · iOS & Android Development · Robotics · Drones · Arduino · Raspberry Pi · Flight Control