Skip to content

SparkFun Triple Axis Accelerometer Breakout - MMA8452Q Particle (Photon/Core) Library

License

Notifications You must be signed in to change notification settings

sparkfun/SparkFun_MMA8452Q_Particle_Library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SparkFun MMA8452Q 3-Axis Accelerometer Particle Library

A firmware library for the SparkFun's MMA8452Q 3-Axis Accelerometer.

MMA8452Q 3-Axis Accelerometer

About

The MMA8452Q is an I2C-based 3-axis accelerometer. It has user selectable full scales of ±2g/±4g/±8g with high pass filtered data as well as non filtered data available real-time. Unique features include programmable interrupts, tap-detection, and orientation detection.

Repository Contents

  • /firmware - Source files for the library (.cpp, .h).
  • /firmware/examples - Example sketches for the library (.cpp). Run these from the Particle IDE.
  • spark.json - General library properties for the Particle library manager.

Example Usage

Create an MMA8452Q 3-Axis Accelerometer Object & Initialize

To begin, create an MMA8452Q 3-Axis Accelerometer class object. This'll often go in the global section of the code:

//////////////////////////////
// MMA8452Q Object Creation //
//////////////////////////////
MMA8452Q accel; // This creates an MMA8452Q object, which we'll use to interact with the sensor

To initialize the sensor, call the begin([range], [odr]) function, where [range] is the full-scale range of the sensor and [odr] is the output data rate:

void setup()
{
	...
	accel.begin(SCALE_2G, ODR_1); // Set up accel with +/-2g range, and slowest (1Hz) ODR
	...
}

The full-scale range can be: SCALE_2G, SCALE_4G, or SCALE_8G (2, 4, or 8g).

The output-data rate (ODR) can be: ODR_800, ODR_400, ODR_200, ODR_100, ODR_50, ODR_12, ODR_6 or ODR_1 (800, 400, 200, 100, 50, 12, 6, or 1 Hz).

Update and Read Acceleration Values

All three of the accelerometer values are read in one fell swoop with the read() function:

accel.read();

Once read, the library updates six class variables: x, y, z -- the "raw" 12-bit values from the accelerometer -- and cx, cy, and cz, the calculated accelerations in g.

Serial.println("X: " + String(accel.x) + " | " + String(accel.cx, 2) + " g");
Serial.println("Y: " + String(accel.y) + " | " + String(accel.cy, 2) + " g");
Serial.println("Z: " + String(accel.z) + " | " + String(accel.cz, 2) + " g");

Recommended Components

Products Versions

License Information

This product is open source!

Please review the LICENSE.md file for license information.

If you have any questions or concerns on licensing, please contact techsupport@sparkfun.com.

Distributed as-is; no warranty is given.

  • Your friends at SparkFun.

About

SparkFun Triple Axis Accelerometer Breakout - MMA8452Q Particle (Photon/Core) Library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages