Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    Arduino Nicla BHI260AP Timestamp and Data Logging to SPI Flash

    Arduino Nicla BHI260AP Timestamp and Data Logging to SPI Flash

    Moechl
    New Poster

    Hey everyone,

    I have posted this question two weeks ago in the Arduino forum but have not revceived any answers.

    I did an extensive amount of research and went throught the Arduino_BHY2 source code, but at this point, help would be much appreciated.

    I want record an acceleration signal with a rate of 1000 to 3200 Hz with a duration of 10 seconds, if possible. Afterwards I forward the data to a PC using USB. I use the Nicla Sense ME because it has an accelerometer and a 2 Mb data logging flash.

    I have written code (below) that does that at 1000 Hz, but for a shorter sample length of 0.5 seconds.

    I have two questions:

    1. My measurement is for verification of a mechanical system and I need to be able to trust the measurements. Therefore I would like to have a timestamp from the sample creation.
    I store my own timestamp in datalines[i][0]. As you can see in the output, the timing is all over the place, which is not much of a surprise, because my timestamp is made after transfer via serial from the sensor and buffering. Does anyone know how to get a timestamp for the respective reading from the sensor? Or can the sensor just be trusted with 1kHz samples?

    2. With my 0.5 second sample I already max out the Nicla's RAM. There is a data logging flash (MX25R1635FZUIH0) connected via SPI. I really don't want to start from scratch using the flash's data sheet, can anyone recommend a library or any simpler solution?

    Help would be much appreciated! I'm also happy to receive feedback on my coding as I think there is still a lot to learn for me.

    Thank you
    Moechl

    Code:

     

    #include "Arduino.h"
    #include "Arduino_BHY2.h"
    #include "Nicla_System.h"
    
    #define SAMPLE_LENGTH 500 //number of samples recorded; 500 is about the maximum for this RAM
    
    int sampleInterval = 1000; //microseconds
    int l = SAMPLE_LENGTH;
    int16_t datalines[SAMPLE_LENGTH][4]; // array where the data is stored
    
    SensorXYZ accel(SENSOR_ID_ACC);
    
    void setup()
    {
    Serial.begin(115200);
    while (!Serial);
    
    BHY2.begin(); //methods are defined in Arduino_BHY2.cpp
    accel.begin(1000, 0); //sample rate 1000 Hz, 0 ms latency
    
    nicla::begin();
    nicla::leds.begin();
    
    BHY2.delay(50);
    
    static auto sampleTime = micros();
    static auto startTime = millis();
    
    
    /* record values to datalines */
    
    for (int i = 0; i <= l; i++) {
    sampleTime = micros();
    while (micros() - sampleTime < sampleInterval) {
    BHY2.update(); // Update function should be continuously polled
    }
    datalines[i][0] = millis() - startTime; //does not give a good timestamp
    datalines[i][1] = accel.x();
    datalines[i][2] = accel.y();
    datalines[i][3] = accel.z();
    }
    
    
    BHY2.delay(50);
    
    /* write the data to PC over serial */
    for (int k = 0; k <= l; k++) {
    Serial.println(String(datalines[k][0]) + "," + String(datalines[k][1]) + "," + String(datalines[k][2]) + "," + String(datalines[k][3]) + ";");
    delay(30);
    }
    }
    
    void loop()
    {
    // blink so I know it is done
    nicla::leds.setColor(green);
    delay(1000);
    nicla::leds.setColor(off);
    delay(1000);
    
    }
    Output Excerpt:
    
    14:03:15.948 -> 1,1836,-816,3702;
    14:03:15.988 -> 33,1830,-823,3720;
    14:03:16.029 -> 34,1845,-824,3710;
    14:03:16.069 -> 39,1843,-822,3732;
    14:03:16.069 -> 41,1841,-812,3723;
    14:03:16.109 -> 42,1834,-816,3735;
    14:03:16.149 -> 43,1834,-816,3735;
    14:03:16.190 -> 44,1829,-826,3724;
    14:03:16.230 -> 49,1846,-819,3708;
    14:03:16.230 -> 50,1845,-821,3719;
    14:03:16.270 -> 51,1829,-820,3727;
    14:03:16.310 -> 52,1829,-820,3727;

     

     

    6 REPLIES 6

    Moechl
    New Poster

    May I ask for your help @BSTRobin  ?🙏

    BSTRobin
    Community Moderator
    Community Moderator

    Hi Moechl,

    We are checking now, and will give you feedback later.

    BSTRobin
    Community Moderator
    Community Moderator

    Hi Moechl,

    Current FW supports max ODR 400HZ.
    Regarding the timestamp of sensor you could refer to function BoschParser::parseGeneric in BoschParser.cpp, It print timestamp from FIFO for each sensor.

    Hi BSTRobin,

    thanks for the answer.

    As for the ODR, you are right I already noticed some temporal quantization when exceeding the 400 Hz. This is a bit unfortunate, as Arduino links this datasheet which on page 149 states a maximum ODR of 1600 Hz for the accelerometer and even the default sampling rate for the sensor seems to be 1000 Hz, when looking into SensorClass.h. Is there a way around this, maybe by using the "bhy2.h" directly?

    Using the BoschParser::parseGeneric function cannot work directly on arduino, because it does not support the printf function, if I am not mistaken. Is there a workaround? Maybe the bhy2_get_hw_timestamp_ns function in bhy2.c will help in the future. But getting a timestamp is not important if I cannot reach my desired sampling rate.

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist