Help using ArduinoBLE with Arduino Nano 33 BLE

Hello! I recently bought a couple of Nano BLE 33s and was hoping on using them to wirelessly track motion. I was using the ArduinoBLE library and trying to connect to them. No matter what device I use (Android, iPhone (does not even show up), Win10) the Arduino immediately disconnects. This is regardless if I use the default Bluetooth menu or a specialized BLE app like nRF Connect. nRF connect gives me a 133 GATT error. I have tried experimenting with my connection intervals with no luck. Does anyone have any ideas? I was hoping I would at least get the Nano to connect before I make software that reads the data…

Here is my code (For some reason the example Arduino BLE on GitHub has a while loop within the loop function and it does not sense disconnections)

#include <ArduinoBLE.h>
#include <Arduino_LSM9DS1.h>
/*
Battery Monitor
This example creates a BLE peripheral with the standard battery service and
level characteristic. The A0 pin is used to calculate the battery level.
The circuit:

  • Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
    Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.
    You can use a generic BLE central app, like LightBlue (iOS and Android) or
    nRF Connect (Android), to interact with the services and characteristics
    created in this sketch.
    This example code is in the public domain.
    */

// BLE inertia Service
BLEService inertiaService(“180F”);

// BLE Battery Level Characteristic
BLEFloatCharacteristic inertiaChar0(“2A19”, // standard 16-bit characteristic UUID
BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes
BLEFloatCharacteristic inertiaChar1(“2A20”, // standard 16-bit characteristic UUID
BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes
BLEFloatCharacteristic inertiaChar2(“2A21”, // standard 16-bit characteristic UUID
BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes
BLEFloatCharacteristic inertiaChar3(“2A22”, // standard 16-bit characteristic UUID
BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes
BLEFloatCharacteristic inertiaChar4(“2A23”, // standard 16-bit characteristic UUID
BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes
BLEFloatCharacteristic inertiaChar5(“2A24”, // standard 16-bit characteristic UUID
BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes

float x = 0;
float y = 0;
float z = 0;

float xacc = 0;
float yacc = 0;
float zacc = 0;

void setup() {
Serial.begin(9600); // initialize serial communication
while (!Serial);
// begin initialization

if (!BLE.begin()) {
Serial.println(“starting BLE failed!”);

while (1);
}
BLE.setConnectionInterval(0x0010, 0x0c80);
BLE.setConnectable(true);
String address = BLE.address();
Serial.print("Local address is: ");
Serial.println(address);
pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected

/* Set a local name for the BLE device
This name will appear in advertising packets
and can be used by remote devices to identify this BLE device
The name can be changed but maybe be truncated based on space left in advertisement packet
*/
BLE.setLocalName(“Drums”);
BLE.setAdvertisedService(inertiaService); // add the service UUID
inertiaService.addCharacteristic(inertiaChar0);
inertiaService.addCharacteristic(inertiaChar1);
inertiaService.addCharacteristic(inertiaChar2);
inertiaService.addCharacteristic(inertiaChar3);
inertiaService.addCharacteristic(inertiaChar4);
inertiaService.addCharacteristic(inertiaChar5);// add the battery level characteristic
BLE.addService(inertiaService); // Add the battery service
inertiaChar0.writeValue(x);
inertiaChar1.writeValue(y);
inertiaChar2.writeValue(z);
inertiaChar3.writeValue(xacc);
inertiaChar4.writeValue(yacc);
inertiaChar5.writeValue(zacc);// set initial value for this characteristic

/* Start advertising BLE. It will start continuously transmitting BLE
advertising packets and will be visible to remote BLE central devices
until it receives a new connection */

// start advertising
BLE.advertise();
Serial.println(“Bluetooth device active, waiting for connections…”);
}

void loop() {
// wait for a BLE central
BLEDevice central = BLE.central();
if(central)
{
Serial.print("Connected to central: ");
// print the central’s BT address:
Serial.println(central.address());
// turn on the LED to indicate the connection:
digitalWrite(LED_BUILTIN, HIGH);
while (central.connected()) {
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(xacc, yacc, zacc);

inertiaChar3.writeValue(xacc);
inertiaChar4.writeValue(yacc);
inertiaChar5.writeValue(zacc);
}

if (IMU.gyroscopeAvailable()) {
IMU.readGyroscope(x, y, z);

inertiaChar0.writeValue(x);
inertiaChar1.writeValue(y);
inertiaChar2.writeValue(z);

}
Serial.println(“connected!”);
}
digitalWrite(LED_BUILTIN, LOW);
Serial.print("Disconnected from central: ");
Serial.println(central.address());
}

}

I've deleted your other cross-post @cybertheory.

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Ok Sorry about that! Thank you!

You don't initialise the IMU Arduino - ArduinoLSM9DS1begin
that might be responsible.

Additionally, how far away is the arduino from the other device? I've noticed its really short ranged, its possible it disconnects due to range.

Extras:
Based on my experiences, your implementation won't actually transmit any meaningful data. Most of your messages will just get dropped and won't get received by the other end. For example, one of the 3 acceleration values for a frame might get dropped. Repeat this over a few seconds and you have useless data.

To guarantee each frame is complete, you need to fill an array and send the entire thing in one go. On top of that you might want to consider increasing the MTU and combining multiple frames together to reduce the impact of BT protocol overhead.

Additionally, the ArduinoBLE library has a limit on the number of packets you can send without getting a response from the other device. This will cause the entire application to hang for up to 15 seconds (not sure on the exact value, its somewhat random). I made a modification to the library on my machine to overcome this.

Last thing, the Arduino_LSM9DS1.h is lacking a lot of features, I'd recommend getting the sparkfun LSM9DS1 library as its much more complete. You can control the range of the sensors and sampling frequencies.