Accel Sample
This application demonstrates reading G values applied to X, Y and Z axes.
To run the example:
  1. 1.
    Open the IoT_Node_AccelTilt_Accel sketch from the examples menu.
  2. 2.
    Select Turta IoT Node from the Tools > Board menu.
  3. 3.
    Select your device's COM port from Tools > Port menu.
  4. 4.
    Open Serial Monitor from Tools > Serial Monitor.
  5. 5.
    Select 115.200 baud from the Serial Monitor's status bar.
  6. 6.
    Upload the code to your device.

Sample Code

IoT_Node_AccelTilt_Accel.ino
#include <Turta_AccelTilt_Module.h>
// Create Accel & Tilt Sensor instance.
Turta_AccelTilt_Module accel;
void setup() {
// Initialize Accel & Tilt Sensor.
accel.begin();
// Configure serial port.
Serial.begin(115200);
delay(200);
}
void loop() {
// Read X-Axis.
double xAxisG = accel.readXAxis();
Serial.print("X: ");
Serial.println(xAxisG);
// Read Y-Axis.
double yAxisG = accel.readYAxis();
Serial.print("Y: ");
Serial.println(yAxisG);
// Read Z-Axis.
double zAxisG = accel.readZAxis();
Serial.print("Z: ");
Serial.println(zAxisG);
// Read X, Y, Z-Axis at one shot.
double x, y, z;
accel.readXYZAxis(x, y, z);
Serial.print("X: ");
Serial.print(x);
Serial.print(", Y: ");
Serial.print(y);
Serial.print(", Z: ");
Serial.println(z);
// Print an empty line.
Serial.println("");
// Delay 100ms.
delay(100);
}

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:
X: 0.12
Y: 0.34
Z: 0.92
X: 0.12, Y: 0.34, Z: 0.92
The application runs forever until you clear it from memory.
Last modified 2yr ago
Copy link
On this page
Sample Code
Result