I want my code to be able to determine the direction of motion for the LIS2DE12 accelerometer. I did a test where I had the accelerometer on a breadboard (connected to the STM32) and logged the values over UART while the breadboard was at rest and when I slid the board in one direction.
When the board is not moving, the values make sense:
Timestamp: 26852, X: -0.63, Y: -0.47, Z: 10.04
Timestamp: 26869, X: -0.47, Y: -0.47, Z: 9.89
Timestamp: 26886, X: -0.78, Y: -0.63, Z: 10.20
The z-axis is the gravity axis and although it's not perfect, it's close to 9.8 m/s^2. The x and y axes are near 0. When I move the board in one direction, just sliding it in the x-direction on a table, I would expect the values to either consistently increase in the positive or negative direction. But the values jump all over the place and switch from positive to negative or vice versa, and switch between increasing and decreasing. What could be going on here?
These are data samples during the time of movement:
Timestamp: 26920, X: 4.24, Y: 1.73, Z: 11.30
Timestamp: 26936, X: -0.47, Y: -2.04, Z: 10.20
Timestamp: 26953, X: 0.47, Y: -1.10, Z: 8.47
Timestamp: 26969, X: 2.51, Y: -1.73, Z: 13.02
Timestamp: 26986, X: 0.16, Y: -2.35, Z: 10.51
Timestamp: 27003, X: -1.10, Y: 0.94, Z: 8.32
Timestamp: 27019, X: 2.82, Y: 1.57, Z: 12.71
Timestamp: 27035, X: 0.63, Y: -0.94, Z: 12.87
Timestamp: 27052, X: 2.35, Y: -6.28, Z: 11.61
Timestamp: 27069, X: -0.31, Y: 0.31, Z: 10.98
Timestamp: 27086, X: -1.73, Y: 0.47, Z: 3.92
Timestamp: 27102, X: 1.73, Y: -5.65, Z: 10.20
Timestamp: 27119, X: 0.00, Y: -8.63, Z: 8.32
Timestamp: 27135, X: 3.92, Y: 0.47, Z: 16.16
Timestamp: 27151, X: 2.98, Y: -7.06, Z: 13.65
Timestamp: 27168, X: -1.73, Y: -1.88, Z: 11.45