Accelerometer Serial Plotter values

I am getting a sawtooth wave from the serial plotter even when the sensor is not moving
SparkfunLIS3DH accelerometer. The wave does change when I move the accelerometer manually.


Thank you

#include "SparkFunLIS3DH.h"
#include "Wire.h"
#include "SPI.h"
#include <math.h> // Include the math library for sqrt function

LIS3DH myIMU; // Default constructor is I2C, addr 0x19.

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  delay(1000); // relax...
  Serial.println("Processor came out of reset.\n");

  // Call .begin() to configure the IMU
  myIMU.begin();
}

void loop() {
  // Get all parameters
  float accelX = myIMU.readFloatAccelX();
  float accelY = myIMU.readFloatAccelY();
  float accelZ = myIMU.readFloatAccelZ();

  float accelerationMagnitude = sqrt(accelX * accelX + accelY * accelY + accelZ * accelZ);

  Serial.print("\nAccelerometer:\n");
  Serial.print(" X = ");
  Serial.println(accelX, 4);
  Serial.print(" Y = ");
  Serial.println(accelY, 4);
  Serial.print(" Z = ");
  Serial.println(accelZ, 4);

  Serial.print("Acceleration Magnitude = ");
  Serial.println(accelerationMagnitude, 4);

  delay(500);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.