Bosch Sensortec Community

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

    BHI160B BoschSensorHub library

    BHI160B BoschSensorHub library

    bgfas
    New Poster

    I am trying to bring up a board with a BHI160B. Is the library found at https://github.com/BoschSensortec/BoschSensorHub known to work for this sensor?

    The circuit involves a BHI160B with no attached secondary devices, should I be using the Bosch_PCB_7183_di03_BMI160-7183_di03.2.1.11696_170103.h firmware? The application only requires reading the accelerometer and gyroscope virtual sensors.

    26 REPLIES 26

    Hi BSTRobin,

    Thanks again for your reply. The code you pasted didn't compile. I made a few changes:

    """

    /* get virtual sensor information from sensor hub */
    Serial.println("Supported Virtual Sensor Information:\n");
    Serial.println("Supported Virtual Sensor Information:");
    Serial.println("-wakeup-");
    for(int i = 1; i < 32; i++)
    {
    //bhi160.getSensorInformation(BHY_VS_ORIENTATION, true, &information);
    bhi160.getSensorInformation((bhyVirtualSensor)i, true, &information);

    if(information.type == i){
    Serial.print("id=");
    Serial.println(i);
    }
    }

    Serial.println("-non-wakeup-");
    for(int i = 1; i < 32; i++)
    {
    bhi160.getSensorInformation((bhyVirtualSensor)i, false, &information);

    if(information.type == i){
    Serial.print("id=");
    Serial.println(i);
    }

    }
    //PDEBUG("");

    """

    the above code produced the following output:

    """

    Serial working
    Sensor found over I2C! Product ID: 0x83
    Uploading Firmware.
    Firmware booted
    Supported Virtual Sensor Information:

    Supported Virtual Sensor Information:
    -wakeup-
    -non-wakeup-
    id=1
    id=2
    id=3
    id=4
    id=9
    id=10
    id=11
    id=14
    id=15
    id=16
    id=17
    id=18
    id=19
    id=20
    id=22
    id=23
    id=24
    id=25
    id=31
    BHY_VS_ORIENTATION wakeup
    type: 35
    driver_id: 254
    driver_version: 1
    power: 0
    max_range: 1
    resolution: 16
    fifo_reserved: 0
    fifo_max: 1893
    event_size: 8
    min_rate: 1
    BHY_VS_ACCELEROMETER wakeup
    type: 33
    driver_id: 48
    driver_version: 1
    power: 1
    max_range: 4
    resolution: 16
    fifo_reserved: 0
    fifo_max: 1893
    event_size: 8
    min_rate: 1
    Orientation callback installed
    Failed to enable virtual sensor (Orientation (Non Wake-up)). Loaded firmware may not support requested sensor id.

    """

    Thanks again for your help. It is odd to me that no wakeup virtual sensors appeared supported.

    BSTRobin
    Community Moderator
    Community Moderator

    Hi bgfas,

    From your print information, non-wakeup sensor ID BHY_SID_ACCELEROMETER and BHY_VS_ORIENTATION had been supported. You could enable virtual sensor like this and test it again.
    bhi160.installSensorCallback(BHY_SID_WAKEUP_OFFSET + BHY_SID_ACCELEROMETER, false, accelerometerHandler))
    bhi160.configVirtualSensor(BHY_SID_WAKEUP_OFFSET + BHY_SID_ACCELEROMETER, false, BHY_FLUSH_ALL, 25, 0, 0, 0))

    Hi BSTRobin,

    Unfortunately those modifications do not work. I had to change the lines to get them to compile:

    bhi160.installSensorCallback((bhyVirtualSensor)(BHY_SID_WAKEUP_OFFSET + BHY_SID_ACCELEROMETER), false, accelerometerHandler)

    bhi160.configVirtualSensor((bhyVirtualSensor)(BHY_SID_WAKEUP_OFFSET + BHY_SID_ACCELEROMETER), false, BHY_FLUSH_ALL, 25, 0, 0, 0)

    However the accelerometer callback failed to install:

    """

    Failed to install accelerometer callback
    Error code: (-4). Out of range

    """

    The wakeup accelerometer (32 + 1) was not present in the output for the code you previously suggested (no wakeup sensors appeared supported, so no sensor ids >32). Does that help to explain why the callback registration fails? If so, what might be the issue?

    If I attempt to register a non-wakeup accelerometer (1), the callback registration does not return an error but the configuration does:

    """

    Accelerometer callback installed
    Failed to enable virtual sensor (Accelerometer (Non Wake-up)). Loaded firmware may not support requested sensor id.

    """

    Thanks again for your help.

    BSTRobin
    Community Moderator
    Community Moderator

    Hi bgfas,

    From your prevous test information, sensor ID 33, 35 have been supported in sensor list for the firmware. But it is strange you couldn't enable them.

    BSTRobin
    Community Moderator
    Community Moderator

    Hi bgfas,

    1. Previous code I provided had some mistake. Now you could use the following code to print sensor ID list.

    /* get virtual sensor information from sensor hub */
    Serial.println("Supported Virtual Sensor Information:\n");
    Serial.println("Supported Virtual Sensor Information:");
    Serial.println("-wakeup-");
    for(int i = 1; i < 32; i++)
    {
    bhi160.getSensorInformation((bhyVirtualSensor)i, true, &information);

    if(information.type == (i + BHY_SID_WAKEUP_OFFSET)){
    Serial.print("id=");
    Serial.println(i);
    }
    }

    Serial.println("-non-wakeup-");
    for(int i = 1; i < 32; i++)
    {
    bhi160.getSensorInformation((bhyVirtualSensor)i, false, &information);

    if(information.type == i){
    Serial.print("id=");
    Serial.println(i);
    }

    }

    2. Your previous code that use API to install and config ACC sensor ID is correct. But as the API return failed value, could you check where there is an error return in the function?
    bhi160.installSensorCallback(BHY_VS_ACCELEROMETER, true, accelerometerHandler);
    bhi160.configVirtualSensor(BHY_VS_ACCELEROMETER, true, BHY_FLUSH_ALL, 25, 0, 0, 0);

    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