Go Down

Topic: How to read values off of MPU 9150 (Read 1 time) previous topic - next topic

azizsm

Hello, this is my first dealing with an IMU and I2C as well, the problem I am having is that I can't manage to get the accelerometer or gyro values from the  MPU 9150.  https://www.sparkfun.com/products/11486

I tried a couple of codes, one was a pack of libraries https://github.com/zarthcode/MPU9150Lib and I really didn't know what I would do with the results because it printed the "output of the data fusion" and I really dont know what that is exactly.
Code: [Select]
////////////////////////////////////////////////////////////////////////////
//
//  This file is part of MPU9150Lib
//
//  Copyright (c) 2013 Pansenti, LLC
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy of
//  this software and associated documentation files (the "Software"), to deal in
//  the Software without restriction, including without limitation the rights to use,
//  copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
//  Software, and to permit persons to whom the Software is furnished to do so,
//  subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in all
//  copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
//  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
//  PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
//  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
//  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
//  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include <Wire.h>
#include "I2Cdev.h"
#include "MPU9150Lib.h"
#include "CalLib.h"
#include <dmpKey.h>
#include <dmpmap.h>
#include <inv_mpu.h>
#include <inv_mpu_dmp_motion_driver.h>
#include <EEPROM.h>

MPU9150Lib MPU;                                              // the MPU object

//  MPU_UPDATE_RATE defines the rate (in Hz) at which the MPU updates the sensor data and DMP output

#define MPU_UPDATE_RATE  (10)

//  SERIAL_PORT_SPEED defines the speed to use for the debug serial port

#define  SERIAL_PORT_SPEED  115200

void setup()
{
    Serial.begin(SERIAL_PORT_SPEED);
    Serial.println("Arduino9150 starting");
    Wire.begin();
    MPU.init(MPU_UPDATE_RATE);                             // start the MPU
}

void loop()

  if (MPU.read()) {                                        // get the latest data
//  MPU.printQuaternion(MPU.m_rawQuaternion);              // print the raw quaternion from the dmp
//  MPU.printVector(MPU.m_rawMag);                         // print the raw mag data
//  MPU.printVector(MPU.m_rawAccel);                       // print the raw accel data
//  MPU.printAngles(MPU.m_dmpEulerPose);                   // the Euler angles from the dmp quaternion
//  MPU.printVector(MPU.m_calAccel);                       // print the calibrated accel data
//  MPU.printVector(MPU.m_calMag);                         // print the calibrated mag data
    MPU.printAngles(MPU.m_fusedEulerPose);                 // print the output of the data fusion
    Serial.println();
  }
}


There are so many libraries here within each other so I'm pretty much lost.


The second one is from http://playground.arduino.cc/Main/MPU-9150 , I liked this one cause I would like to deal directly with the registers using the Wire library only and no other library.

But the strange thing that this code only outputs "36.50  -1  -1  -1  -1  -1  -1  -1  -1  -1" over and over, nothing is changing.

I would really appreciate any help, I have been struggling with this for a couple of days now. Thank you!

michinyon

It looks like your i2c communication is not actually working.

Do you get a correct response from the i2c_scanner sketch ?

azizsm

I removed all the connections except for Vcc, GND, SDA and SCL and it does work for the serial monitor now but the output for http://playground.arduino.cc/Main/MPU-9150 is still the same

Now, say I just wanted to get the X axis accelerometer output. The device's address is 0x68, register address are 0x1B for the high byte and 0x1C for the low byte. Using the Wire library, what should the commands for reading be like?


I have the same problem with you---seeing "36.50  -1  -1  -1  -1  -1  -1  -1  -1  -1" over and over.
However, I found the other two ways to solve it .
The codes in http://playground.arduino.cc/Main/MPU-6050 and https://github.com/sparkfun/MPU-9150_Breakout can work out correctly.
Maybe the problem is in the code of 9150 itself or for other configuration reasons, hope someone can check it later.

geris2

Hi!
Was this issue ever solved?
I have the same problem but interestingly I get correct measurements from the magnetometer and the dummy data from any of the mpu6050 compatible registers.
I tried every sample code.
I guess its hardware problem :(

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy