datalog
Dependencies: BSP_B-L475E-IOT01
Diff: main.cpp
- Revision:
- 0:656457722e56
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Nov 28 11:27:38 2022 +0000 @@ -0,0 +1,47 @@ +#include "mbed.h" +#include "stm32l475e_iot01_accelero.h" +// use mbedOs 6 and bsp init change odr to 6660 +// Full-scale range = 4g +static int64_t sampling_freq = 6660; // in Hz. +static int64_t time_between_samples_us = (1000000 / (sampling_freq - 1)); + +// to classify 1 frame of data you need FRAME_SIZE values +static int16_t aX[6660]={0}; +static int16_t aY[6660]={0}; +static int16_t aZ[6660]={0}; + +// set baud rate of serial port to 115200 +static BufferedSerial serial_port(USBTX, USBRX, 921600); +FileHandle *mbed::mbed_override_console(int fd) { + return &serial_port; +} + +int main() +{ + int16_t pDataXYZ[3] = {0}; + BSP_ACCELERO_Init(); + Timer t; + t.start(); + while (1) { + // fill the features array + for (size_t ix = 0; ix < 6660; ix++) { + int64_t next_tick = t.read_us() + time_between_samples_us; + BSP_ACCELERO_AccGetXYZ(pDataXYZ); + + // copy accelerometer data into the features array + aX[ix] = pDataXYZ[0]; + aY[ix] = pDataXYZ[1]; + aZ[ix] = pDataXYZ[2]; + + while (t.read_us() < next_tick) { + /* busy loop */ + } + } + // print the predictions + for (size_t ix = 0; ix < 6660; ix++) { + printf("%d,%d,%d\n\r",aX[ix],aY[ix],aZ[ix]); + } + + ThisThread::sleep_for(3s); + } +} \ No newline at end of file