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.