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,

    For your issue, firstly in order to confirm whether your chip matches the firmware, you need to read the 0x91 register value to confirm whether the chip is BI160 or BHI160B.
    If revision ID value is 0x01, chip is BHI160. And the firmware should be like this: Bosch_PCB_7183_di01_BMI160-7183_di01*.h
    If revision ID value is 0x03, chip is BHI160B. And the firmware should be like this: Bosch_PCB_7183_di03_BMI160-7183_di03*.h

    BHI160X revision_ID register.png

    Hi, I have the exact same issue. I tried with both firmwares and still it is not working. I just opened the repository, and flashed my arduino card. 

    Thanks for your time 

    Paul

    Hi polomontreal,

    Sensor part should match corresponding firmware, you could see previous comment.
    You could give more detailed information about not working.

    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