MMA8452Q Triple Axis Accelerometer
The MMA8452Q is a low-power, three-axis, capacitive MEMS accelerometer with 8 or 12 bits of resolution. The surface mount chip is located on a break out board with inputs to ground, power, I2C, and two external interrupts pins.
Hello World
Import programMMA8452_Demo
The main.cpp program below demonstrates a simple way to interface with the MMA8452 accelerometer. The function reads in the acceleration data in the X, Y, and Z directions and displays them through a serial com port on a PC. The Putty Output figure below shows the output of the accelerometer using Putty. The program also dims or brightens the mbed LEDs 1-3 based on whether or not they are at 'level'( 0 Gs) or above respectively. The video below previews the code in action.
Library
Import libraryMMA8452
Library for driving the MMA8452 accelerometer over I2C
Datasheet
http://www.freescale.com/files/sensors/doc/data_sheet/MMA8452Q.pdfNotes
Wiring
MMA8452Q attached to mbed on a breadboard.
MMA8452Q schematic.
Pinout Table
MMA8452Q pins | Mbed pins |
---|---|
1 Vcc | Vout (3.3V) |
2 SDA | P28 (SDA) |
3 SCL | P27 (SCL) |
4 I1 | Any DigitalOut Pins |
5 I2 | Any DigitalOut Pins |
6 GND | GND |
API Documentation
Import library
Public Member Functions |
|
MMA8452 (PinName sda, PinName scl, int frequency) | |
Create an accelerometer object connected to the specified I2C pins.
|
|
~MMA8452 () | |
Destructor.
|
|
int | activate () |
Puts the
MMA8452
in active mode.
|
|
int | standby () |
Puts the
MMA8452
in standby.
|
|
int | getDeviceID (char *dst) |
Read the device ID from the accelerometer (should be 0x2a)
|
|
int | getStatus (char *dst) |
Read the
MMA8452
status register.
|
|
int | readXYZRaw (char *dst) |
Read the raw x, y, an z registers of the
MMA8452
in one operation.
|
|
int | readXRaw (char *dst) |
Read the raw x register into the provided buffer.
|
|
int | readYRaw (char *dst) |
Read the raw y register into the provided buffer.
|
|
int | readZRaw (char *dst) |
Read the raw z register into the provided buffer.
|
|
int | readXYZCounts (int *x, int *y, int *z) |
Read the x, y, and z signed counts of the
MMA8452
axes.
|
|
int | readXCount (int *x) |
Read the x axes signed count.
|
|
int | readYCount (int *y) |
Read the y axes signed count.
|
|
int | readZCount (int *z) |
Read the z axes signed count.
|
|
int | readXYZGravity (double *x, double *y, double *z) |
Read the x, y, and z accelerations measured in G.
|
|
int | readXGravity (double *x) |
Read the x gravity in G into the provided double pointer.
|
|
int | readYGravity (double *y) |
Read the y gravity in G into the provided double pointer.
|
|
int | readZGravity (double *z) |
Read the z gravity in G into the provided double pointer.
|
|
int | isXYZReady () |
Returns 1 if data has been internally sampled (is available) for all axes since last read, 0 otherwise.
|
|
int | isXReady () |
Returns 1 if data has been internally sampled (is available) for the x-axis since last read, 0 otherwise.
|
|
int | isYReady () |
Returns 1 if data has been internally sampled (is available) for the y-axis since last read, 0 otherwise.
|
|
int | isZReady () |
Returns 1 if data has been internally sampled (is available) for the z-axis since last read, 0 otherwise.
|
|
int | readRegister (char addr, char *dst) |
Reads a single byte from the specified
MMA8452
register.
|
|
int | readRegister (char addr, char *dst, int nbytes) |
Reads n bytes from the specified
MMA8452
register.
|
|
int | writeRegister (char addr, char data) |
Write to the specified
MMA8452
register.
|
|
int | writeRegister (char addr, char *data, int nbytes) |
Write a data buffer to the specified
MMA8452
register.
|
You need to log in to post a discussion