View Single Post
  #12   Spotlight this post!  
Unread 03-02-2016, 20:51
Ian R. Ian R. is offline
Registered User
FRC #2283 (Panteras)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Mexico
Posts: 13
Ian R. will become famous soon enough
Re: MPU-9150 (I2C) with Labview

Quote:
Originally Posted by RyanN View Post
Told ya so!

It's been three years since I messed with it.

So the magnetometer is a 3rd party sensor. InvenSense doesn't make it... they just buy the silicon and wire it up inside the little chip you have, then slap black plastic and their logo on top. (I think it's really an MPU 6050 core with a magnetometer wired up).

The magnetometer is hidden behind the auxiliary I2C bus on the IMU. You have to talk through the auxiliary bus in order to talk to the magnetometer. You can setup the IMU to go into pass-through mode.

I wish I had access to my old code (Thanks IT for deleting it).

This might get you started: https://github.com/sparkfun/MPU-9150...50/MPU6050.cpp

Code:
void MPU6050::getMotion9(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz, int16_t* mx, int16_t* my, int16_t* mz) {
    
	//get accel and gyro
	getMotion6(ax, ay, az, gx, gy, gz);
	
	//read mag
	I2Cdev::writeByte(devAddr, MPU6050_RA_INT_PIN_CFG, 0x02); //set i2c bypass enable pin to true to access magnetometer
	delay(10);
	I2Cdev::writeByte(MPU9150_RA_MAG_ADDRESS, 0x0A, 0x01); //enable the magnetometer
	delay(10);
	I2Cdev::readBytes(MPU9150_RA_MAG_ADDRESS, MPU9150_RA_MAG_XOUT_L, 6, buffer);
	*mx = (((int16_t)buffer[1]) << 8) | buffer[0];
        *my = (((int16_t)buffer[3]) << 8) | buffer[2];
        *mz = (((int16_t)buffer[5]) << 8) | buffer[4];		
}
You can find those register constants in https://github.com/sparkfun/MPU-9150...6050/MPU6050.h
I've already got the register constants from the register sheet, but this line of code should perform all the magic:
Code:
I2Cdev::writeByte(devAddr, MPU6050_RA_INT_PIN_CFG, 0x02); //set i2c bypass enable pin to true to access magnetometer
I thought the mag was wired as an additional I2C device, and not behind the IMU.
Thanks for pointing it out!
Reply With Quote