Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMI160: Convert raw data from the into meaningful data.

    BMI160: Convert raw data from the into meaningful data.

    SpaceToon
    Member

    Hi everybody,

    I have a BMI160 sensor, which is connected to my Adafruit Feather M0 Bluefruit LE  development board to measure the acceleration and orientation. I have found a code online for the development board (through Arduino IDE) and I uploaded the code to my board. I successfully receive sensordata via Bluetooth Low Energy at my computer, however these data are not meaningful. My question is how do I "convert" these raw data into meaningful data (i.e. in m/s² and °/s) ? 

    //output 
    //No matter how I move the sensor, the first zeros remain
    0000002452552255248620
    0000002522552015248620
    000000702245239620
    0000002539770124620
    0000002438555667500
    00000022842354974400
    0000002152422464345380
    000000212026218620

     

    Here is a part of the code for the development board:

    void loop(void) {
      
      byte data[12]; 
    
      if(millis()-lastUpdate >=1000)
      {
      lastUpdate = millis();
      
      for (int i = 0; i < 12; i++)
      {
        // Read 12 bytes of data
        // xGyr lsb, xGyr msb, yGyr lsb, yGyr msb, zGyr lsb, zGyr msb
        // xAccl lsb, xAccl msb, yAccl lsb, yAccl msb, zAccl lsb, zAccl msb
       data[i]=readBMI(12+i);
        ble.print(data[i]); //send value to bluefruit uart
        Serial.print(data[i], HEX);
        Serial.print(" ");
        Serial.print(i);
        Serial.print(" ");
        if(i==11){
          ble.print(byte(0x00));
          }
      }
    
      ble.println();  //print newline so app knows to plot the values
    
      Serial.println();
      }
    }
    
    
    //-----------------------------------------------------------
    
    
    byte readBMI(int reg)
    {
        byte data = 0x00;
        // Start I2C Transmission
        Wire.beginTransmission(AddrBMI160);
        // Select data register
        Wire.write(reg);
        // Stop I2C Transmission
        Wire.endTransmission();
    
        // Request 1 byte of data
        Wire.requestFrom(AddrBMI160, 1);
    
        // Read 12 bytes of data
        // xGyr lsb, xGyr msb, yGyr lsb, yGyr msb, zGyr lsb, zGyr msb
        // xAccl lsb, xAccl msb, yAccl lsb, yAccl msb, zAccl lsb, zAccl msb
        if (Wire.available() == 1)
        {
          data = Wire.read();
        }
      return data;
      
    }

     

     

    1 REPLY 1

    Nikosant03
    Long-established Member
    Hi,
    First of all I am not an expert but I have some personal experience with BMX160 which combines both the BMI160 and BMM150.
    BMI160 returns LSBs and looking the datasheet e.g for 2g range we have 16384LSB/g (see pg8). So the first thing you have to consider is the range you have set for both sensor.

    What can I see from you code is that you read 12bytes of data. That makes sense since BMI160 integrates a 16bit digital triaxial accel and gyro (see pg2).

    What you have to do is
    1. Parsing the data. At the moment the readings you receive are the data of accel and gyro for x,y,z axis all in one raw 🙂

    2. Depending on the range you have set the accel and gyro just make the convertion from LSB to g or mg for accel and deg per second for gyro following the datasheet.

    Keep in mind that data parsing and units convertion should be perfomed into the central's side (computer)and not to peripheral (Adafruit feather) since is more efficient in terms of energy for BLE applications.

    Hope this helps
    Nick
    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