MPU-9255 Module: Gyroscope, Accelerometer and Magnetometer Applications

Overview:

An MPU (microprocessor unit) is a device that implements the core elements of a computer system on a single integrated circuit, or as a few integrated circuits operating as a cohesive unit, designed for processing digital data. An MPU-9255 (and other similar circuits) is a multi-chip module (MCM) that houses a 3-axis gyroscope, accelerometer and magnetometer.

This tutorial will explore the functions of the MPU-9255 module using Arduino, where the module will sense or detect its movement, acceleration and the nearest magnetic field. A secondary measurement for the temperature is included.

 

Hardware Used:

Arduino UNO


MPU-9255 9DOF 9-axis Inertial MPU


Jumper Wires


Software Used:

Arduino IDE

 

Application Discussion

The MPU-9250 is a multi-chip module (MCM) consisting of two dies integrated into a single QFN package. It is a 9-axis motion tracking device that combines a 3-axis gyroscope, 3-axis accelerometer, 3-axis magnetometer, and a Digital Motion Processor. With a dedicated Inter-Integrated Circuit (I2C) sensor bus, the MPU-9250 directly provides complete 9-axis Motion Fusion output. The sensor and interrupt registers may be read using Serial Peripheral Interface (SPI) as well.

This tutorial aims to teach you the basic functions of an MPU9255 module. Using Arduino, you can find how its accelerometer, gyroscope and magnetometer work by monitoring the module and how it reacts to movements in specific directions and proximity to sensitive areas. A temperature sensor is also optionally included to showcase its secondary functions.

MPU-9255 9DOF 9-axis Inertial MPU (3-in-1: Gyroscope, Accelerometer, Magnetometer I2C/SPI)

 

Description

This is an MPU9250, which is a multi-chip module (MCM) consisting of two dies integrated into a single QFN package. One die houses the 3-Axis gyroscope and the 3-Axis accelerometer. The other die houses the AK8963 3-Axis magnetometer from Asahi Kasei Microdevices Corporation. Hence, the MPU-9250 is a 9-axis Motion Tracking device that combines a 3-axis gyroscope, 3-axis accelerometer, 3-axis magnetometer, and a Digital Motion Processor (DMP). The MPU-9250 also features an embedded temperature sensor.

This module includes pull-up resistors on the SDA, SCL, and nCS lines, pull-down resistors on the FSYNC and AD0 lines, and an on-board 3.3V voltage regulator allowing you to power the module from 5V sources such as an Arduino. If you desire to power the module from 3.3V you can bridge the solder jumper next to the voltage regulator to bypass the regulator (refer to schematic link here).

Product Content:

    • 1 piece – MPU-9250 Module
    • 1 piece – Ten pin male header (1×10)
Specifications:
    • On-board pull-up resistors on SDA, SCL, and nCS
    • On-board pull-down resistors on FSYNC and AD0
    • 3-Axis Accelerometer
        • Range: up to ± 16 g
        • Sensitivity: up to 16,384 LSB/g
    • 3-Axis Gyroscope
        • Range: up to ± 2000 deg/sec
        • Sensitivity: up to 131 LSB/deg/sec
    • 3-Axis Magnetometer
        • Range: ± 4800 µT
        • Sensitivity: 0.6 µT/LSB
    • Supply Voltage: 4.4 to 6.5 V or 3.3V if you solder the solder jumper near the on-board voltage regulator
    • Interface: I2C
    • I2C Address: 0x68 by default, 0x69 if AD0 is pulled high
    • Board Dimensions: 25.5mm (1.004″) long x 15.4mm (0.606″) wide, 3mm (0.118″) inside diameter of mounting holes
    • Weight: 2.72g (0.096oz)

 

Hardware Setup

MPU9255 Module

Actual Setup

Fritzing Diagram

 

Schematic Diagram

 

Pin Configuration

Arduino UNO pins

PIN A4  => MPU module SDA (YELLOW)

PIN A5  => MPU module SCL (GREEN)

GND     => MPU module GND (BLACK)

VCC     => MPU module VCC (RED)

Software Setup:

The Arduino Codes for the application can be downloaded here or you can copy the code down below. You must also download and import the MPU9250 library, which is provided by Robojax and provided here. After uploading the code, open the Serial Monitor to view the progress of the module. Search the Tools bar to select it or simply press Ctrl+Shift+M. To see the effects of the module properly, change the baud to the required amount (115200 baud).

MPU9255 Module

#include <MPU9250.h>

#include "MPU9250.h"

// an MPU9250 object with the MPU-9250 sensor on I2C bus 0 with address 0x68
MPU9250 IMU(Wire,0x68);
int status;

void setup() {
  // serial to display data
  Serial.begin(115200);
  while(!Serial) {}

  // start communication with IMU
  status = IMU.begin();
  if (status < 0) {
    Serial.println("IMU initialization unsuccessful");
    Serial.println("Check IMU wiring or try cycling power");
    Serial.print("Status: ");
    Serial.println(status);
    while(1) {}
  }
}

void loop() {
  // read the sensor
  IMU.readSensor();
  // display the data
  Serial.print("AccelX: ");
  Serial.print(IMU.getAccelX_mss(),6);
  Serial.print("  ");
  Serial.print("AccelY: ");  
  Serial.print(IMU.getAccelY_mss(),6);
  Serial.print("  ");
  Serial.print("AccelZ: ");  
  Serial.println(IMU.getAccelZ_mss(),6);
 
  Serial.print("GyroX: ");
  Serial.print(IMU.getGyroX_rads(),6);
  Serial.print("  ");
  Serial.print("GyroY: ");  
  Serial.print(IMU.getGyroY_rads(),6);
  Serial.print("  ");
  Serial.print("GyroZ: ");  
  Serial.println(IMU.getGyroZ_rads(),6);

  Serial.print("MagX: ");  
  Serial.print(IMU.getMagX_uT(),6);
  Serial.print("  ");  
  Serial.print("MagY: ");
  Serial.print(IMU.getMagY_uT(),6);
  Serial.print("  ");
  Serial.print("MagZ: ");  
  Serial.println(IMU.getMagZ_uT(),6);
 
  Serial.print("Temperature in C: ");
  Serial.println(IMU.getTemperature_C(),6);
  Serial.println();
  delay(200);
}

Code Breakdown:

MPU9255 Module

#include <MPU9250.h>
  • Includes the MPU9250.h library in the code.
Serial.begin(115200);
  while(!Serial) {}
  • Displays data on the Serial Monitor.
status = IMU.begin();
  if (status < 0) {
    Serial.println("IMU initialization unsuccessful");
    Serial.println("Check IMU wiring or try cycling power");
    Serial.print("Status: ");
    Serial.println(status);
    while(1) {}
  • Checks the status of the MPU module.
  • Checks if the module is connected or not.

 

Video Output

 

 

Conclusion

MPU modules are good circuit boards that can analyze and measure a multitude of variables and their sensitivity means that they need to be taken care of properly to function well.

 

References

https://robojax.com/learn/arduino/?vid=robojax-MPU9250

AccelerometerArduinoArduino unoGyroscopeMagnetometerMpuMpu9255

Leave a comment

All comments are moderated before being published