UPM

The UPM API is a high level sensor library for IoT devices using MRAA. See examples here. Back to index page.
SparkFun sensor images provided under CC BY-NC-SA-3.0.

MMA7660 Class

Module: mma7660

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

Methods

MMA7660

(
  • bus
  • address
)
Number

MMA7660 constructor

Parameters:

  • bus Number

    I2C bus to use

  • address Number

    Address for this sensor; default is 0x55

Returns:

Number:

writeByte

(
  • reg
  • byte
)
Boolean

Writes a byte value into a register

Parameters:

  • reg Number

    Register location to write into

  • byte Number

    Byte to write

Returns:

Boolean:

True if successful

readByte

(
  • reg
)
Number

Reads a byte value from a register

Parameters:

  • reg Number

    Register location to read from

Returns:

Number:

Value in a specified register

getRawValues

(
  • x
  • y
  • z
)

Reads the current value of conversion

Parameters:

  • x Int *

    Returned x value

  • y Int *

    Returned y value

  • z Int *

    Returned z value

getAcceleration

(
  • ax
  • ay
  • az
)

Gets the computed acceleration

Parameters:

  • ax Float *

    Returned computed acceleration of the X-axis

  • ay Float *

    Returned computed acceleration of the Y-axis

  • az Float *

    Returned computed acceleration of the Z-axis

getVerifiedAxis

(
  • axis
)
Number

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

Parameters:

  • axis MMA7660_REG_T

    Axis to read

Returns:

Number:

Axis value

getVerifiedTilt

() Number

Reads the tilt register, verifying its validity

Returns:

Number:

Tilt value

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.

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.

tiltBackFront

() Number

Reads tiltBackFront bits
The value returned is one of the MMA7660_TILT_BF_T values

Returns:

Number:

Bits corresponding to the BackFront tilt status

tiltLandscapePortrait

() Number

Reads tiltLandscapePortrait bits
The value returned is one of the MMA7660_TILT_LP_T values

Returns:

Number:

Bits corresponding to the LandscapePortrait tilt status

tiltTap

() Boolean

Reads the tiltTap status

Returns:

Boolean:

True if a tap is detected

tiltShake

() Boolean

Reads the tiltShake status

Returns:

Boolean:

True if a shake is detected

uninstallISR

()

Uninstalls the previously installed ISR

setInterruptBits

(
  • ibits
)
Boolean

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:

  • ibits Number

    Sets the requested interrupt bits

Returns:

Boolean:

True if successful

setSampleRate

(
  • sr
)
Boolean

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

Parameters:

  • sr MMA7660_AUTOSLEEP_T

    One of the MMA7660_AUTOSLEEP_T values

Returns:

Boolean:

True if successful

getAcceleration

() Std::vector float

Reads the current acceleration values. The returned memory is statically allocated and will be overwritten on each call.

Returns:

Std::vector float :

std::vector containing x, y, z.

getRawValues

() Std::vector int

Reads the current value of conversion. The returned memory is statically allocated and will be overwritten on each call.

Returns:

Std::vector int :

std::vector containing x, y, z.

installISR

(
  • pin
  • isr
  • arg
)

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

Parameters:

  • pin Number

    GPIO pin to use as the interrupt pin

  • isr Function

    Pointer to a function to be called on interrupt

  • arg Void *

    Pointer to an object to be supplied as an argument to the ISR.