MMA8491Q Accel Tilt Sensor
This documentation includes installation guidelines and sample code for your hardware.

Overall Info

MMA8491Q is a 3-axis accelerometer with tilt sensing and digital accelerometer functions.

Sensor Connections

    SCL: D12.
    SDA: D11.
    EN: D6.
    INT X: A3.
    INT Y: A2.
    INT Z: A1.
    POWER: VCC (+3.3V) and GND.

Specifications

MMA8491Q's technical specifications are as follows:
    Range: ±8 g full-scale range.
    Sensitivity: 14-bit digital output, 1 mg/LSB sensitivity
    Tilt Detection: 3-Axis, 43.5° / 0.688g.
    Output Data Rate: Up to 800Hz.

Arduino Library

Turta_AccelTilt_Sensor library is responsible for reading the accelerometer and tilt data.
To use the library on Arduino IDE, add the following #include statement to the top of your sketch.
1
#include <Turta_AccelTilt_Sensor.h>
Copied!
Then, create an instance of the Turta_AccelTilt_Sensor class.
1
Turta_AccelTilt_Sensor accel
Copied!
Now you're ready to access the library by calling the accel instance.

Initialization

To initialize the module, call the begin method.
1
begin()
Copied!
This method configures the I2C bus and GPIO pins to read sensor data.

Basic Members

Read X-Axis

Returns the G value of the X axis.
1
double readXAxis()
Copied!
    Parameters
      None.
    Returns
      Double: G Value of the X axis.

Read Y-Axis

Returns the G value of the Y axis.
1
double readYAxis()
Copied!
    Parameters
      None.
    Returns
      Double: G Value of the Y axis.

Read Z-Axis

Returns the G value of the Z axis.
1
double readZAxis()
Copied!
    Parameters
      None.
    Returns
      Double: G Value of the Z axis.

Read XYZ Axis

Returns the values of all axes in a single shot.
1
void readXYZAxis(double x, double y, double z)
Copied!
    Parameters
      Double: x out
      Double: y out
      Double: z out
    Returns
      None

Read Tilt State

Returns the tilt state of all axes.
1
void readTiltState(bool xTilt, bool yTilt, bool zTilt)
Copied!
    Parameters
      Bool: xTilt out
      Bool: yTilt out
      Bool: zTilt out
    Returns
      None

Examples

You can open the examples from Arduino IDE > File > Examples > Examples from Custom Libraries > Turta MKR Sensor Shield > Accel Tilt Sensor. There are two examples of this sensor.

Accel

This application demonstrates reading G values applied to X, Y and Z axes.
To run the example:
    1.
    Open the Accel sketch from the examples menu.
    2.
    Select your Arduino MKR series board from the Tools > Board menu.
    3.
    Select your device's COM port from Tools > Port menu.
    4.
    Open Serial Monitor from Tools > Serial Monitor.
    5.
    Select 115.200 baud from the Serial Monitor's status bar.
    6.
    Upload the code to your device.
Sample Code
Accel.ino
1
#include <Turta_AccelTilt_Sensor.h>
2
3
// Create Accel & Tilt Sensor instance.
4
Turta_AccelTilt_Sensor accel;
5
6
void setup() {
7
// Initialize Accel & Tilt Sensor.
8
accel.begin();
9
10
// Configure serial port.
11
Serial.begin(115200);
12
delay(200);
13
}
14
15
void loop() {
16
// Read X-Axis.
17
double xAxisG = accel.readXAxis();
18
Serial.print("X: ");
19
Serial.println(xAxisG);
20
21
// Read Y-Axis.
22
double yAxisG = accel.readYAxis();
23
Serial.print("Y: ");
24
Serial.println(yAxisG);
25
26
// Read Z-Axis.
27
double zAxisG = accel.readZAxis();
28
Serial.print("Z: ");
29
Serial.println(zAxisG);
30
31
// Read X, Y, Z-Axis at one shot.
32
double x, y, z;
33
accel.readXYZAxis(x, y, z);
34
Serial.print("X: ");
35
Serial.print(x);
36
Serial.print(", Y: ");
37
Serial.print(y);
38
Serial.print(", Z: ");
39
Serial.println(z);
40
41
// Print an empty line.
42
Serial.println("");
43
44
// Delay 100ms.
45
delay(100);
46
}
Copied!
Result
After the application is uploaded to the device, it writes G forces applied to all axes to the Serial Monitor. The example output should be like this:
1
X: 0.12
2
Y: 0.34
3
Z: 0.92
4
X: 0.12, Y: 0.34, Z: 0.92
Copied!
The application runs forever until you clear it from memory.

Tilt

This application demonstrates reading tilt states of X, Y, and Z axes.
To run the example:
    1.
    Open the Tilt sketch from the examples menu.
    2.
    Select your Arduino MKR series board from the Tools > Board menu.
    3.
    Select your device's COM port from Tools > Port menu.
    4.
    Open Serial Monitor from Tools > Serial Monitor.
    5.
    Select 115.200 baud from the Serial Monitor's status bar.
    6.
    Upload the code to your device.
Sample Code
Tilt.ino
1
#include <Turta_AccelTilt_Sensor.h>
2
3
// Create Accel & Tilt Sensor instance.
4
Turta_AccelTilt_Sensor accel;
5
6
void setup() {
7
// Initialize Accel & Tilt Sensor.
8
accel.begin();
9
10
// Configure serial port.
11
Serial.begin(115200);
12
delay(200);
13
}
14
15
void loop() {
16
// Read Tilt State.
17
bool xTilt, yTilt, zTilt;
18
accel.readTiltState(xTilt, yTilt, zTilt);
19
Serial.print("X: ");
20
Serial.print(xTilt ? "Tilt" : "Flat");
21
Serial.print(", Y: ");
22
Serial.print(yTilt ? "Tilt" : "Flat");
23
Serial.print(", Z: ");
24
Serial.println(zTilt ? "Tilt" : "Flat");
25
26
// Delay 100ms.
27
delay(100);
28
}
Copied!
Result
After the application is uploaded to the device, it writes tilt states to the Serial Monitor. The example output should be like this:
1
X: Flat, Y: Flat, Z: Tilt
2
X: Flat, Y: Flat, Z: Tilt
3
X: Flat, Y: Tilt, Z: Flat
4
X: Flat, Y: Tilt, Z: Flat
Copied!
The application runs forever until you clear it from memory.
Last modified 2yr ago