Pay job/MPU-9150 compass/problem

Hello everyone

I have some small problem with the mpu 9150 compass,sow i wonder if someone here can fix it for me.

The code is not write by me,but something is.

Before I turn on the mpu 9150, i need to pointing mpu-9150 to the south about 200 degrees, to get right direction. after i do that and turn on the mpu-9150 the mpu-9150 is now working and show right direction. :slight_smile:

I have to do this,every time I shall start up mpu 9150 :0
It should not be like that. :0

Can pay through PAYPAL.

I have upload the code,see attachment.

Bottonside_Code_Version_26__English.ino (26.1 KB)

MPU9150Lib.cpp (16.7 KB)

Do you use a I2C level shifter ?

What is that I2C level shifter?

I use the 9 Degrees of Freedom Breakout - MPU-9150 this use I2C and the depth sensor use also I2C but not the same address.

Can you copy a link to that 9DOF board ? and to the height (baromic pressure) sensor board ?
The sensors are 3.3V, but the Arduino Mega 2560 has a 5V I2C bus.

This Kalman guide has a link at the end of the first post to working code for MPU-6050 + magnetometer : http://forum.arduino.cc/index.php/topic,58048.0.html
It is a different magnetomer than the one inside the MPU-9150.

You code is not easy, many includes, many libraries. It's big. I don't know what all those libraries are doing.

Here is some link:

9 Degrees of Freedom Breakout - MPU-9150

Pressure Sensor - MS5803-14BA Breakout

Both MPU-9150 and MS5803-14BA is connected to together SDA,SCL and power is connected to 3,3 volt on Arduino Mega 2560.

Everything in the code is working,except MPU-9150 compass,i most manual calibration the compass,i need to pointing mpu-9150 to the south about 200 degrees, to get right direction.after i do that,the compass is working and show right direction.

Is not a problem,but shall not be like that. I can buy a small manual compass and use that to find south and then start up the mpu-9150.

It should not be like that. I agree.

But you use your sensors outside the specificiation.
The SDA and SCL signals from the Arduino Mega 2560 board have 10k pullup to 5V. That creates a 5V I2C bus. You may not connect those to the 3.3V sensors. You need a level-shifter.
It is even possible that your sensors are already damaged.

There are two level shifters: with 4 pins on each side and with 6 pins on each side. The have the same components and work the same.

I can not guarantee that the problem will be gone with a level-shifter. It is probably something in the library somewhere that causes a wrong startup value for the magnetometer, but I have no idea.
A workaround could be to use the HMC5883L with a good library.

In the code the calibration for the magnetometer is called. What happens if you set it to false ?
m_useMagCalibration = false;

ok, i will buy a level-shifter,i will also buy a new 9 Degrees of Freedom Breakout.
I have many MS5803 sensor,i need only solder a new MS5803 on the Breakout board.
I use my own Breakout board for MS5803.

Everything is working, sow i dont think something is damaged yet.

Something in the library,somewhere that causes a wrong startup value for the magnetometer, I think,that to, but what.

In the code the calibration for the magnetometer is called. What happens if you set it to false ?
m_useMagCalibration = false;

I have now set it to false,but nothing happens,is the same.

I have remove nearly all of the code, ther is only MPU-9150 and OSD Max7456 left,in the Sketch.

#include <SPI.h>                           // OSD MAX7456
#include <MAX7456.h>                       // OSD MAX7456
#include <Wire.h>                          // MPU-9150
#include "I2Cdev.h"                        // MPU-9150
#include "MPU9150Lib.h"                    // MPU-9150
#include "CalLib.h"                        // MPU-9150
#include <dmpKey.h>                        // MPU-9150
#include <dmpmap.h>                        // MPU-9150
#include <inv_mpu.h>                       // MPU-9150
#include <inv_mpu_dmp_motion_driver.h>     // MPU-9150
#include <EEPROM.h>                        // MPU-9150

