Bosch Sensortec Community

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

    BOSch BMI160 - Too many or too few measured values ​​are recorded

    BOSch BMI160 - Too many or too few measured values ​​are recorded

    Sixtien
    Occasional Visitor

    Hi,
    I use a Bosch BMI160 sensor to measure the three-axis acceleration and orientation. This sensor is connected to a developer board. I read a total of 12 registers and expect 12 values ​​each time (one LSB and MSB value per axis). The problem now is that in rare cases I have fewer or more values when I start the transmission, such as just now:

     

    //output:
    "178,62"
    "178,62 211,255,246,255,241,255,253"
    "178,62 211,255,246,255,241,255,253,1,94,7,200,62"

     


    I would now like to know whether it is perhaps due to my code. Above all, the last two output lines show that there is a space in the second value ("62 211"), but I don't insert a space in the code. How can that be? Here is a piece of my code (the rest is just setting up the sensor and dev-board):

     

    void initBMI160()
    {
    
      // Start I2C Transmission ACC to the BMI160 sensor
      Wire.beginTransmission(AddrBMI160);
      // Select data register
      Wire.write(0x00);
      // Stop I2C Transmission
      Wire.endTransmission();
      Serial.println(F("Send done"));
    
      // Request 1 byte of data
      Wire.requestFrom(AddrBMI160, 1);
    
      // Read 6 bytes of data
      // xAccl lsb, xAccl msb, yAccl lsb, yAccl msb, zAccl lsb, zAccl msb
      if (Wire.available() == 1)
      {
        byte data = Wire.read();
        Serial.println(F("data available"));
        Serial.println(data, HEX);
      }
      else {
        Serial.println(F("No data available"));
      }
    
      //PMU mode
      // Start I2C Transmission
      Wire.beginTransmission(AddrBMI160);
      // Set PMU for acc
      Wire.write(0x7E);
      // Set Acc to normal mode
      Wire.write(0x11);
      // Stop I2C Transmission
      Wire.endTransmission();
    
      //"You need to wait for at least 5ms and then you can write value of 0x15 to command register 0x7E to bring gyro to normal mode"
      delay(50);
    
      // Start I2C Transmission
      Wire.beginTransmission(AddrBMI160);
      // Set PMU for gyr
      Wire.write(0x7E);
      // Set Gyr to normal mode
      Wire.write(0x15);
      // Stop I2C Transmission
      Wire.endTransmission();
    
      //"You also need to wait at least 80ms for gyro to be stablized before you perform I2C read or write action"
      delay(200);
      
      //Range
      // Start I2C Transmission
      Wire.beginTransmission(AddrBMI160);
      // Set ACC_RANGE
      Wire.write(0x41);
      // Set Acc range to +-2g
      Wire.write(0x03);
      // Stop I2C Transmission
      Wire.endTransmission();
    
      // Start I2C Transmission
      Wire.beginTransmission(AddrBMI160);
      // Set Range for Gyr
      Wire.write(0x43);
      // Set Gyr Range to 250dps
      Wire.write(0x03);
      // Stop I2C Transmission
      Wire.endTransmission();
    
      //Read PMU
      // Start I2C Transmission
      Wire.beginTransmission(AddrBMI160);
      // PMU REG
      Wire.write(0x03);
      // Stop I2C Transmission
      Wire.endTransmission();
    
      // Request 1 byte of data
      Wire.requestFrom(AddrBMI160, 1);
    
      // Read PMU REG
      if (Wire.available() == 1)
      {
        byte data = Wire.read();
        Serial.println(F("PMU REG"));
        Serial.println(data, HEX);
      }
      else {
        Serial.println(F("No data available"));
      }
    
      //Read Range
      // Start I2C Transmission
      Wire.beginTransmission(AddrBMI160);
      // ACC_RANGE
      Wire.write(0x41);
      // Stop I2C Transmission
      Wire.endTransmission();
    
      // Request 1 byte of data
      Wire.requestFrom(AddrBMI160, 1);
    
      // Read PMU REG
      if (Wire.available() == 1)
      {
        byte data = Wire.read();
        Serial.println(F("ACC_RANGE REG"));
        Serial.println(data, HEX);
      }
      else {
        Serial.println(F("No data available"));
      }
    
      // Start I2C Transmission
      Wire.beginTransmission(AddrBMI160);
      // GYR_RANGE
      Wire.write(0x43);
      // Stop I2C Transmission
      Wire.endTransmission();
    
      // Request 1 byte of data
      Wire.requestFrom(AddrBMI160, 1);
    
      // Read PMU REG
      if (Wire.available() == 1)
      {
        byte data = Wire.read();
        Serial.println(F("GYR_RANGE REG"));
        Serial.println(data, HEX);
      }
      else {
        Serial.println(F("No data available"));
      }
      Serial.println(F("BMI160 init done"));
    }

     

     

     

    void loop() {
    
      Wire.beginTransmission(AddrBMI160);
      Wire.write(12);
      Wire.endTransmission(true);
      Wire.requestFrom(AddrBMI160, 12, true);
    
      for (int i = 0; i < 12; i++) {
    
        ble.print(Wire.read());
    
        // Separator for further processing
        if (i < 11) {
          ble.print(",");
        }
      }
    
      // A space so that the further program knows that the values ​​can be plotted
      ble.println();
      delay(1000);
    }

     


    So I always expect 12 values, that are seperated with a comma for the further processing of the data on my PC.

    2 REPLIES 2

    FAE_CA1
    Community Moderator
    Community Moderator

    Hi,

    Thanks for your inquiry.

    It is correct that you write value of 0x11 to register 0x7E to bring BMI160 accel to normal mode and then add 50ms delay. It is also correct that you write value of 0x15 to register 0x7E to bring BMI160 gyro to normal mode and then add 200ms delay. If you read PMU_status register 0x03 and can get back the value of 0x14, then it means that BMI160 both accel and gyro are in normal mode. It also means that your I2C single byte read and write are working properly.

    Now you should get 12 bytes data from register 0x0C to 0x17 for gyro data and accel data in your loop for I2C multi-byte burst reading. You can use Arduino serial monitor to check if you can always get 12 bytes data displayed there or not. If yes, then it means that your I2C burst read is working properly and your BLE link function "ble.print()" has some problem.

    Thanks.


    @FAE_CA1 wrote:

    Hi,

    Thanks for your inquiry.

    It is correct that you write value of 0x11 to register 0x7E to bring BMI160 accel to normal mode and then add 50ms delay. It is also correct that you write value of 0x15 to register 0x7E to bring BMI160 gyro to normal mode and then add 200ms delay.


     

    Hey, @FAE_CA1: Is there anywhere an official source, where I can find these information? I Did not find these information in the BMI160 datasheet, so how could a newbie know that he/she has to set these "setting"? Where is this written?

    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