Accelerometer and angle meter

Dependencies:   Beep mbed

Embed: (wiki syntax)

« Back to documentation index

MMA8452 Class Reference

MMA8452 Class Reference

Library for interfacing with MMA8452 I2C Accelerometer. More...

#include <MMA8452.h>

Public Member Functions

 MMA8452 (PinName sdaPin, PinName sclPin)
 Create a MMA8452 object connected to the specified pins.
void init ()
 Initialise accelerometer.
Acceleration readValues ()
 Get values of acceleration.

Detailed Description

Library for interfacing with MMA8452 I2C Accelerometer.

See also:
http://www.freescale.com/files/sensors/doc/data_sheet/MMA8452Q.pdf
https://www.sparkfun.com/products/12756

Revision 1.0

Author:
Craig A. Evans
Date:
March 2015

Example:

#include "mbed.h"
#include "MMA8452.h"
 
MMA8452 mma8452(p28,p27);  // SDA, SCL
Serial serial(USBTX,USBRX);
 
int main() {
 
    mma8452.init();  // 100 Hz update rate, ±4g scale
 
    Acceleration acceleration;  // Accleration structure declared in MMA8452 class
 
    while(1) {
 
        acceleration = mma8452.readValues();   // read current values and print over serial port
        serial.printf("x = %.2f g y = %.2f g z = %.2f g\n",acceleration.x,acceleration.y,acceleration.z);
        wait(0.1);   // short delay until next reading
 
    }
 
}

Definition at line 68 of file MMA8452.h.


Constructor & Destructor Documentation

MMA8452 ( PinName  sdaPin,
PinName  sclPin 
)

Create a MMA8452 object connected to the specified pins.

Parameters:
sdaPin- mbed SDA pin
sclPin- mbed SCL pin

Definition at line 412 of file main.cpp.


Member Function Documentation

void init (  )

Initialise accelerometer.

Powers up the accelerometer, sets 100 Hz update rate and ±4g scale

Definition at line 419 of file main.cpp.

Acceleration readValues (  )

Get values of acceleration.

Reads the x,y,z values in g's

Returns:
an Acceleration structure with x,y,z members (float)

Definition at line 454 of file main.cpp.