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.
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.
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.
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]:
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 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.
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
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: