upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Types | Public Member Functions
MMA7660 Class Reference

API for the MMA7660 I2C 3-Axis Digital Accelerometer. More...

Detailed Description

UPM module for the MMA7660 I2C 3-axis digital accelerometer. This device supports a variety of capabilities, including the generation of interrupts for various conditions, tilt and basic gesture detection, and X/Y/Z-axis measurements of g-forces being applied (up to 1.5g)

This module was tested with the Grove 3-Axis Digital Accelerometer (1.5g)

mma7660.jpg
// Instantiate an MMA7660 on I2C bus 0
upm::MMA7660 *accel = new upm::MMA7660(MMA7660_I2C_BUS,
MMA7660_DEFAULT_I2C_ADDR);
// place device in standby mode so we can write registers
accel->setModeStandby();
// enable 64 samples per second
accel->setSampleRate(upm::MMA7660::AUTOSLEEP_64);
// place device into active mode
accel->setModeActive();
while (shouldRun)
{
int x, y, z;
accel->getRawValues(&x, &y, &z);
cout << "Raw values: x = " << x
<< " y = " << y
<< " z = " << z
<< endl;
float ax, ay, az;
accel->getAcceleration(&ax, &ay, &az);
cout << "Acceleration: x = " << ax
<< "g y = " << ay
<< "g z = " << az
<< "g" << endl;
usleep(500000);
}

Public Types

enum  MMA7660_REG_T {
  REG_XOUT = 0x00, REG_YOUT = 0x01, REG_ZOUT = 0x02, REG_TILT = 0x03,
  REG_SRST = 0x04, REG_SPCNT = 0x05, REG_INTSU = 0x06, REG_MODE = 0x07,
  REG_SR = 0x08, REG_PDET = 0x09, REG_PD = 0x0a
}
 
enum  MMA7660_INTR_T {
  INTR_NONE = 0x00, INTR_FBINT = 0x01, INTR_PLINT = 0x02, INTR_PDINT = 0x04,
  INTR_ASINT = 0x08, INTR_GINT = 0x10, INTR_SHINTZ = 0x20, INTR_SHINTY = 0x40,
  INTR_SHINTX = 0x80
}
 
enum  MMA7660_MODE_T {
  MODE_MODE = 0x01, MODE_TON = 0x04, MODE_AWE = 0x08, MODE_ASE = 0x10,
  MODE_SCPS = 0x20, MODE_IPP = 0x40, MODE_IAH = 0x80
}
 
enum  MMA7660_TILT_BF_T { BF_UNKNOWN = 0x00, BF_LYING_FRONT = 0x01, BF_LYING_BACK = 0x02 }
 
enum  MMA7660_TILT_LP_T {
  LP_UNKNOWN = 0x00, LP_LANDSCAPE_LEFT = 0x01, LP_LANDSCAPE_RIGHT = 0x02, LP_VERT_DOWN = 0x05,
  LP_VERT_UP = 0x06
}
 
enum  MMA7660_AUTOSLEEP_T {
  AUTOSLEEP_120 = 0x00, AUTOSLEEP_64 = 0x01, AUTOSLEEP_32 = 0x02, AUTOSLEEP_16 = 0x03,
  AUTOSLEEP_8 = 0x04, AUTOSLEEP_4 = 0x05, AUTOSLEEP_2 = 0x06, AUTOSLEEP_1 = 0x07
}
 

Public Member Functions

 MMA7660 (int bus, uint8_t address=MMA7660_DEFAULT_I2C_ADDR)
 
 ~MMA7660 ()
 
bool writeByte (uint8_t reg, uint8_t byte)
 
uint8_t readByte (uint8_t reg)
 
void getRawValues (int *x, int *y, int *z)
 
void getAcceleration (float *ax, float *ay, float *az)
 
int getVerifiedAxis (MMA7660_REG_T axis)
 
uint8_t getVerifiedTilt ()
 
void setModeActive ()
 
void setModeStandby ()
 
uint8_t tiltBackFront ()
 
uint8_t tiltLandscapePortrait ()
 
bool tiltTap ()
 
bool tiltShake ()
 
void installISR (int pin, void(*isr)(void *), void *arg)
 
void uninstallISR ()
 
bool setInterruptBits (uint8_t ibits)
 
bool setSampleRate (MMA7660_AUTOSLEEP_T sr)
 

Constructor & Destructor Documentation

MMA7660 ( int  bus,
uint8_t  address = MMA7660_DEFAULT_I2C_ADDR 
)

MMA7660 constructor

Parameters
busI2C bus to use
addressAddress for this sensor; default is 0x55
~MMA7660 ( )

MMA7660 destructor

Member Function Documentation

bool writeByte ( uint8_t  reg,
uint8_t  byte 
)

Writes a byte value into a register

Parameters
regRegister location to write into
byteByte to write
Returns
True if successful
uint8_t readByte ( uint8_t  reg)

Reads a byte value from a register

Parameters
regRegister location to read from
Returns
Value in a specified register
void getRawValues ( int *  x,
int *  y,
int *  z 
)

Reads the current value of conversion

Parameters
xReturned x value
yReturned y value
zReturned z value
void getAcceleration ( float *  ax,
float *  ay,
float *  az 
)

Gets the computed acceleration

Parameters
axReturned computed acceleration of the X-axis
ayReturned computed acceleration of the Y-axis
azReturned computed acceleration of the Z-axis
int getVerifiedAxis ( MMA7660_REG_T  axis)

Reads an axis, verifying its validity. The value passed must be one of REG_XOUT, REG_YOUT, or REG_ZOUT.

Parameters
axisAxis to read
Returns
Axis value
uint8_t getVerifiedTilt ( )

Reads the tilt register, verifying its validity

Returns
Tilt value
void setModeActive ( )

Puts the device in the active mode. In this mode, register writes are not allowed. Place the device in the standby mode before attempting to write registers.

void setModeStandby ( )

Puts the device in the standby (power saving) mode. Note: when in the standby mode, there is no valid data in the registers. In addition, the only way to write a register is to put the device in the standby mode.

uint8_t tiltBackFront ( )

Reads tiltBackFront bits

The value returned is one of the MMA7660_TILT_BF_T values

Returns
Bits corresponding to the BackFront tilt status
uint8_t tiltLandscapePortrait ( )

Reads tiltLandscapePortrait bits

The value returned is one of the MMA7660_TILT_LP_T values

Returns
Bits corresponding to the LandscapePortrait tilt status
bool tiltTap ( )

Reads the tiltTap status

Returns
True if a tap is detected
bool tiltShake ( )

Reads the tiltShake status

Returns
True if a shake is detected
void installISR ( int  pin,
void(*)(void *)  isr,
void *  arg 
)

Installs an interrupt service routine (ISR) to be called when an interrupt occurs

Parameters
pinGPIO pin to use as the interrupt pin
fptrPointer to a function to be called on interrupt
argPointer to an object to be supplied as an argument to the ISR.
void uninstallISR ( )

Uninstalls the previously installed ISR

bool setInterruptBits ( uint8_t  ibits)

Enables interrupt generation based on passed interrupt bits. The bits are a bitmask of the requested MMA7660_INTR_T values. Note: the device must be in the standby mode to set this register.

Parameters
ibitsSets the requested interrupt bits
Returns
True if successful
bool setSampleRate ( MMA7660_AUTOSLEEP_T  sr)

Sets the sampling rate of the sensor. The value supplied must be one of the MMA7660_AUTOSLEEP_T values.

Parameters
srOne of the MMA7660_AUTOSLEEP_T values
Returns
True if successful

The documentation for this class was generated from the following files: