View Single Post
  #13   Spotlight this post!  
Unread 04-02-2016, 19:19
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
Ok, I tested it out today, and we finally got a response from the mag.
But anither issue arised. While we can read from all the low byte registers, the high ones always return 0.
We tried communicating with the mag directly, as well as through the MPU, but it's the same problem.
I'm not sure if we have to read each independent register and then shift the high one and add the low one to it, or if we should read the low register and ask for 2 bytes.
Reply With Quote