Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BHI160b basic.ino compilation error

    BHI160b basic.ino compilation error

    ryantheeng
    Member

    Trying to run the basic.ino example for the bhi160b sensor. The only thing changed is the fw file and the int pin. I was unable to compile the code with the following error: 

    BoschSensorHub-master\examples\basic\basic.ino: In function 'void setup()':
    basic:60:25: error: 'bhy1_fw' was not declared in this scope
    bhi160.loadFirmware(bhy1_fw);
    ^
    exit status 1
    'bhy1_fw' was not declared in this scope

    Thank you in advance.

    PS: Below is the example code.

    #include <Wire.h>
    
    #include "bhy.h"
    #include "bosch_pcb_7183_di03_bmi160-7183_di03-2-1-11824.h"
    
    #define BHY_INT_PIN 23
    #define PWR 19 //GPIO pin 19
    #define LED 18
    
    BHYSensor bhi160;
    
    volatile bool intrToggled = false;
    
    bool checkSensorStatus(void);
    
    void bhyInterruptHandler(void)
    {
        intrToggled = true;
    }
    void waitForBhyInterrupt(void)
    {
        while (!intrToggled)
            ;
        intrToggled = false;
    }
    
    //global variables
    byte addr;
    
    void setup()
    {
        pinMode(PWR,OUTPUT); //set pwr to imu
        digitalWrite(PWR,HIGH); //set to high  
        pinMode(LED,OUTPUT); //display LED
        digitalWrite(LED,HIGH); //set to high  
        
        delay(2000);
        
        Serial.begin(115200);
        Wire.begin();
    
        addr = finderskeepers();
    
        if (Serial)
        {
            Serial.println("Serial working");
        }
    
        attachInterrupt(BHY_INT_PIN, bhyInterruptHandler, RISING);
    
        bhi160.begin(BHY_I2C_ADDR2);
    
        // 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 */
    
        /* Link callbacks and configure desired virtual sensors here */
    
        if (checkSensorStatus())
            Serial.println("All ok");
    }
    
    void loop()
    {
        if (intrToggled)
        {
            intrToggled = false;
            bhi160.run();
            checkSensorStatus();
        }
    }
    
    /*print errors for debugging*/
    void errorhandler(String statement) {
      Serial.print("[ERROR]\t"+statement);
      return;
    }
    /*find a slave device*/
    byte finderskeepers() {
      byte error, address;
      Serial.print("I2C Scan\n");
      for (address = 1; address < 127; address++) {
        
        delay(500);//delay
        Serial.print("Checking ");
        Serial.println(address);
        Serial.print("\r");
        
        Wire.beginTransmission(address);
        error = Wire.endTransmission();
        if (error == 0) {
          Serial.print("I2C @ address 0x\n");
          Serial.println(address,HEX);
          return address;
        }
        else if (error == 4) {
          Serial.print("[ERROR]\tUknown Error @ address 0x\n");
          Serial.println(address,HEX);
        }
      }
      errorhandler("No Connections Found\n");
      return 0;
    }
    
    bool checkSensorStatus(void)
    {
        if (bhi160.status == BHY_OK)
            return true;
    
        if (bhi160.status < BHY_OK) /* All error codes are negative */
        {
            Serial.println("Error code: (" + String(bhi160.status) + "). " + bhi160.getErrorString(bhi160.status));
    
            return false; /* Something has gone wrong */
        }
        else /* All warning codes are positive */
        {
            Serial.println("Warning code: (" + String(bhi160.status) + ").");
    
            return true;
        }
    
        return true;
    }

     

    7 REPLIES 7

    BSTRobin
    Community Moderator
    Community Moderator

    Hello ryantheeng,

    As you changed "bhy1_fw", you should include correct header file to your source code, like "#include "bosch_pcb_7183_di03_bmi160-7183_di03-2-1-11824.h"".

    Hi Robin,

    thank you for your prompt reply. The code is now compiling, however, I am getting the following error code:

     

    Error code: (-91). Product ID Mismatch

     

     Seems to be failing at checkSensorStatus. I'm using the library from https://github.com/BoschSensortec/BoschSensorHub and a bhi160b.

    Any help is appreciated, thanks.

    BSTRobin
    Community Moderator
    Community Moderator

    Hello ryantheeng,

    Can you successfully compile the reference code without modification? If yes, you could try to modify it step by step.

    Hi Robin,

    I believe I might not have been super clear about my issue. I have assembled a custom PCB with a BHI160b and ESP32 and am now trying to get it to read data. I have working I2C code, and am now attempting to load the proper firmware.

    I am using un-altered source code found here: https://github.com/BoschSensortec/BoschSensorHub/tree/master/examples/basic 

    and standalone firmware file found here: https://www.bosch-sensortec.com/products/smart-sensors/bhi160-firmware/

    Code compiles and uploads to ESP32 but I receive Error code (-91) Product ID mismatch. I was just wondering what may be causing this issue.

    Thank you,

    Ryan

    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