readGyro taking too long with BMI270

I have an app that is supposed to take gyro readings 500 times / second, so 500Hz.

With the Rev1 board using the LSM9 sensor that worked fine, I just had to insert a delayMicroseconds between each read.

I tried the same approach with the Rev2 board but is not working well. After inserting some millis() calls, I discovered that each call to readGyro is now taking about 7mS to return !

I'm using the "official" Arduino_BMI270_BMM150 library and configuring the gyro like:
sens_cfg[1].type = BMI2_GYRO; sens_cfg[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE; sens_cfg[1].cfg.gyr.noise_perf = BMI2_GYR_RANGE_2000; sens_cfg[1].cfg.gyr.bwp = BMI2_GYR_OSR2_MODE; sens_cfg[1].cfg.gyr.odr = BMI2_GYR_ODR_1600HZ; sens_cfg[1].cfg.gyr.range = BMI2_GYR_RANGE_2000; sens_cfg[1].cfg.gyr.ois_range = BMI2_GYR_OIS_2000;

Any ideas ?

post the code using code tags so that it's readable.

(likely due to the poor library - some other users complain Sampling Rate Does Not Match Configured Value (800 Hz) · Issue #48 · arduino-libraries/Arduino_BMI270_BMM150 · GitHub)

Try the Sparkfun library and let us know how it goes. SF usually does a good job with device libraries.

That said, Bosch sensors are rather often not competitive with those of other manufacturers, for various reasons.

  sens_cfg[1].type = BMI2_GYRO;
  sens_cfg[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
  sens_cfg[1].cfg.gyr.noise_perf = BMI2_GYR_RANGE_2000;
  sens_cfg[1].cfg.gyr.bwp = BMI2_GYR_OSR2_MODE;
  sens_cfg[1].cfg.gyr.odr = BMI2_GYR_ODR_1600HZ;
  sens_cfg[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
  sens_cfg[1].cfg.gyr.ois_range = BMI2_GYR_OIS_2000;

I'll give Sparkfun a try.
I don't think the Bosch sensor is the issue. Looking at the specs it seems more capable than the LSM9. However, it also look a lot harder to master.

Why would you care, if you can't even get the most basic measurement at the expected rate? I suggest to re-evaluate your priorities.

I don't care but I'm forced to use the Bosch sensor as is the one present in the Rev2 board.
I was perfectly happy with the older one

Reading the GitHub "bugs" report, seems you won't get your 500Hz, at least not from the Arduino_BMI270_BMM150 library.

This "bug" report has the following fatal flaw, and prints sample data every pass:

void setup() {
  Serial.begin(9600);

Post your complete code, so we can see if you have made the same mistake.

Note: if Serial.print() runs at native USB speed on the Nano 33 BLE, the baud rate setting might be irrelevant. I don't have one to test.

I confirm that the value of the argument has no effect:

right it's "true" USB speed

I'm not relying on an output to Serial:

  for (int i = 0; i < size_sample; i++) {
    
    elapsed = millis();
    IMU.readGyro(xg, yg, zg);
    elapsed = millis() - elapsed;

    total_elapsed += elapsed;
    
    zabs = abs(zg);
    //delayMicroseconds(loopTimeAdj);
    speedPoints[i] = zabs;
    if (zabs < 10) return (9);            // if speed starts to go back to 0, exit with error
  }

  elapsed_avg = total_elapsed / size_sample;

Give the Sparkfun library a try.

I just tried one of the Sparkfun examples (see below), but it didn't work. It always reports that the BMI270 isn't found.
That's strange because I think on the Nano 33 BLE, the BMI is wired in the same way as in the Adafruit breakout boards (I2C with address 0x68).
What could be failing ?

#include <Wire.h>
#include "SparkFun_BMI270_Arduino_Library.h"

// Create a new sensor object
BMI270 imu;

// I2C address selection
uint8_t i2cAddress = BMI2_I2C_PRIM_ADDR; // 0x68
//uint8_t i2cAddress = BMI2_I2C_SEC_ADDR; // 0x69

void setup()
{
    // Start serial
    Serial.begin(115200);
    Serial.println("BMI270 Example 1 - Basic Readings I2C");

    // Initialize the I2C library
    Wire.begin();

    // Check if sensor is connected and initialize
    // Address is optional (defaults to 0x68)
    while(imu.beginI2C(i2cAddress) != BMI2_OK)
    {
        // Not connected, inform user
        Serial.println("Error: BMI270 not connected, check wiring and I2C address!");

        // Wait a bit to see if connection is established
        delay(1000);
    }

    Serial.println("BMI270 connected!");
}

void loop()
{
    // Get measurements from the sensor. This must be called before accessing
    // the sensor data, otherwise it will never update
    imu.getSensorData();

    // Print acceleration data
    Serial.print("Acceleration in g's");
    Serial.print("\t");
    Serial.print("X: ");
    Serial.print(imu.data.accelX, 3);
    Serial.print("\t");
    Serial.print("Y: ");
    Serial.print(imu.data.accelY, 3);
    Serial.print("\t");
    Serial.print("Z: ");
    Serial.print(imu.data.accelZ, 3);

    Serial.print("\t");

    // Print rotation data
    Serial.print("Rotation in deg/sec");
    Serial.print("\t");
    Serial.print("X: ");
    Serial.print(imu.data.gyroX, 3);
    Serial.print("\t");
    Serial.print("Y: ");
    Serial.print(imu.data.gyroY, 3);
    Serial.print("\t");
    Serial.print("Z: ");
    Serial.println(imu.data.gyroZ, 3);

    // Print 50x per second
    delay(20);
}

Check whether the Nano 33 BLE uses a different I2C bus, e.g. Wire1.

The first step with any new I2C device is to run the I2C address scanner program, to see what device addresses are detected.

Thanks for the tip.
The BMI is on wire1

The Adafruit lib is slightly better. 3ms vs 7ms for a sensor read.
Still too much.