//  DEVICE_TO_USE selects whether the IMU at address 0x68 (default) or 0x69 is used
//    0 = use the device at 0x68
//    1 = use the device at ox69

#define  DEVICE_TO_USE    0

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  (20)

//  MAG_UPDATE_RATE defines the rate (in Hz) at which the MPU updates the magnetometer data
//  MAG_UPDATE_RATE should be less than or equal to the MPU_UPDATE_RATE

#define MAG_UPDATE_RATE  (10)

//  MPU_MAG_MIX defines the influence that the magnetometer has on the yaw output.
//  The magnetometer itself is quite noisy so some mixing with the gyro yaw can help
//  significantly. Some example values are defined below:

#define  MPU_MAG_MIX_GYRO_ONLY          0                   // just use gyro yaw
#define  MPU_MAG_MIX_MAG_ONLY           1                   // just use magnetometer and no gyro yaw
#define  MPU_MAG_MIX_GYRO_AND_MAG       10                  // a good mix value 
#define  MPU_MAG_MIX_GYRO_AND_SOME_MAG  50                  // mainly gyros with a bit of mag correction 


#define MPU_LPF_RATE   40    //  MPU_LPF_RATE is the low pas filter rate and can be between 5 and 188Hz

// Pin Mapping Of MAX7456 on Arduino Mega 2560
						 
const byte osdChipSelect	= 53;
const byte masterOutSlaveIn	= 51;
const byte masterInSlaveOut     = 50;
const byte slaveClock	        = 52;
const byte osdReset		= 0;
MAX7456 OSD(osdChipSelect);		

void setup()
{
        SPI.begin();
	SPI.setClockDivider(SPI_CLOCK_DIV2);		
	OSD.begin(MAX7456_COLS_P0,MAX7456_ROWS_P0,MAX7456_FULLSCREEN);
	OSD.display();
	OSD.setDefaultSystem(MAX7456_PAL);
	Wire.begin();
        Serial.begin(57600);
        pinMode(23,INPUT);	      // VSYNC pin 23, On Arduino Mega 2560/ OSD MAX7456
        
//****************************************************************
   //MPU-9150
  while(PINA&2);                      // VSYNC pin 23/OSD MAX7456
  MPU.selectDevice(DEVICE_TO_USE);                        
  MPU.init(MPU_UPDATE_RATE, MPU_MAG_MIX_GYRO_AND_MAG, MAG_UPDATE_RATE, MPU_LPF_RATE);   // start the MPU
  while(PINA&2);                      // VSYNC pin 23/OSD MAX7456

 }
//****************************************************************
//-----------------------------------------
void loop(){
  	

 MPU.selectDevice(DEVICE_TO_USE);                           // only needed if device has changed since init but good form anyway
  if (MPU.read()) {        // get the latest data if ready yet
  
      MPU.printAngles(MPU.m_dmpEulerPose);                         // the Euler angles from the dmp quaternion
  
   // 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.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
   
  }
}

Here is all libraries For MPU-9150,i have only Modified the MPU9150 CPP file,to work with OSD Max7456.
see attachment.

Here is a video of the working mpu-9150,on the third line on the screen , is mpu-9150 X-Y-Z
On the compass i have add.North,South,West,East--- (on Norwegian)
I have made some custom symbol for ROLL,PITCH.

Arrow up with F and degrees,mean Front is 20 degrees up.
Arrow down with F and degrees,mean Front is 20 degrees down.
Arrow down with V and degrees, mean left side is 20 degrees down.
Arrow down with H and degrees, mean right side is 20 degrees down..

libraries For MPU-9150.rar (73.6 KB)

I think I know what's wrong, with the MPU-9150.

In the code,i have use: MPU.printAngles(MPU.m_dmpEulerPose);
If you use that, the mpu-9150 use not the magnetic field around me.

If i use the MPU.printAngles(MPU.m_fusedEulerPose); the mpu-9150 use the magnetic field around me. but the measurements are not correct.

Sow i need to add Callibration and 360 degrees to the compass in the mpu-9150 sketch.

