datalog

Dependencies:   BSP_B-L475E-IOT01

main.cpp

Committer:
sertackilickaya
Date:
17 months ago
Revision:
0:656457722e56

File content as of revision 0:656457722e56:

#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);
    }
}