Library for driving the MMA8452 accelerometer over I2C

Dependents:   MMA8452_Test MMA8452_Demo Dualing_Tanks IMU-Controlled_MP3_Player ... more

Here is a simple example:

#include "mbed.h"
#include "MMA8452.h"

int main() {
   Serial pc(USBTX,USBRX);
   pc.baud(115200);
   double x = 0, y = 0, z = 0;

   MMA8452 acc(p28, p27, 40000);
   acc.setBitDepth(MMA8452::BIT_DEPTH_12);
   acc.setDynamicRange(MMA8452::DYNAMIC_RANGE_4G);
   acc.setDataRate(MMA8452::RATE_100);
   
   while(1) {
      if(!acc.isXYZReady()) {
         wait(0.01);
         continue;
      }
      acc.readXYZGravity(&x,&y,&z);
      pc.printf("Gravities: %lf %lf %lf\r\n",x,y,z);
   }
}

An easy way to test that this actually works is to run the loop above and hold the MMA8452 parallel to the ground along the respective axis (and upsidedown in each axis). You will see 1G on the respective axis and 0G on the others.

History

Improved doxygen. default tip

2014-03-07, by ashleymills [Fri, 07 Mar 2014 14:53:40 +0000] rev 21

Improved doxygen.


Independent read methods present.

2014-03-07, by ashleymills [Fri, 07 Mar 2014 11:55:30 +0000] rev 20

Independent read methods present.


Adding independent query methods;

2014-03-06, by ashleymills [Thu, 06 Mar 2014 18:07:43 +0000] rev 19

Adding independent query methods;


Debugging enabled by default for convenience

2014-03-05, by ashleymills [Wed, 05 Mar 2014 17:04:04 +0000] rev 18

Debugging enabled by default for convenience


Cleaned up debug handling

2014-03-05, by ashleymills [Wed, 05 Mar 2014 17:01:00 +0000] rev 17

Cleaned up debug handling


Added data ready query commands for each independent axes.

2014-03-05, by ashleymills [Wed, 05 Mar 2014 16:47:13 +0000] rev 16

Added data ready query commands for each independent axes.


Removed crap from comments.

2014-03-05, by ashleymills [Wed, 05 Mar 2014 15:36:03 +0000] rev 15

Removed crap from comments.


Updated author priority to reflect work

2014-03-05, by ashleymills [Wed, 05 Mar 2014 15:09:21 +0000] rev 14

Updated author priority to reflect work


Has routines to read raw, counts, and gravity.

2014-03-05, by ashleymills [Wed, 05 Mar 2014 15:04:13 +0000] rev 13

Has routines to read raw, counts, and gravity.


Added basic raw reading back in after remake.

2014-03-04, by ashleymills [Tue, 04 Mar 2014 17:50:47 +0000] rev 12

Added basic raw reading back in after remake.