MPU DMP code modified for use with ST Nucelo boards. This Library makes use of I2Cdev.

Dependents:   MPU9150_nucleo_i2cdev Orion_newPCB_test_LV Orion_PCB_test_Faulhaber_gr41_wptcmd_V1 MPU9150_nucleo_i2cdev ... more

Fork of MPU6050-DMP-Ian by Ian Hua

Files at this revision

API Documentation at this revision

Comitter:
akashvibhute
Date:
Thu May 19 06:38:09 2016 +0000
Parent:
16:babac099274f
Commit message:
added getMag function to query onboard magnetometer

Changed in this revision

MPU/inc/MPU6050.h Show annotated file Show diff for this revision Revisions of this file
MPU/src/MPU6050.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/MPU/inc/MPU6050.h	Thu Oct 01 06:42:51 2015 +0000
+++ b/MPU/inc/MPU6050.h	Thu May 19 06:38:09 2016 +0000
@@ -603,6 +603,7 @@
     void 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);
     void getMotion6(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz);
     void getAcceleration(int16_t* x, int16_t* y, int16_t* z);
+    void getMag(int16_t* mx, int16_t* my, int16_t* mz);
     int16_t getAccelerationX();
     int16_t getAccelerationY();
     int16_t getAccelerationZ();
--- a/MPU/src/MPU6050.cpp	Thu Oct 01 06:42:51 2015 +0000
+++ b/MPU/src/MPU6050.cpp	Thu May 19 06:38:09 2016 +0000
@@ -1897,6 +1897,20 @@
     *my = (((int16_t)buffer[2]) << 8) | buffer[3];
     *mz = (((int16_t)buffer[4]) << 8) | buffer[5];
 }
+
+void MPU6050::getMag(int16_t* mx, int16_t* my, int16_t* mz)
+{
+    // magnetometer reading
+    i2Cdev.writeByte(devAddr, MPU6050_RA_INT_PIN_CFG, 0x02); //set i2c bypass enable pin to true to access magnetometer
+    wait_ms(10); // necessary wait >=6ms
+    i2Cdev.writeByte(MPU9150_RA_MAG_ADDRESS, 0x0A, 0x01); // enable the magnetometer
+    wait_ms(10); // necessary wait >=6ms
+    i2Cdev.readBytes(MPU9150_RA_MAG_ADDRESS, MPU9150_RA_MAG_XOUT_L, 6, buffer);
+    *mx = (((int16_t)buffer[0]) << 8) | buffer[1];
+    *my = (((int16_t)buffer[2]) << 8) | buffer[3];
+    *mz = (((int16_t)buffer[4]) << 8) | buffer[5];
+}
+
 /** Get raw 6-axis motion sensor readings (accel/gyro).
  * Retrieves all currently available motion sensor values.
  * @param ax 16-bit signed integer container for accelerometer X-axis value