Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    Unable to read Data from BHI160B IMU sensor

    Unable to read Data from BHI160B IMU sensor

    vamshi
    Established Member

    Hi,

    We are working on BHI160B IMU and Reading data from the past one week using Arduino code("BoschSensorHub-master"(example:Orientation.ino)). When we were taking Data from BHI160B we observed that it has suddenly stopped giving data. We checked it again, able to read product ID(0x83) and Sensor configuration as below. But unable to read actual Data then found that Interrupt has not triggered. What could be the reason? Can anyone help me to resolve this?

    image (3).png


    Thanks in advance. 

    3 REPLIES 3

    BSTRobin
    Community Moderator
    Community Moderator

    Hi vamshi,

    Could we know where your BHI160B software gets from?

    vamshi
    Established Member

    Thank you for the reply @BSTRobin,

    We are working on attached Orientation.ino code got from https://github.com/BoschSensortec/BoschSensorHub/tree/master/examples/orientation We are able to read Dev ID and Sensor Configuration But it is getting struck In the void loop. where newOrientation data condition was not true.
    Please see the attached code and help me.

    void setup()
    {
        disableCore0WDT();
        disableLoopWDT();
        
        Serial.begin(115200);
        Wire.begin();
    
        if (Serial)
        {
            Serial.println("Serial working");
        }
        attachInterrupt(BHY_INT_PIN, bhyInterruptHandler, RISING);//RISING
    
        bhi160.begin(BHY_I2C_ADDR);//BHY_I2C_ADDR2-->if SA_GPIO7(high)
    
        /* Check to see if something went wrong. */
        if (!checkSensorStatus())
            return;
    
        Serial.println("Sensor found over I2C! Product ID: 0x" + String(bhi160.productId, HEX));
        
        Serial.println("Uploading Firmware.");
        bhi160.loadFirmware(bhy1_fw);
    
        if (!checkSensorStatus())
            return;
    
        intrToggled = false; /* Clear interrupt status received during firmware upload */
        waitForBhyInterrupt();  /* Wait for meta events from boot up */
       // Serial.println("Firmware booted");
    
        /* Install a metaevent callback handler and a timestamp callback handler here if required before the first run */
        bhi160.run(); /* The first run processes all boot events */
        
        /* Install a vector callback function to process the data received from the wake up Orientation sensor */
        if (bhi160.installSensorCallback(BHY_VS_ORIENTATION, true, orientationHandler)) 
        {
            checkSensorStatus();
            return;
        }
        else
            Serial.println("Orientation callback installed"); 
      
        /* Enable the Orientation virtual sensor that gives you the heading, roll, pitch
           based of data from the accelerometer, gyroscope and magnetometer.
           The sensor is set into wake up mode so as to interrupt the host when a new sample is available
           Additionally, the FIFO buffer of the sensor is flushed for all previous data
           The maximum report latency of the sensor sample, the sensitivity and the dynamic range
           are set to 0
         */
        if (bhi160.configVirtualSensor(BHY_VS_ORIENTATION, true, BHY_FLUSH_ALL, 200, 0, 0, 0)) 
        {
            Serial.println("Failed to enable virtual sensor (" + bhi160.getSensorName(
                              BHY_VS_ORIENTATION) + "). Loaded firmware may not support requested sensor id.");
        }
        else
            Serial.println(bhi160.getSensorName(BHY_VS_ORIENTATION) + " virtual sensor enabled");   
        
        status = bhi160.getSensorInformation(BHY_VS_ORIENTATION, true, &informations); 
        
        if (bhi160.status == BHY_OK)
        {
          gu8InformBuf[0] = (uint16_t)informations.driver_id;
          gu8InformBuf[1] = (uint16_t)informations.max_range;
          gu8InformBuf[2] = (uint16_t)informations.resolution;
          gu8InformBuf[3] = (uint16_t)informations.max_rate;
          Serial.println("Sensor Information:"); Serial.println(gu8InformBuf[0], HEX);
          Serial.println(gu8InformBuf[1], HEX); Serial.println(gu8InformBuf[2], HEX);  Serial.println(gu8InformBuf[3], HEX);
    
          Serial.println("Sensor Information:"); Serial.print("Sample Rate:"); Serial.println(gu8InformBuf[0]);
          Serial.print("Max Range:");Serial.println(gu8InformBuf[1]); Serial.print("Resolution:");Serial.println(gu8InformBuf[2]);  
          Serial.print("Max_Rate:");Serial.println(gu8InformBuf[3]);
        }
        status = bhi160.getConfiguration(BHY_VS_ORIENTATION, true, &configurations); 
        if (bhi160.status == BHY_OK)
        {
          gu8ConfigBuf[0] = (uint16_t)configurations.sampleRate;
          gu8ConfigBuf[1] = (uint16_t)configurations.maxReportLatency;
          gu8ConfigBuf[2] = (uint16_t)configurations.changeSensitivity;
          gu8ConfigBuf[3] = (uint16_t)configurations.dynamicRange;
          Serial.println("Sensor Configuration:"); Serial.println(gu8ConfigBuf[0], HEX);
          Serial.println(gu8ConfigBuf[1], HEX); Serial.println(gu8ConfigBuf[2], HEX);  Serial.println(gu8ConfigBuf[3], HEX);
    
          Serial.println("Sensor Configuration:"); Serial.print("Sample Rate:"); Serial.println(gu8ConfigBuf[0]);
          Serial.print("Max Report Latency:");Serial.println(gu8ConfigBuf[1]); Serial.print("Sensitivity:");Serial.println(gu8ConfigBuf[2]);  
          Serial.print("Dynamic Range:"); Serial.println(gu8ConfigBuf[3]);
        }
    }
    
    void loop()
    {
        if (intrToggled)
        {
            intrToggled = false;
            bhi160.run();
            checkSensorStatus();
    
            if (newOrientationData)
            {
                /* Can also be viewed using the plotter */
                Serial.println(String(roll) + "," + String(pitch) + "," + String(heading));// + "," + String(status)
                newOrientationData = false;
            }
         }
    }
    void orientationHandler(bhyVector data, bhyVirtualSensor type) //<--  
    {
        roll = data.z;
        pitch = data.y;
        heading = data.x;
    
        status = data.status;
        newOrientationData = true;
    }

     

    Thank you

    BSTRobin
    Community Moderator
    Community Moderator

    Hi vamshi,

    You could add the following code to check whether the revision ID(0x03) matches the firmware?

    int8_t BHYSensor::begin(uint8_t i2cAddress, TwoWire &wire)
    {
    deviceId = i2cAddress;
    revisionId;
    i2c = &wire;
    const uint8_t nTries = 5;
    uint8_t tries = nTries;
    uint8_t data;

    i2c->begin();

    while (tries > 0)
    {
    status = read(BHY_REG_PRODUCT_ID_ADDR, &data);
    revisionId = read(BHY_REG_REVISION_ID_ADDR, &data);
    --tries;
    ...
    }
    ...
    }

    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