Go Down

Topic: MMA8453Q 3 Axis Accelerometer (Read 4160 times) previous topic - next topic

Chris_Johnson

Hi,

I recently purchased a MMA8453Q: Xtrinsic 3-Axis, 12-bit Accelerometer from Ebay on a lovely little break out board. I really wanted to experiment with a I2C controlled device. Little did I realise what I ride I was in for I spent a good part of 9 hours getting the code up and running or more so figuring out why wire.h was useless for this particular device. I finally came across Sparkfun selling a device of the same family http://www.sparkfun.com/products/10953  . I've seen lot of people raving about how cheap the device is an how it is such a wonderfully small form factor but no one as yet saying how to interface with it using an arduino.

 

Well Wayne Truchsess has developed the I2C master library which I'm sure some of you have come across and many many thanks to him as without him I wouldn't have stood a chance in getting this device to work without writing my own software I2C and probably going back to using a good old fashioned PIC.

So for all to use here is the code that can successfully communicate with this amazing little device.

I would recommend starting of by commenting all of the main loop code out and just running the WHO AM I section. Once you get 58 spitting out over the serial line then your almost there. The difficult part is waking the device once this occurs then reading of the XYZ registers is easy.

I hope others find this usefull,

Many thanks,

Chris

Code: [Select]

#include <I2C.h>
//I2c.h is available at:
//http://www.dsscircuits.com/articles/arduino-i2c-master-library.html
//or directley...
//http://dsscircuits.com/images/code/I2C_Rev2.zip

#define ACC  0x1D

void setup()
{
  I2c.begin();
  Serial.begin(9600);
}

void loop()
{
  /*WHO AM I - ASK FOR DEVICE ID DEFAULT: 0x58*/
  //I2c.read(ACC,0x0D,1) ;//who am I
  //Serial.print("I AM:");
  //byte WHO = I2c.receive();
  //Serial.print(WHO,BIN);
  //Serial.print("  ");
  //Serial.println(WHO, DEC);

  /*CNTRL REG 1 - Will tell if Active bit has been set or not*/
  //I2c.read(ACC,0x2A,1) ;
  //Serial.print("CTRL REG 1: ");
  //Serial.println(I2c.receive(), BIN);
 
  /*SYSTEM MODE
   
    00 - Sleep
    01 - Awake
    10 - Standby
   
  */
 
  I2c.read(ACC,0x0B,1) ;//
  //Serial.print("SYS MODE:");
  //Serial.println(I2c.receive(), BIN);
  if(I2c.receive() == 0x00)
  {
    Serial.print("Waking Device");
    I2c.write(ACC,0x2A,0x01);
  }
  else if(I2c.receive() == 0x01)
  {
    Serial.print("AWAKE\n");
  }
  else if(I2c.receive() == 0x02)
  {
    Serial.print("STANDBY\n");
  }
 
  /*X Register*/
  I2c.read(ACC,0x01,1);
  byte X1 = I2c.receive();
  Serial.print("X1:");
  Serial.println(X1, DEC);

  /*Y Register*/
  I2c.read(ACC,0x03,1);
  byte Y1 = I2c.receive();
  Serial.print("Y1:");
  Serial.println(Y1, DEC);

 
  /*Z Registers*/
  I2c.read(ACC,0x05,1);
  byte Z1 = I2c.receive();
  Serial.print("Z1:");
  Serial.println(Z1, DEC);

  delay(100); //Not necessary just so we can see the info
}

Go Up