Go Down

Topic: mma8452 (Read 131 times) previous topic - next topic


Hi, im trying to change the scale on this sensor. im using the example for changing the scale however when i try it doesnt work, it just stays at 2g

Does anyone know how to change this properly?

One thing ive noticed is that this is for the Q sensor however mine doesnt have this on the board but i also cant find any sort of libs for the none Q version that i have

Many thanks #

Code: [Select]
  Library for the MMA8452Q
  By: Jim Lindblom and Andrea DeVore
  SparkFun Electronics

  Do you like this library? Help support SparkFun. Buy a board!

  This sketch uses the SparkFun_MMA8452Q library to initialize
  the accelerometer, change the scale, and stream calcuated x,
  y, z, acceleration values from it (in g units).

  Hardware hookup:
  Arduino --------------- MMA8452Q Breakout
    3.3V  ---------------     3.3V
    GND   ---------------     GND
  SDA (A4) --\/330 Ohm\/--    SDA
  SCL (A5) --\/330 Ohm\/--    SCL

  The MMA8452Q is a 3.3V max sensor, so you'll need to do some
  level-shifting between the Arduino and the breakout. Series
  resistors on the SDA and SCL lines should do the trick.

  License: This code is public domain, but if you see me
  (or any other SparkFun employee) at the local, and you've
  found our code helpful, please buy us a round (Beerware

  Distributed as is; no warrenty given.

#include <Wire.h>                 // Must include Wire library for I2C
#include "SparkFun_MMA8452Q.h"    // Click here to get the library: http://librarymanager/All#SparkFun_MMA8452Q

MMA8452Q accel;                   // create instance of the MMA8452 class

void setup() {
  Serial.println("MMA8452Q Change Scale Test Code!");

  if (accel.begin() == false) {
    Serial.println("Not Connected. Please check connections and read the hookup guide.");
    while (1);

  /* Default scale is +/-2g (full-scale range)
     Set scale using SCALE_2G, SCALE_4G, SCALE_8G
     Sets scale to +/-2g, 4g, or 8g respectively

void loop() {
  if (accel.available()) {      // Wait for new data from accelerometer
    // Acceleration of x, y, and z directions in g units
    //Serial.print(accel.getCalculatedX(), 3);
    Serial.println(accel.getCalculatedY(), 3);
  //  Serial.print("\t");
   // Serial.print(accel.getCalculatedZ(), 3);
   // Serial.println();

Go Up