Dear everyone,
I just started to work on Sense Rev2 with the official library.
I successfully change the sample rate by editing the 228 lines of the src/BMI270.cpp.
In the serial monitor, the sample rate is indeed close to 1600Hz.
However, I can't access data in real 1600Hz on my PC via Serial communication. The sample rate is only 180+Hz.
Based on my previous experience, my serial communication code is correct.
Can you point out what else I should do now?
Thanks for your help!
/*
Arduino BMI270 - Simple Accelerometer
This example reads the acceleration values from the BMI270
sensor and continuously prints them to the Serial Monitor
or Serial Plotter.
The circuit:
- Arduino Nano 33 BLE Sense Rev2
created 10 Jul 2019
by Riccardo Rizzo
This example code is in the public domain.
*/
#include "Arduino_BMI270_BMM150.h"
uint8_t sampleBuffer_8bit[192];
int sb_index = 0;
short x, y, z;
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("Started");
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println(" Hz");
}
void loop() {
if (IMU.accelerationAvailable()) {
IMU.readRawAcceleration(x, y, z);
// Serial.print(x);
// Serial.print('\t');
// Serial.print(y);
// Serial.print('\t');
// Serial.println(z);
sampleBuffer_8bit[sb_index] = (x & 0xFF);
sb_index ++;
sampleBuffer_8bit[sb_index] = (x >> 8) & 0xFF;
sb_index ++;
if (sb_index >= 192){
Serial.write(sampleBuffer_8bit, sb_index);
sb_index=0;
}
}
}
Edit:
I change to 200Hz config, the real sample rate is 190Hz, however, when I go to 400Hz, it is still 200Hz. Since the available() is achieved by interrupt, I am confused where is the bottleneck of it.