Unable to read sensor values on the app

Hi, I am trying to read two pressure sensor values using Arduino Nano 33 BLE. I can see the values on the serial monitor but not on the app. I am attaching the block, arduino code and the app. Please suggest ideas to fix this problem? Thanks.


mansday240313A_LED_BLE.ino (12.9 KB)
BLE33_Read_and_Write.aia (205.9 KB)

According to

and
image

your BLE extension is not up to date.

(I have not yet looked at your blocks.)

Looking at your blocks, I don't see any place you register for floats, which would obviate the need for a Clock Timer to request floats.

But I see a Clock Timer, which you never enable.


image

(Unable to upload image of all blocks. Did we finally fill up the board?)

1 Like

Thanks ABG! I just upgraded my BLE extension.

Hmm.... I will get back to the lab again tomorrow and test the same with the timer enabled. Thanks a lot!!

P.S. I don't know enough about the float data type in your sketch to weigh in on that shortFloat true/false choice.

There should be a block tool tip to tell you how short a short float is.
(I hope)

Another possiible solution is to convert float values to strings before sending'em to the app,
In the Arduino code you could use the
dtostrf (float_value, min_width, num_digits_after_decimal, where_to_store_string)
function.
In this way the app can receive text (which is simpler to handle). Just remember that the last sending from Arduino shall be done with a .println(); (i.e. closed with a linefeed), the terminator character in the BT receiver shall be 0x0A (ASCII linefeed) and the number of bytes shall be set -1 (minus one). Though it seems hard, don't be scared, in the FAQ section, under @ABG management you'll find clear explanations of all what I've just said above.

I checked the TimerEnabled setting with a TimerInterval of 2000 ms. The pressure values now appear on the app updating at every 2000 ms [Thanks to ABG]. In this iteration, the shortfloat setting was set to false. However, when I set the shortfload setting to true, some random values [-0.00067,160000], [495001856, 200000],.... were appearing.

But the problem now is that both values are of sensor A, but just for a fraction of a second, both values are of sensor B. I think I am unable to use the BLE FloatsReceived block correctly. Is there a way to distinguish between the float values of the two sensors? I am attaching my updated blocks.

I was also getting a Runtime Error "No connection with a BLE device" when I turned on the TimerEnabled setting. So I added a block [when BluetoothLE1.RssiChanged, set TimerEnabled to true] which solved the Runtime Error problem.

Thank you, Uskiara. I will also try this tactic. By enabling the clock timer, the float values are now visible on the app but the my blocks are not able to distinguish between float values of the two sensors. I think it will be easier to distinguish them if I convert them to string as you suggested.

Dear @Ahmed_Zaidi,
I've just had a quick look to your .ino.
If you convert the sensor values from float to string, you can put before the value a header like "A:" + valueA and "B:"+valueB. In this case it will be easy in your app to differentiate the two values. When the app receives a string it will search for a matching characters pair "A:" or "B:" an decide accordingly where (in which label) to display the value.

1 Like

The problem is in the floats received event block.

The event block is trying to tell you about the incoming float with those four local variables, but you ignore the one that tells you which stream of floats it came from.

Instead, you were using some out of sync global.

1 Like

Thank you ABG! I think I understood what you are suggesting and I am getting closer. I am attaching some pictures. The old .FloatsReceived block looked like this [old image attached]:

When I try to select from different options, I see this [Options image attached]:
Options

I do not see distinct floatValues of the two sensors. So I had to select the 'floatValues' which is what I think you are refering to 'out of sync global'. Is this true?

Thank you again,
Ahmed

Screenshot_20240314_074413_DuckDuckGo

If A = A always will be true... same for B = B...
try this

Taifun


Thank you Taifun! I just tried this [please check in the attached, whether I did what you suggested] but I see the characteristic UUID values in the sensor value.


If I use it like attached image, I still see sensor A values in both the labels updating at the clock's time interval. But just for a millisecond, I see sensor B values in both the labels.

Yes, this looks correct

Can you elaborate?
It might be a good idea to display all 3 local variables from the FloatsReceived event in labels to better understand what is going on

Taifun



Using this block, I am getting nothing in label A and B, but the new 3rd label [label 14] is showing correct pressure value.

To debug correctly, do not use if statements and use new labels to display all 3 values

My guess is, you additionally have a clock running, which overwrites SensorA.Text and SensorB.Text

Also you still did not understand, that comparing the same value results always in true...
A = A
characteristicUUID = characteristicUUID

Taifun

1 Like

Thanks a lot Taifun! I changed the blocks like this:


And on the app, I see this:

After 2 seconds, the value in the red block of sensor B changes to 0001 and the Sensor C value shows the value of second pressure sensor just for a fraction of a second. I think the problem is also in this block below:

In the Clock.Timer event you read A and then B
Which means in the FloatsReceived event you first get A and then B

Taifun

1 Like