Attached is the example acceleration code for the Arduino_BMI270_BMM150 rev 1.2.1 library.
It always stops with this output:
Started
Accelerometer sample rate = 0.39 Hz
Acceleration in G's
X Y Z
The same thing happens with the example gyro code.
Anyone know why this is happening?
/*
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"
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");
Serial.println();
Serial.println("Acceleration in G's");
Serial.println("X\tY\tZ");
}
void loop() {
float x, y, z;
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(x, y, z);
Serial.print(x);
Serial.print('\t');
Serial.print(y);
Serial.print('\t');
Serial.println(z);
}
}
You have no way to update the X, Y, Z variables. Ideally they should be on the left side and one at a time, but in this case &x, &y, &z might be all you have to work with.
Goto Definition is a feature of the IDE. You really should know how to use your tools. Here is a picture of me doing a right click on the readAcceleration member.
Are you suggesting this will fix it?
IMU.readAcceleration(&x, &y, &z);
I tried it and it doesn't compile.
C:\Users\Mike\Desktop\ble\ble.ino: In function 'void loop()':
C:\Users\Mike\Desktop\ble\ble.ino:41:36: error: no matching function for call to 'BoschSensorClass::readAcceleration(float*, float*, float*)'
IMU.readAcceleration(&x, &y, &z);
^
In file included from c:\Users\Mike\Documents\Arduino\libraries\Arduino_BMI270_BMM150\src/Arduino_BMI270_BMM150.h:23:0,
from C:\Users\Mike\Desktop\ble\ble.ino:17:
c:\Users\Mike\Documents\Arduino\libraries\Arduino_BMI270_BMM150\src/BoschSensorClass.h:59:17: note: candidate: virtual int BoschSensorClass::readAcceleration(float&, float&, float&)
virtual int readAcceleration(float& x, float& y, float& z); // Results are in G (earth gravity).
^~~~~~~~~~~~~~~~
c:\Users\Mike\Documents\Arduino\libraries\Arduino_BMI270_BMM150\src/BoschSensorClass.h:59:17: note: no known conversion for argument 1 from 'float*' to 'float&'
exit status 1
Compilation error: no matching function for call to 'BoschSensorClass::readAcceleration(float*, float*, float*)'
I added a serial print for debugging and "Arrived Here!" never makes it to the Serial monitor. This shows that the if statement, "if (IMU.accelerationAvailable())" is never true. Because of that, it is impossible to update the x, y, z variables.
#include "Arduino_BMI270_BMM150.h"
void setup() {
Serial.begin(115200);
while (!Serial)
;
Serial.println("Started");
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1)
;
}
If that code is an unmodified, standard example from a library that is advertised to support the Nano BLE Sense Rev 2, then it seems likely that the sensor is defective.
Send the Nano back to the seller for refund or replacement.
Note: you should check the accelerometer data sheet to determine whether this is a valid sample rate. I doubt it is.