jdvr1994 / MPU9250PhotonLibrary

This is a library of MPU9250 devices (Inertial and Magnetic Array Sensors) for Particle Photon
GNU General Public License v3.0
2 stars 1 forks source link

MPU9250Library

This is a library of MPU9250 devices (Inertial and Magnetic Array Sensors) for Particle Photon

Supported MPU9250 devices

Usage

Set up the hardware:

Flash the mpu9250 example.

Adapt it to your needs while keeping this general structure:

MPU9250 margSensor();
int16_t dataSensor[10];

void setup() {
  margSensor.begin();
}
void loop() {
  margSensor.Read9Axis(dataSensor);
  // The sensor values is stored in dataSensor[x] as follows:
  // dataSensor[0] ~ dataSensor[2] (Acceleration X Axis - Acceleration Y Axis - Acceleration Z Axis)
  // dataSensor[3] (Temperature)
  // dataSensor[4] ~ dataSensor[6] (AngularRate X Axis - AngularRate Y Axis - AngularRate Z Axis)
  // dataSensor[7] ~ dataSensor[9] ( MagneticComponent X Axis - MagneticComponent Y Axis - MagneticComponent Z Axis)
}

Documentation

MPU9250

// IMPORTANT: Create dataSensor array for to store all readings
int16_t dataSensor[10];

begin

margSensor.begin();

Sets up the the operating mode of mpu9250 devices.

getGyroOffsets

int16_t GyroOffsets[3]; //we will save the readings of the offsets in this array
margSensor.getGyroOffsets(GyroOffsets);
Serial.printlnf("GyroOffset X:  %d", GyroOffsets[0]);
Serial.printlnf("GyroOffset Y:  %d", GyroOffsets[1]);
Serial.printlnf("GyroOffset Z:  %d", GyroOffsets[2]);

This function allows us to read the offsets gyroscope Register and store them in the pointer GyroOffsets

getAccelOffsets

int16_t AccelOffsets[3]; //we will save the readings of the offsets in this array
margSensor.getAccelOffsets(AccelOffsets);
Serial.printlnf("AccelOffset X:  %d", AccelOffsets[0]);
Serial.printlnf("AccelOffset Y:  %d", AccelOffsets[1]);
Serial.printlnf("AccelOffset Z:  %d", AccelOffsets[2]);

This function allows us to read the offsets accelerometer Register and store them in the pointer AccelOffsets

setGyroOffsetX

setGyroOffsetY

setGyroOffsetZ

int16_t gxOffset = 543;
int16_t gyOffset = 25;
int16_t gzOffset = -78;

margSensor.setGyroOffsetX(gxOffset);
margSensor.setGyroOffsetY(gyOffset);
margSensor.setGyroOffsetZ(gzOffset);

These functions set up gyroscope offset register.

setAccelOffsetX

setAccelOffsetY

setAccelOffsetZ

int16_t axOffset = 2890;
int16_t ayOffset = -13125;
int16_t azOffset = -768;

margSensor.setAccelOffsetX(axOffset);
margSensor.setAccelOffsetY(ayOffset);
margSensor.setAccelOffsetZ(azOffset);

These functions set up accelerometer offset register.

setGyroScale

/* ============================
    Select Gyroscope Scale:
    0 = ±250dps =
    1 = ±500 dps =
    2 = ±1000 dps =
    3 = ±2000 dps =
    ===============================*/
 margSensor.setGyroScale(3);// +-2000 dps

This function set up gyroscope scale register.

setAccelScale

/* ============================
    Select Accelerometer scale:
    0 = ±2g
    1 = ±4g
    2 = ±8g
    3 = ±16g
    ===============================*/
 margSensor.setAccelScale(1);// +-4g

This function set up accelerometer scale register.

Nuances

References

License

Copyright 2018-2022 JDVR, Juan David Velasquez Rosero

Released under the LGPL license