Unlocking the GY-91 (MPU-9250 + BMP-280)

The GY-91 is a 9-axis inertial measurement unit (IMU) composed of a 3-axis gyroscope, 3-axis Accelerometer and 3-axis Magnetometer-which are contained in the MPU-9250 (there is also a temperature sensor by the way-but usually it’s not used). On top of the MPU-9250 chip, the GY-91 incorporates a BMP-280 barometer (which also has a temperature sensor!). Though all these functionalities are great (and the chip itself is relatively inexpensive), it has minimal documentation (though you can take a look at MPU-9250 and BMP-280 datasheets individually), with next to no supported code/examples. So after a bit of tinkering with Ardublock (I’m a visual coder by the way) I masked the chip as a MPU-6050-but this limited my access to just the gyro and accelerometer. Then, I decided to solve this problem once and for all in the following code, which can read all axes of the GY-91 chip and put the values in a serial monitor. The base code can then be used for more useful projects (too bad I don’t know C++) This is it:

/**
 @file read9axis.ino
 @brief This is an Example for the FaBo 9Axis I2C Brick.

   http://fabo.io/202.html

   Released under APACHE LICENSE, VERSION 2.0

   http://www.apache.org/licenses/

 @author FaBo<info@fabo.io>
*/

#include <Wire.h>
#include <FaBo9Axis_MPU9250.h>
#include <Wire.h>
#include "i2c.h"
#include "i2c_BMP280.h"

BMP280 bmp280;
FaBo9Axis fabo_9axis;

void setup() {
  Serial.begin(9600);
  Serial.println("RESET");
  Serial.println();

    Serial.print("Probe BMP280: ");
    if (bmp280.initialize()) Serial.println("Sensor found");
    else
    {
        Serial.println("Sensor missing");
        while (1) {}
    }

    // onetime-measure:
    bmp280.setEnabled(0);
    bmp280.triggerMeasurement();
  Serial.println("configuring device.");

  if (fabo_9axis.begin()) {
    Serial.println("configured FaBo 9Axis I2C Brick");
  } else {
    Serial.println("device error");
    while(1);
  
  }
}

void loop() {
  float ax,ay,az;
  float gx,gy,gz;
  float mx,my,mz;
  float temp;

  fabo_9axis.readAccelXYZ(&ax,&ay,&az);
  fabo_9axis.readGyroXYZ(&gx,&gy,&gz);
  fabo_9axis.readMagnetXYZ(&mx,&my,&mz);
  fabo_9axis.readTemperature(&temp);
    bmp280.awaitMeasurement();

  float temperature;
  bmp280.getTemperature(temperature);

  float pascal;
  bmp280.getPressure(pascal);

  static float meters, metersold;
  bmp280.getAltitude(meters);
  metersold = (meters);

  bmp280.triggerMeasurement();
    
  Serial.print("AccX: ");
  Serial.print(ax);
  Serial.print(" AccY: ");
  Serial.print(ay);
  Serial.print(" AccZ: ");
  Serial.println(az);

  Serial.print("GyX: ");
  Serial.print(gx);
  Serial.print(" GyY: ");
  Serial.print(gy);
  Serial.print(" GyZ: ");
  Serial.println(gz);

  Serial.print("MagX: ");
  Serial.print(mx);
  Serial.print(" MagY: ");
  Serial.print(my);
  Serial.print(" MagZ: ");
  Serial.println(mz);

  Serial.print("Temp: ");
  Serial.println(temp);

  Serial.print(" HeightPT1: ");
  Serial.print(metersold);
  Serial.print(" m; Height: ");
  Serial.print(meters);
  Serial.print(" Pressure: ");
  Serial.print(pascal);
  Serial.print(" Pa; T: ");
  Serial.print(temperature);
  Serial.println(" C");

  delay(1000);
}

I know almost in C++ (but I’ll be learning MicroPython soon ;)), so for those of you who master it (which should be like 99.9999% of you), feel free to edit, develop and improve this code. :slight_smile: By the way, don’t forget to download all the associated MPU-9250 (FaBo 202 9-axis library) and BMP-280 (I2C-Sensor-Lib iLib) libraries in you Arduino Editor. Also, I used an Arduino Uno board for this project (Pinout: VIN → 5v, GND → GND, SCL → SCL/A5, SDA → SDA/A4), so I don’t GUARANTEE that this will work on other boards (but hopefully it does)…

Duplicate post deleted.

Great post, thumbs up. Thank you