Nano 33 BLE Sense disconnecting from Android App

Hi!

I have developed a wearable based on Arduino Nano 33 BLE Sense. The device collects data from built-in and external sensors and sends them over BLE to a custom Android App. I want the device to operate over night continuously as the data are related to sleep efficiency.

In brief, I write acceleration, gyroscope, light and noise data characteristics on every loop iteration. At first I used a delay of 1000 ms at the end of the loop (with the same behavior). Now this needs to be set at 100ms as in the loop I also sample data from a heart rate sensor, which didn't work with a delay of 1000ms (took some time to figure out).

I also write two characteristics (heart rate and skin temperature) using the micropocessor's timer interrupts at 1 and 5 minute intervals.

On the Android App I save the transmitted data every one second so the 100ms delay is useless in this case, but still have to respect it in order to sample correctly the heart rate.

The device is powered by a 3.7 V battery with a capacity of 200mAh.

The whole Arduino-Android system is working great. My problem is that during the night, the android app receives a notification that the arduino is disconnected from BLE. And this is happening on random(?) occasions. For example, in my first use over night the device was transmitting data successfully for about 2 hours. Next night it disconnected after only 10 minutes. What is even more strange, is that on every loop I check for the BLE central connection, and if connected I keep the built-in LED on high, else on low. However, when the device is disconnected, the LED is kept on high, meaning that the central is still connected.

I suspect it may be a problem of the Voltage level after some period passes. Maybe the BLE chip needs a certain Voltage level to operate? Even so, I read that the nrf52840 can operate from +5.5 down to +1.7v , which my battery can supply. So that shouldn't be a problem.

Overall, the device is "alive" for about a total of 6 hours.

Any ideas appreciated. Thank you in advance!

Ok I just run the device with power from laptop USB, not the battery and still got the same result. After 10-15 minutes the connection is broken, but the LED remains on high.

So the speculation of the Voltage level and BLE opeartion is rejected.

Maybe some problem with my Android code ?

BLE is radio, which is inherently unreliable.

Welcome to the forum.

Can you share your code?

Does your Android app try to restart the connection when it is lost?

As jremington states. Radios are inherently unreliable. This is especially true for BLE. It operates in the 2.4 GHz ISM band which is used by many players with a lot more power available. BLE tries to get around that by several tricks like channel hoping and placing the advertisement channels between WiFi channels. But BLE devices are designed to just use enough power to work under normal conditions. From time to time that is not enough and packets are lost. If you want continuous operations the central device will need to reconnect in these cases. I do not believe the OS will handle that and therefore your app will need to handle this.

Thank you both for your help and instructions.

Up until yesterday I didn't have a handle for the disconnection. First thing I tried is to connect with the device's GATT server setting the "autoConnect" argument to True, but didn't see any improvement with that. Next thing I tried, is to implement the reconnection manually. So, in case of a disconnect event, I start scanning again for the device and connect to it immediately when found. This seemed to work once but didn't manage to try it more than once yet. You can find the code of my main activity (app) and the ble controller here in case you can find any obvious mistakes.

What is the most interesting though, is what you mentioned about the 2.4GHz band. I made a trial away from my room, where I have a powerline WiFi extender, and I got a continuous communication for straight 30 minutes. Then I made a trial again in my room and the communication ended after 2 minutes. Finally, I unplugged my extender and started the wearable while I was sleeping. I got a nice 1,5 hours measurement with no connection loss until I woke up. So thank you very much for pointing this out!

I will try to make some more adjustments but this is a big improvement on its own!

Last night I wore the device again. Same setup, WiFi extender unplugged, the communication ended after 30 minutes. Strange. I can't understand what's going wrong.

I have followed your instructions and my Android code can successfully re-establish connection automatically if I close the device and open it again. The problem is that, during the night, when the disconnect event is received from Android, the Arduino central is still connected. So the reconnection is not done properly.

So I found where the problem was. I was using a library for NRF52 based-boards in order to create the 1 and 5 minute timer interrupts to post 2 of my characteristics over BLE.

Eventually, this was crashing Nano at some undefined (?) time. As it seems, the LED staying at high was not indicating a connected central but it was the last state of Nano before it became stalled. I checked this trying to open Serial Monitor while being at this state, and this also caused the Arduino desktop app to crash.

Finally, I implemented the interrupts programmatically and managed to have a continuous operation overnight.

Thank you for your support forum.

1 Like

Hello,

I’m a beginner to arduino. For a capstone project I will also be transmitting data from a wearable using the arduino to a custom made app from scratch. Any suggestions and resources on how to get started and establish the BLE connection?

Thanks!

Hi @nr3240 ,

For starters you should definitely study the operation concept of Bluetooth Low Energy in general. You can start from this Arduino resource regarding the BLE library:
https://www.arduino.cc/en/Reference/ArduinoBLE
Then, if you are working on an Android custom app, you should also refer to the official documentation https://developer.android.com/guide/topics/connectivity/bluetooth/ble-overview.
However, you will probably find that not so complete, and you will have to do some research on forums etc, depending on what you actually want to achieve. I also found this article helpful.
It will be a bit difficult if you have not done it again. I suggest that you set small milestones at first, and implement simple functionalities, not all at once (e.g. first scanning, second, connecting, third subscribing etc.). Last, the best advice I can give you, is that like @jremington suggested, BLE is actually a radio communication, so do not expect things to be executed sequentially or like a normal program would do! In many cases, you will have to wait enough for some events, or you will have to handle disconnection etc.

I hope you find my advice of value. Best of luck!

Thank you so much! Is appreciate your help and guidance. Thank you for the references and notes to keep in mind.

How can I implement the interrupts programmatically? :thinking:
I have a simple switch case with multiple analogWrites, which makes Sense, unresponsive.

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