Can’t get NANO BLE SENSE REV 2 IMU data

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);
  }
}

Not much to go on. Why is the serial monitor in upper case and your code in lower case re the X Y 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.

It always helps to do a 'Goto Definition'.

The ones in lower case are never reached because if (IMU.accelerationAvailable()) is never true.

if the if (IMU.accelerationAvailable()) was true, then x, y, and z would have been updated by
IMU.readAcceleration(x, y, z);

The code is not mine, as I mentioned, the code is what is offered as an example in the library.

Shouldn't that work?

I'm not sure what you mean with that comment.

&X, &Y, &Z will cause X, Y, Z to receive new values.

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.


This is what I see when I click Goto Definition

Look at x, y, z closely.

Perhaps I could explain the problem this way: The setup routine works just fine, and it prints the capital X, Y, Z as TEXT headers, not variables.

The loop is supposed to update the lower-case x, y, z VARIABLES when the data is ready and that is what is not working.

I know, I read the code and given the way you have coded it the pgm is working perfect. I told you how to fix it, just 1 char 3 times.

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)
;
}

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()) {
Serial.println("Arrived Here!");
IMU.readAcceleration(x, y, z);
Serial.print(x);
Serial.print('\t');
Serial.print(y);
Serial.print('\t');
Serial.println(z);
}
}

With a bit more testing, I removed the if statement and the x, y, z variables do get values, but they are fixed even when the device is moved around.

This narrows it down to the if statement being the problem. If anyone has a way to get this working, I would be appreciative.

Here is the modified loop:

void loop() {
  float x, y, z;

 // if (IMU.accelerationAvailable()) {
    Serial.println("Arrived Here!");
    IMU.readAcceleration(x, y, z);
    Serial.print(x);
    Serial.print('\t');
    Serial.print(y);
    Serial.print('\t');
    Serial.println(z);
 // }
 delay(1000);
}

and the result:
-1.00 -0.72 -3.00

Arrived Here!

-1.00 -0.72 -3.00

Arrived Here!

-1.00 -0.72 -3.00

Arrived Here!

-1.00 -0.72 -3.00

Arrived Here!

-1.00 -0.72 -3.00

Arrived Here!

-1.00 -0.72 -3.00

Arrived Here!

-1.00 -0.72 -3.00

Arrived Here!

-1.00 -0.72 -3.00

Arrived Here!

-1.00 -0.72 -3.00

Arrived Here!

-1.00 -0.72 -3.00

Arrived Here!

-1.00 -0.72 -3.00

Arrived Here!

-1.00 -0.72 -3.00

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.

Accelerometer sample rate = 0.39 Hz

You are correct sir. I pulled a nano BLE sense Rev 2 from another project, and it works fine.

Thank you!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.