Hello. I plan to use accelerometer to measure the vibrations of cnc machine spindle. I have picked up a LIS3DH module and wired it up to a microcontroller using I2C. I have downloaded Adafruit LIS3DH library which makes it very easy to interface with the accelerometer. The sketch is as following:
The current configuration:
Range: 2G
Data rate : 200HZ
High resolution (12-bit mode) is enabled.
When I look at the readings over few seconds when the accelerometer is standing still on my table:

I have 2 main questions:
1. As you can see, the readings fluctuate quite a bit ( for example Z axis can read as low as 15800 and as high as 16100 ). Is this normal behaviour? I am worried that this is going to cause problems when I am trying to measure slight vibrations of the spindle
2. Is there a good way to calibrate it for my environment so when its standing where all the force is towards the Z axis, the other 2 axis should read as close to 0 as possible?
This perhaps is not the best way to measure the spindle vibrations but keep in mind that this is a school project and it does not have to be perfect. As long as I can get some sort of viable results - it is fine. I am hoping to get some clarification from someone who is fammiliar with the LIS3DH chip and how it supposed to operate
Code:
// Basic demo for accelerometer readings from Adafruit LIS3DH
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>
// Used for software SPI
#define LIS3DH_CLK 13
#define LIS3DH_MISO 12
#define LIS3DH_MOSI 11
// Used for hardware & software SPI
#define LIS3DH_CS 10
// software SPI
//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS, LIS3DH_MOSI, LIS3DH_MISO, LIS3DH_CLK);
// hardware SPI
//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS);
// I2C
Adafruit_LIS3DH lis = Adafruit_LIS3DH();
void setup(void) {
Serial.begin(115200);
while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("LIS3DH test!");
if (! lis.begin(0x18)) { // change this to 0x19 for alternative i2c address
Serial.println("Couldnt start");
while (1) yield();
}
// to turn on high resolution:
//ctrl_reg1[3] LPEN bit - 0
//ctrl_reg4[3] HR bit - 1
Serial.println("LIS3DH found!");
lis.setRange(LIS3DH_RANGE_2_G); // 2, 4, 8 or 16 G!
Serial.print("Range = "); Serial.print(2 << lis.getRange());
Serial.println("G");
lis.setDataRate(LIS3DH_DATARATE_200_HZ);
Serial.print("Data rate set to: ");
switch (lis.getDataRate()) {
case LIS3DH_DATARATE_1_HZ: Serial.println("1 Hz"); break;
case LIS3DH_DATARATE_10_HZ: Serial.println("10 Hz"); break;
case LIS3DH_DATARATE_25_HZ: Serial.println("25 Hz"); break;
case LIS3DH_DATARATE_50_HZ: Serial.println("50 Hz"); break;
case LIS3DH_DATARATE_100_HZ: Serial.println("100 Hz"); break;
case LIS3DH_DATARATE_200_HZ: Serial.println("200 Hz"); break;
case LIS3DH_DATARATE_400_HZ: Serial.println("400 Hz"); break;
case LIS3DH_DATARATE_POWERDOWN: Serial.println("Powered Down"); break;
case LIS3DH_DATARATE_LOWPOWER_5KHZ: Serial.println("5 Khz Low Power"); break;
case LIS3DH_DATARATE_LOWPOWER_1K6HZ: Serial.println("16 Khz Low Power"); break;
}
}
void loop() {
lis.read(); // get X Y and Z data at once
// Then print out the raw data
Serial.print("X: "); Serial.print(lis.x);
Serial.print(" \tY: "); Serial.print(lis.y);
Serial.print(" \tZ: "); Serial.print(lis.z);
/* Or....get a new sensor event, normalized */
sensors_event_t event;
lis.getEvent(&event);
/* Display the results (acceleration is measured in m/s^2) */
Serial.print("\t\tX: "); Serial.print(event.acceleration.x);
Serial.print(" \tY: "); Serial.print(event.acceleration.y);
Serial.print(" \tZ: "); Serial.print(event.acceleration.z);
Serial.println(" m/s^2 ");
Serial.println();
delay(200);
}
Range: 2G
Data rate : 200HZ
High resolution (12-bit mode) is enabled.
When I look at the readings over few seconds when the accelerometer is standing still on my table:

I have 2 main questions:
1. As you can see, the readings fluctuate quite a bit ( for example Z axis can read as low as 15800 and as high as 16100 ). Is this normal behaviour? I am worried that this is going to cause problems when I am trying to measure slight vibrations of the spindle
2. Is there a good way to calibrate it for my environment so when its standing where all the force is towards the Z axis, the other 2 axis should read as close to 0 as possible?
This perhaps is not the best way to measure the spindle vibrations but keep in mind that this is a school project and it does not have to be perfect. As long as I can get some sort of viable results - it is fine. I am hoping to get some clarification from someone who is fammiliar with the LIS3DH chip and how it supposed to operate