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.

MMA7361 Class

Module: mma7361

This library was tested with the DFRobot MMA7361 Analog Accelerometer. It supports 3 Axes with a selectable 1.5G and 6G sensitivity.

Methods

MMA7361

(
  • x_pin
  • y_pin
  • z_pin
  • selftest_pin
  • sleep_pin
  • freefall_pin
  • range_pin
  • a_ref
)
Number

MMA7361 object constructor

Parameters:

  • x_pin Number

    Analog pin to use for X axis. -1 to disable.

  • y_pin Number

    Analog pin to use for Y axis. -1 to disable.

  • z_pin Number

    Analog pin to use for Z axis. -1 to disable.

  • selftest_pin Number

    GPIO pin to use for self test. -1 to disable.

  • sleep_pin Number

    GPIO pin to use for sleep function. -1 to disable.

  • freefall_pin Number

    GPIO pin to use for free fall (0g) detection. -1 to disable.

  • range_pin Number

    GPIO pin to select range (1.5g or 6g). -1 to disable.

  • a_ref Number

    The analog reference voltage in use. Default 5.0.

Returns:

Number:

setRange

(
  • range
)

Set the range of the device. This device supports two G ranges: 1.5 and 6. The default is 1.5G.

Parameters:

  • range Boolean

    true for 6G, false for 1.5G

setSleep

(
  • sleep
)

Set sleep mode. When in sleep mode the sensor uses minimal power.

Parameters:

  • sleep Boolean

    true to go into sleep mode, false to wake up

isInFreefall

() Boolean

Get freefall detection status.

Returns:

Boolean:

true if a freefall condition is detected, false otherwise.

enableSelftest

(
  • enable
)

Enable self test mode.

Parameters:

  • enable Boolean

    true to enable the self test mode, false otherwise.

update

()

Read the sensor status an update internal state. update() must have been called before calling getAcceleration() , getNormalized() , or getVolts() .

setOffset

(
  • x
  • y
  • z
)

Set sensor offset. This offset is applied to the return values before scaling. Default is 0.0.

Parameters:

  • x Number

    Offset to apply to X value

  • y Number

    Offset to apply to Y value

  • z Number

    Offset to apply to Z value

setScale

(
  • x
  • y
  • z
)

Set sensor scale. The acceleration return values are scaled by this value before the offset is applied. Default is 1.0.

Parameters:

  • x Number

    Scale to apply to X value

  • y Number

    Scale to apply to Y value

  • z Number

    Scale to apply to Z value

getAcceleration

(
  • x
  • y
  • z
)

Get computed acceleration from the sensor. update() must have been called prior to calling this function.

Parameters:

  • x Float *

    a pointer in which X acceleration data will be returned

  • y Float *

    a pointer in which Y acceleration data will be returned

  • z Float *

    a pointer in which Z acceleration data will be returned

getAcceleration

() Float *

Get computed acceleration from the sensor. update() must have been called prior to calling this function.

Returns:

Float *:

a pointer to a statically allocated array of 3 floats containing the X, Y, and Z componenets.

getVolts

(
  • x
  • y
  • z
)

Get the measured volts from the sensor. update() must have been called prior to calling this function.

Parameters:

  • x Float *

    a pointer in which X volt data will be returned

  • y Float *

    a pointer in which Y volt data will be returned

  • z Float *

    a pointer in which Z volt data will be returned

getVolts

() Float *

Get the measured volts from the sensor. update() must have been called prior to calling this function.

Returns:

Float *:

a pointer to a statically allocated array of 3 floats containing the X, Y, and Z componenets.

getNormalized

(
  • x
  • y
  • z
)

Get the normalized ADC values from the sensor. update() must have been called prior to calling this function.

Parameters:

  • x Float *

    a pointer in which X normalized ADC data will be returned

  • y Float *

    a pointer in which Y normalized ADC data will be returned

  • z Float *

    a pointer in which Z normalized ADC data will be returned

getNormalized

() Float *

Get the normalized ADC values from the sensor. update() must have been called prior to calling this function.

Returns:

Float *:

a pointer to a statically allocated array of 3 ints containing the X, Y, and Z componenets.