A basic library for the FXOS8700Q combination accelerometer / magnetometer

Dependencies:   MotionSensor

Dependents:   K64F_eCompass_LCD Hello_FXOS8700Q rtos_compass K64F_eCompass ... more

This library supports the 6 axis combination Accelerometer / Magnetometer. Functions are provided to retrieve data in raw 16 bit signed integers or unit converted G's and micro-teslas

Files at this revision

API Documentation at this revision

Comitter:
JimCarver
Date:
Sat Apr 19 00:16:49 2014 +0000
Parent:
3:eb1271ef90bc
Child:
5:c4176a12f7d5
Commit message:
Added unit converted magnetometer support

Changed in this revision

FXOS8700Q.cpp Show annotated file Show diff for this revision Revisions of this file
FXOS8700Q.h Show annotated file Show diff for this revision Revisions of this file
--- a/FXOS8700Q.cpp	Thu Apr 17 17:54:13 2014 +0000
+++ b/FXOS8700Q.cpp	Sat Apr 19 00:16:49 2014 +0000
@@ -23,6 +23,7 @@
 FXOS8700Q::FXOS8700Q(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) {
     // activate the peripheral
     uint8_t data[2] = {FXOS8700Q_CTRL_REG1, 0x00};
+    m_i2c.frequency(400000);
     writeRegs(data, 2);
     data[0] = FXOS8700Q_M_CTRL_REG1;
     data[1] = 0x1F;
@@ -95,6 +96,14 @@
     d[2] = (res[4] << 8) | res[5];
 }
 
+void FXOS8700Q::getMagAllAxis(float * res) {
+    int16_t raw[3];
+    MagXYZraw( raw);
+    res[0] = (float) raw[0] * 0.1f;
+    res[1] = (float) raw[1] * 0.1f;
+    res[2] = (float) raw[2] * 0.1f;
+}        
+    
 int16_t FXOS8700Q::getAccAxis(uint8_t addr) {
     int16_t acc;
     uint8_t res[2];
--- a/FXOS8700Q.h	Thu Apr 17 17:54:13 2014 +0000
+++ b/FXOS8700Q.h	Sat Apr 19 00:16:49 2014 +0000
@@ -113,13 +113,20 @@
   float getAccZ();
 
   /**
-   * Get XYZ axis acceleration
+   * Get XYZ axis acceleration in G's
    *
    * @param res array where acceleration data will be stored
    */
   void getAccAllAxis(float * res);
   
   /**
+   * Get XYZ axis magnetic readings in micro-teslas
+   *
+   * @param res array where acceleration data will be stored
+   */
+  void getMagAllAxis(float * res);
+  
+  /**
    * Get XYZ axis acceleration, signed 16 bit values
    *
    * @param res array where acceleration data will be stored