Is it possible to get the output in the sketch and not in the MPU9150Lib CPP-fil.

Serial.print("x: "); Serial.print(vec[VEC3_X] * RAD_TO_DEGREE);
Serial.print(" y: "); Serial.print(vec[VEC3_Y] * RAD_TO_DEGREE);
Serial.print(" z: "); Serial.print(vec[VEC3_Z] * RAD_TO_DEGREE);

I need someone to do that for me, i will pay tru PayPal :slight_smile: Send me a PM

Here is the sketch only to mpu-9150 to output to serial monitor:
:

#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>

//  DEVICE_TO_USE selects whether the IMU at address 0x68 (default) or 0x69 is used
//    0 = use the device at 0x68
//    1 = use the device at ox69

#define  DEVICE_TO_USE    0

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  (20)

//  MAG_UPDATE_RATE defines the rate (in Hz) at which the MPU updates the magnetometer data
//  MAG_UPDATE_RATE should be less than or equal to the MPU_UPDATE_RATE

#define MAG_UPDATE_RATE  (10)

//  MPU_MAG_MIX defines the influence that the magnetometer has on the yaw output.
//  The magnetometer itself is quite noisy so some mixing with the gyro yaw can help
//  significantly. Some example values are defined below:

#define  MPU_MAG_MIX_GYRO_ONLY          0                  // just use gyro yaw
#define  MPU_MAG_MIX_MAG_ONLY           1                   // just use magnetometer and no gyro yaw
#define  MPU_MAG_MIX_GYRO_AND_MAG       20                  // a good mix value 
#define  MPU_MAG_MIX_GYRO_AND_SOME_MAG  50                  // mainly gyros with a bit of mag correction 

//  MPU_LPF_RATE is the low pas filter rate and can be between 5 and 188Hz

#define MPU_LPF_RATE   5

//  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.print("Arduino9150 starting using device "); Serial.println(DEVICE_TO_USE);
  Wire.begin();
  MPU.selectDevice(DEVICE_TO_USE);                        // only really necessary if using device 1
  MPU.init(MPU_UPDATE_RATE, MPU_MAG_MIX_GYRO_AND_MAG, MAG_UPDATE_RATE, MPU_LPF_RATE);   // start the MPU
}

void loop()
{  
  MPU.selectDevice(DEVICE_TO_USE);                         // only needed if device has changed since init but good form anyway
  if (MPU.read()) {                                        // get the latest data if ready yet

 MPU.printAngles(MPU.m_fusedEulerPose);                 // print the output of the data fusion
    Serial.println();
  }
}

I have now order new mpu-9150 and a I2C level shifter, i will get this next week :slight_smile:

I have upload the Libraries ,see attachment.

Libraries to MPU-9150 Serial_output.rar (68.9 KB)

Is it possible to get the output in the sketch and not in the MPU9150Lib CPP-fil.

The output of what? The MPU.printAngles() method?

Have you looked at the library? Specifically, have you looked at the printAngle() method?

void MPU9150Lib::printAngles(float *vec)
{
  Serial.print("x: "); Serial.print(vec[VEC3_X] * RAD_TO_DEGREE);  
  Serial.print(" y: "); Serial.print(vec[VEC3_Y] * RAD_TO_DEGREE);  
  Serial.print(" z: "); Serial.print(vec[VEC3_Z] * RAD_TO_DEGREE);    
}

You are telling the function what angle to print.

You call it:

MPU.printAngles(MPU.m_fusedEulerPose);

So, clearly MPU.m_fusedEulerPose is an array of 3 floats. The value that is printed following the "x: " is MPU.m_fusedEulerPose[0].

I need someone to do that for me, i will pay tru PayPal

I'll be sending you a bill. 8)

I have send you a PM PaulS

I have now found a new library for MPU-9150 ,this is the latest, i have not test it yet.
https://github.com/richards-tech/RTIMULib-Arduino

going crazy, I give up now. I will stick to the one I have upload here.