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