getting input from mpu9150

Hi all!

I'm trying to use an MPU9150. I've got the attached scatch working, and it's getting the accelerations right (calculating the constant to devide the acc input by was easy, as one axis will always sense a 9.87 m/s^2 acceleration when stationary)
But I can't figure out how to get the angular velocity right.

I found some scatches online, but most of them already have the integration and everything inside, while I just need the acceleration and angular velocity. I would love a simple explanation of how to do that :slight_smile:

another problem is that I don't get any input at all from the magnetometer. I'm getting -1 on all axes, no matter what I do. did anyone else have this problem?

/*
 * mpu->arduino
 * VCC->3.3V
 * GND->GND
 * SCL->A5
 * SDA->A4
 * AD0->3.3V
 * INT->2 
 */


#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"

MPU6050 IMU;

int16_t ax, ay, az;
int16_t gx, gy, gz;
int16_t mx, my, mz; //variables for the input from the sensor

double axr, ayr, azr;
double gxr, gyr, gzr;
double mxr, myr, mzr; //variables for the calculated measurements (i.e. real acceleration)

void setup() {
  Serial.begin(9600);
  IMU.initialize();
  bool connectionSuccessful = IMU.testConnection();
}

void loop() {
    
    IMU.getMotion9(&ax, &ay, &az, &gx, &gy, &gz, &mx, &my, &mz);
    axr=double(ax)/1580;
    ayr=double(ay)/1580;
    azr=double(az)/1580;
    Serial.print("a/g/m:\t");
    Serial.print(axr); Serial.print("\t");
    Serial.print(ayr); Serial.print("\t");
    Serial.print(azr); Serial.print("\t");
    Serial.print(gx); Serial.print("\t");
    Serial.print(gy); Serial.print("\t");
    Serial.print(gz); Serial.print("\t");
    Serial.print(mx); Serial.print("\t");
    Serial.print(my); Serial.print("\t");
    Serial.println(mz);

}

Thanks for your help!

You are evidently using code written for the MPU-6050. Is it fully compatible with the MPU-9150?

In the device data sheet, the gyroscope sensitivity is given in LSB/ (degrees/sec). Divide the output value for each axis by the appropriate sensitivity, which depends on whatever range you have selected.

As jremington has stated, you are using the MPU6050 library. I'm not sure the getMotion9 function is gonna be valid for the MPU9150.

There's a library you can use that's focused on the MPU9150. https://github.com/richards-tech/RTIMULib-Arduino. It has different filters intregrated (i.e. kalman filter). Calibration for acc, gyro and compass.
Although the library has become no longer supported since the end of last July, it's probably the most up-to-date and complete library for the MPU9150.

I myself am starting a project with the MPU9150, so we can be in touch.

Thanks jremington, I'll try it out.

Viper_Scull:
As jremington has stated, you are using the MPU6050 library. I'm not sure the getMotion9 function is gonna be valid for the MPU9150.

There's a library you can use that's focused on the MPU9150. https://github.com/richards-tech/RTIMULib-Arduino. It has different filters intregrated (i.e. kalman filter). Calibration for acc, gyro and compass.
Although the library has become no longer supported since the end of last July, it's probably the most up-to-date and complete library for the MPU9150.

I myself am starting a project with the MPU9150, so we can be in touch.

Thanks for the tip, but I'd actually rather write the whole thing (Kalman filter included) myself, so getting a larger, more extensive library, to me, is quite counter productive.
If I had an even simpler code from which I could easily learn how to read and write from and to the mpu9150 that would have been great (inertial navigation I understand.. serial communication and reading the sensor's datasheet is where I'm stuck)

EDIT:
I just now found this scatch, which is way easier to understand:

Now I'm getting something from the magnetometer, but as the OP noted in the link, the values are the same for all axes. If you have any idea how to solve this problem I'd love to hear :slight_smile:

I'd actually rather write the whole thing (Kalman filter included) myself, so getting a larger, more extensive library, to me, is quite counter productive

Yet you are taking someone else's code from the web and expecting it to function correctly, without understanding it.

To work properly with any device, it is essential that you study the device data sheet and make certain that you understand the purpose of every single line in the code you are using.

jremington:
Yet you are taking someone else's code from the web and expecting it to function correctly, without understanding it.

To work properly with any device, it is essential that you study the device data sheet and make certain that you understand the purpose of every single line in the code you are using.

Yeah, I know. The communication itself is something I thought I'll have to take as a given for now, because I'd rather work on the other parts, so for starters I was looking for just a code to give me angular rates, accelerations and magnetometer input.
The code I was using made it look far to complicated for me to handle right now, but I just found a simpler code that I actually understand (well... mostly. the magnetometer part is giving me hell).