kakauet
September 24, 2024, 10:10am
1
Hello,
Does anyone know why my board doesn't initialize IMU service?
This is the code
Thanks!!
#include <ArduinoBLE.h>
#include <Arduino_BMI270_BMM150.h>
// Set the same service UUID as in the Peripheral Device
const char* deviceServiceUuid = "b83b6b32-0d38-45da-9a65-73eecc736b17";
const char* AccXCharUuid = "22128dec-f7bc-4c21-a329-c13449221777";
const char* AccYCharUuid = "677314b1-6d7d-4b38-8e37-0a3d24538c01";
const char* AccZCharUuid = "648ae827-f439-4038-a8ed-88e67b2cbb33";
const char* GyroXCharUuid = "07c120ff-3915-410b-9c45-c84533e674df";
const char* GyroYCharUuid = "17a45678-jj34-5678-1234-56789ab34ef5";
const char* GyroZCharUuid = "9f345678-dd34-5678-1234-56789a67def6";
float x,y,z,gx,gy,gz;
double accelX=0;
double accelY=1;
double accelZ=0;
double gyroX=0;
double gyroY=0;
double gyroZ=0;
BLEService IMUService(deviceServiceUuid);
BLEDoubleCharacteristic AccXChar(AccXCharUuid, BLERead | BLENotify);
BLEDoubleCharacteristic AccYChar(AccYCharUuid, BLERead | BLENotify);
BLEDoubleCharacteristic AccZChar(AccZCharUuid, BLERead | BLENotify);
BLEDoubleCharacteristic GyroXChar(GyroXCharUuid, BLERead | BLENotify);
BLEDoubleCharacteristic GyroYChar(GyroYCharUuid, BLERead | BLENotify);
BLEDoubleCharacteristic GyroZChar(GyroZCharUuid, BLERead | BLENotify);
void setup() {
Serial.begin(9600);
while (!Serial);
if (!BLE.begin()) {
Serial.println("Starting Bluetooth failed!");
while (1);
}
Serial.println("BLE inicializado!");
delay(500);
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
Serial.println("IMU inicializado!");
BLE.setLocalName("Nano 33 BLE");
BLE.setAdvertisedService(IMUService);
IMUService.addCharacteristic(AccXChar);
IMUService.addCharacteristic(AccYChar);
IMUService.addCharacteristic(AccZChar);
IMUService.addCharacteristic(GyroXChar);
IMUService.addCharacteristic(GyroYChar);
IMUService.addCharacteristic(GyroZChar);
BLE.addService(IMUService);
BLE.advertise();
Serial.println("IMU Peripheral (Sending Data)");
}
void loop() {
BLEDevice central = BLE.central();
if (central) {
if (central.connected()) {
Serial.println("Connected to central device");
Serial.print("Device MAC address: ");
Serial.println(central.address());
} else {
Serial.println("Disconnected from central device");
}
}
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(x, y, z);
accelX = x;
accelY = y;
accelZ = z;
Serial.print("x: ");
Serial.print(x);
Serial.print(", y: ");
Serial.print(y);
Serial.print(", z: ");
Serial.println(z);
}
if (IMU.gyroscopeAvailable()) {
IMU.readGyroscope(gx, gy, gz);
gyroX = gx;
gyroY = gy;
gyroZ = gz;
Serial.print("gx: ");
Serial.print(gx);
Serial.print(", gy: ");
Serial.print(gy);
Serial.print(", gz: ");
Serial.println(gz);
}
AccXChar.writeValue(accelX);
AccYChar.writeValue(accelY);
AccZChar.writeValue(accelZ);
GyroXChar.writeValue(gyroX);
GyroYChar.writeValue(gyroY);
GyroZChar.writeValue(gyroZ);
delay(50);
}
What exact model of Nano 33 BLE do you have? Is it a BLE Sense? Rev2?
Perhaps it is a board which uses a LSM9DS1.
#include <Arduino_LSM9DS1.h>
BLE,
BLE Rev. 2,
BLE Sense,
BLE Sense Rev. 2
Whichever - it's on the back of the unit (or the box in came in).
kakauet
September 24, 2024, 4:15pm
4
It's a Nano 33 BLE Rev2. I reinstalled libraries and the problem continues... I don't know what's wrong. I tried some examples from Arduino and no one worked, always the same error "IMU failed"... May be it's due to hardware, but I bought it new, and all the rest services work correctly...
Hmmm. . .
that is the correct library for the
BLE Rev2 (and Sense Rev2)
I've run this on a Sense_Rev2
(I struck out the BLE stuff - don't know if it makes a diff) --
#include "Arduino_BMI270_BMM150.h"
float x, y, z;
void setup()
{
Serial.begin(19200);
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()
{
IMU.readAcceleration(x, y, z);
Serial.print(x);
Serial.print('\t');
Serial.print(y);
Serial.print('\t');
Serial.println(z);
delay(500);
}
kakauet
September 24, 2024, 5:43pm
7
Thanks!!, I tried your code and didn't worked "Failed to initialize IMU!". Do you know if is there a tool or a code for testing the hardware?
So far as a sketch to validate operation - you have it.
Is the IC there, on the board, in place ?
PE - There may be a Boards Manager update needed?
(Arduino Mbed OS Nano Boards)
I have a Nano33 BLE with the LSM9DS1. The IMU is on the Wire1 bus, and I can find two addresses for it with this version of the i2c scanner program. Does it find any devices on the board you have?
#include <Wire.h>
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("Started");
Wire1.begin();
delay(1000);
Serial.println ();
Serial.println ("I2C Wire1 scanner. Scanning ...");
byte count = 0;
for (byte i = 1; i < 120; i++)
{
Wire1.beginTransmission (i);
if (Wire1.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1);
}
}
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
}
void loop() {}
kakauet
September 24, 2024, 8:15pm
11
This is the result of your code, just one device
I2C Wire1 scanner. Scanning ...
Found address: (0x68)
Done.
Found 1 device(s).
What does it mean?. Thanks!!
kakauet
September 24, 2024, 8:20pm
12
Thanks, I had read the text and didn't found any reason for the error... I don't know where I caould find more info....
Did you try to see if there is an Update in Boards Manager (Post No.8) ?
There should be two addresses.
Somewhere deep in the library source code you can find the exact addresses.
https://github.com/arduino-libraries/Arduino_BMI270_BMM150/tree/master
@kakauet
Just to let you know -
the sketch that I posted in No.6 ran fine with my BLE_Sense_Rev2
and it runs fine with my BLE_Rev2.
As I see it, the IMU IC on yours is likely bad.
kakauet
September 26, 2024, 9:41pm
17
Thanks for your help, finally, the nano board was damaged, I changed it and it works!!
system
Closed
March 25, 2025, 9:41pm
18
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.