Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    Using the Arduino Nicla to read float data from sensors

    Using the Arduino Nicla to read float data from sensors

    chillin_panda
    New Poster

    We want to read accelerometer data using the Arduino Nicla,

    We need float data, we tried to modify the BHY2 library but it still giving us integer data.

     

    2 REPLIES 2

    zgg
    Long-established Member

    Hello

    It should be possible to print out data of float type provided that the Board support package supports it.

    for example, using the Nicla Board (from Board Manger) Support Package 2.9.9, and the example:Arduinio_BHY2->Standalone, you can see the data output for temperature and gas are floating point type.

    Could you share the Nicla Board Package version you are using? under menu->Boards Manager

    also, do you mind share a few snippets of your changes in the library?

    a sample change I tested was:

     

    ```

    diff --git a/Arduino_BHY2/src/sensors/DataParser.h b/Arduino_BHY2/src/sensors/DataParser.h
    index 7af5127..b174bea 100644
    --- a/Arduino_BHY2/src/sensors/DataParser.h
    +++ b/Arduino_BHY2/src/sensors/DataParser.h
    @@ -15,6 +15,13 @@ struct DataXYZ {
    + " Y: " + String(y)
    + " Z: " + String(z) + "\n");
    }
    +
    + String toString(float scale) {
    + return (String)("XYZ values - X: " + String(x * scale)
    + + " Y: " + String(y * scale)
    + + " Z: " + String(z * scale) + "\n");
    + }
    +
    };

    struct DataOrientation {
    diff --git a/Arduino_BHY2/src/sensors/SensorXYZ.h b/Arduino_BHY2/src/sensors/SensorXYZ.h
    index 88a36af..8a2a2ae 100644
    --- a/Arduino_BHY2/src/sensors/SensorXYZ.h
    +++ b/Arduino_BHY2/src/sensors/SensorXYZ.h
    @@ -28,7 +28,7 @@ public:

    String toString()
    {
    - return _data.toString();
    + return _data.toString(1 / 4096.f);
    }

    private:

    ```

     

     

    BSTRobin
    Community Moderator
    Community Moderator

    Hello chillin_panda,

    You could refer zgg's reply to get float data from BHI2 host side.

    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