1
4
5
6#include "Wire.h"
7#include <LIS2DW12Sensor.h>
8
9
10#define SERIAL_BAUD_RATE 115200
11
12
16#define SENSOR_DATA_RATE 1600.0f
17
18
22#define SENSOR_RANGE 4
23
24
25#define SENSOR_SAMPLES 1024
26#define AXIS 3
27
28
29LIS2DW12Sensor Accelero(&Wire);
30
31
32static uint8_t drdy = 0;
33static uint16_t neai_ptr = 0;
34static int32_t accelerometer[3];
35static float neai_buffer[SENSOR_SAMPLES * AXIS] = {0.0};
36
37
38
41void setup() {
42
43 Serial.begin(SERIAL_BAUD_RATE);
44
45
49 pinMode(SCL, OUTPUT);
50 for (uint8_t i = 0; i < 20; i++) {
51 digitalWrite(SCL, !digitalRead(SCL));
52 delay(1);
53 }
54 delay(100);
55
56 Wire.begin();
57 Accelero.begin();
58 Accelero.Enable_X();
59 Accelero.Set_X_ODR(SENSOR_DATA_RATE);
60 Accelero.Set_X_FS(SENSOR_RANGE);
61}
62
63
64void loop() {
65
66 while (neai_ptr < SENSOR_SAMPLES) {
67
68 Accelero.ReadReg(LIS2DW12_STATUS, &drdy);
69 if (drdy & 0x01) {
70
71 Accelero.Get_X_Axes(accelerometer);
72
73 neai_buffer[AXIS * neai_ptr] = (float) accelerometer[0];
74 neai_buffer[(AXIS * neai_ptr) + 1] = (float) accelerometer[1];
75 neai_buffer[(AXIS * neai_ptr) + 2] = (float) accelerometer[2];
76
77 neai_ptr++;
78 }
79 }
80
81 neai_ptr = 0;
82
83
84 for (uint16_t i = 0; i < AXIS * SENSOR_SAMPLES; i++) {
85 Serial.print((String)neai_buffer[i] + " ");
86 }
87 Serial.print("\n");
88
89
90
91 memset(neai_buffer, 0.0, AXIS * SENSOR_SAMPLES * sizeof(float));
92}
mad_mcu_algorithm
6 months ago
So cute the cat.