Connection issues between Android (BLE) and Arduino

Hi everyone, I'm trying to write a very simple app to connect my Arduino Nano 33 IoT with my phone (P30 Pro) using the bluetooth.

I found a very nice guide in a [previous post] (First MIT App Inventor Project - Arduino BLE) explaning exactly what I want.

I'm trying to do a little different than this tutorial by using a List Picker to open a new list with all BT (nicer would be to open the app, click a research button and connect automatically with Arduino, without showing a list, but I would be happy if already this list here would work).

I've been able to populate the list with BT devices nearby, but when I try to connect with my Arduino: black screen and it freezes.

Here the screnshot of my app.

Also, I don't know when and I don't understand why, when I install the app I only see the first two elements in the screen.

I'm attaching the aia file in case someone would help me out.

Many thanks!
Breath_Rate_Monitor.aia (204.2 KB)

Setting the Selection in the list picker after picking event to an entire list makes no sense.

Remove that block.

Also, I notice that all your UUIDs are identical.
Where did you get them?

Show your .ino file.

1 Like

I did what you suggested but this is how appears the app.
Empty in the main screen (and I don't understand why because everything disappeared after a modification I did to the blocks but don't understand which one, instead of the one on the right) and in the device list.


For my .ino I followed the tutorial that was giving the same UUID to all the variables, including the service.
Script.ino.ino (7.5 KB)

Until I get to a PC, you could try connecting to the sketch using the Play store app nrfconnect and show us the output.

P.S. I followed your links back to what you say is a tutorial, and i don't see anything worth copying back there.

Because you set the height of Label2 to 100%, so it takes up the height of the entire screen, and everything else has been moved off screen...

I don't have much experience with BLE, but something is wrong. After starting the project, it grants all permissions. When I start scanning with the "StartScanning" block, the "Scanning" block still returns false, as if scanning was not started at all. I also tried asking for permissions for scanning and connection, but it didn't help. Android14

Ok, I had location turned off on my phone.
Now everything works.

1 Like

Your project searches for BLE devices, but you must have Location enabled on your phone.


Because you set the height of Label2 to 100%, so it takes up the height of the entire screen, and everything else has been moved off screen...

Ah... I thought it would take the 100% height of the horizontal alignment box.
Thanks!

About the BLE,
first question: why do I need the position on when I want to set a BT connection? Because now I can see the list of BT devices nearby, and after few attempts, also my Arduino and also many BT devices, incrementing in number, everytime that I close/open the window. I suppose this is not correct. Especially all the null -# MAC address. Is it possible to keep the list updating while being on the list screen?

With nRF Connect app I find my board correctly. I also can find it in the BT connection of my phone (in Settings -> BT)

When I connect to my device an error appears on the screen saying "Runtime Error. Invalid UUID: 0" but I checked in my .ino script (after changing with lowercase letters the UUID variables), I should have set everything

Thanks for your help!

Second question

Scanning searches for all found devices. The extension does not know what bt device you need. You can always filter the list of devices to display, for example, a device with a given mac number.

All your characteristicUuids are identical, and set to 0.0. I don't think this is correct.

1 Like

Yes I was trying to add a single button to connect directly with the specific MAC address but always gives me timeout even if the device is found correctly by android.

Cattura

While if I connect through the pickerlist, it connects but vices me Invalid UUID:
0

for the characteristics, I followed the tutorial where if I get correctly the logic, he set the initial value 0.0. I could try to generate/change the characteristicsUUIDs if you think this might be the problem

These blocks:

call this procedure:

In which you set uuid to 0. Uud apparently can't be 0.

The example you took this project from does something completely different:

ble_register_characteristic

app_inventor_GUUID

Additionally, each uuid in the example is different. In your project, they are all identical.

1 Like

Mmm I might got lost then. I corrected it with the actual UUIDs (each one different) and now I don't get the UUIDs error.
I still get the timeout error in connection tho

Probably yes. Double check your project with the sample project to make sure everything is identical.

I don't know anything about this error. Not enough information. What are you doing to trigger this error and show me a screenshot.

Just click on the device I want to connect from the pick list.
I changed the UUIDs for each characteristic.

Probably the device you want to connect to does not accept this connection. Check if you are connecting to the correct device. And check if the arduino code is correct regarding accepting the connection. What ble module are you using? Also your uuids in the blocks must match those in the arduino.

If nRF Connect is able to connect to Arduino board, I guess there are no problem in the BT connection itself between the board and the smartphone, but it is rather a problem in the configuration (either app or code).

I checked all the characteristics names and UUIDs, service names and it seams their ok. Each UUID has its own code (service + 6 outputs). I'm attaching the new .aia and .ino files in case you'r like to have a look for big mistakes.

I'm using BluetoothLE extension found here. This Arduino has a BLE 4.2 and WiFi connection. I could try with wifi but I didn't want to use this module to connect to a smartphone
BR_Detector2.ino.ino (7.4 KB)
Breath_Rate_Monitor.aia (204.5 KB)

I think that before selecting your device from the list, the scanning should be stopped:

blocks (31)

Make sure 100% that the device you are selecting is the device you want to connect to.

Then, for further debugging, try not registering the receivers:

Let me know if you still get the error after connecting.