upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions | Protected Attributes

API for the DFRobot MMA7361 Analog Accelerometer. More...

Detailed Description

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

// Instantiate a MMA7361 sensor on analog pins A0 (X), A1 (Y) A2
// (Z), selftest pin on D2, upm_delay pin on D3 nd an analog reference
// value of 5.0. The freefall pin and the range pin are unused
// (-1).
upm::MMA7361 sensor(0, 1, 2, 2, 3, -1, -1, 5.0);
// 1.5g (true = 6g)
sensor.setRange(false);
// Every 10th of a second, update and print values
while (shouldRun) {
sensor.update();
float x, y, z;
sensor.getAcceleration(&x, &y, &z);
cout << "Acceleration x = " << x << " y = " << y << "z = " << z << endl;
sensor.getVolts(&x, &y, &z);
cout << "Volts x = " << x << " y = " << y << "z = " << z << endl;
cout << endl;
upm_delay_us(100000);
}

Public Member Functions

 MMA7361 (int x_pin, int y_pin, int z_pin, int selftest_pin, int sleep_pin, int freefall_pin, int range_pin, float a_ref=5.0)
 
 ~MMA7361 ()
 
void setRange (bool range)
 
void setSleep (bool sleep)
 
bool isInFreefall ()
 
void enableSelftest (bool enable)
 
void update ()
 
void setOffset (float x, float y, float z)
 
void setScale (float x, float y, float z)
 
void getAcceleration (float *x, float *y, float *z)
 
float * getAcceleration ()
 
void getVolts (float *x, float *y, float *z)
 
float * getVolts ()
 
void getNormalized (float *x, float *y, float *z)
 
float * getNormalized ()
 

Protected Attributes

mma7361_context m_mma7361
 

Constructor & Destructor Documentation

MMA7361 ( int  x_pin,
int  y_pin,
int  z_pin,
int  selftest_pin,
int  sleep_pin,
int  freefall_pin,
int  range_pin,
float  a_ref = 5.0 
)

MMA7361 object constructor

Parameters
x_pinAnalog pin to use for X axis. -1 to disable.
y_pinAnalog pin to use for Y axis. -1 to disable.
z_pinAnalog pin to use for Z axis. -1 to disable.
selftest_pinGPIO pin to use for self test. -1 to disable.
sleep_pinGPIO pin to use for sleep function. -1 to disable.
freefall_pinGPIO pin to use for free fall (0g) detection. -1 to disable.
range_pinGPIO pin to select range (1.5g or 6g). -1 to disable.
a_refThe analog reference voltage in use. Default 5.0.
~MMA7361 ( )

MMA7361 object destructor

Here is the call graph for this function:

Member Function Documentation

void setRange ( bool  range)

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

Parameters
rangetrue for 6G, false for 1.5G

Here is the call graph for this function:

void setSleep ( bool  sleep)

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

Parameters
sleeptrue to go into sleep mode, false to wake up

Here is the call graph for this function:

bool isInFreefall ( )

Get freefall detection status.

Returns
true if a freefall condition is detected, false otherwise.

Here is the call graph for this function:

void enableSelftest ( bool  enable)

Enable self test mode.

Parameters
enabletrue to enable the self test mode, false otherwise.

Here is the call graph for this function:

void update ( void  )

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

Here is the call graph for this function:

void setOffset ( float  x,
float  y,
float  z 
)

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

Parameters
xOffset to apply to X value
yOffset to apply to Y value
zOffset to apply to Z value

Here is the call graph for this function:

void setScale ( float  x,
float  y,
float  z 
)

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

Parameters
xScale to apply to X value
yScale to apply to Y value
zScale to apply to Z value

Here is the call graph for this function:

void getAcceleration ( float *  x,
float *  y,
float *  z 
)

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

Parameters
xa pointer in which X acceleration data will be returned
ya pointer in which Y acceleration data will be returned
za pointer in which Z acceleration data will be returned

Here is the call graph for this function:

float * getAcceleration ( )

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

Returns
a pointer to a statically allocated array of 3 floats containing the X, Y, and Z componenets.
void getVolts ( float *  x,
float *  y,
float *  z 
)

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

Parameters
xa pointer in which X volt data will be returned
ya pointer in which Y volt data will be returned
za pointer in which Z volt data will be returned

Here is the call graph for this function:

float * getVolts ( )

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

Returns
a pointer to a statically allocated array of 3 floats containing the X, Y, and Z componenets.
void getNormalized ( float *  x,
float *  y,
float *  z 
)

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

Parameters
xa pointer in which X normalized ADC data will be returned
ya pointer in which Y normalized ADC data will be returned
za pointer in which Z normalized ADC data will be returned

Here is the call graph for this function:

float * getNormalized ( )

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

Returns
a pointer to a statically allocated array of 3 ints containing the X, Y, and Z componenets.
Collaboration diagram for MMA7361:
Collaboration graph
[legend]

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