Receiving 24 characters using Bluetooth 4.0

Hi,
I have been trying to recieve a 24 characters long string from BluetoothLE 4.0 and arduino nano on the app screen. The string's format is as follows: 10.5;11.3;14.5;20.4;12.3. The app screen only shows first 20 characters. These are actually five pressure values printed on the arduino nano's serial monitor.
I know that I can't change the MTU of Bluetooth 4.0. I can only do it by sending the data in packets. Please guide me how to send and receive data in packets? Thanks a lot.
My app blocks, arduino code and reference images are attached.
Ahmed



3
blocks4


TestProject.ino (8.9 KB)
Testproject.aia (3.0 MB)

     while (1) {
        // While in this loop, keep Writing the pressure value in the app
   Serial.print("A:");
   Serial.println(SensorA(p1A,p2A,p3A,p4A,p5A,p6A,q1A,q2A),1);  // Write  pressureA value to app
  Serial.print("B:");
  Serial.println(SensorB(p1B,p2B,p3B,p4B,p5B,p6B,q1B,q2B),1);  // Write  pressureB value to app
  Serial.print("C:");
  Serial.println(SensorC(p1C,p2C,p3C,p4C,p5C,p6C,q1C,q2C,q3C),1);  // Write  pressureC value to app
  Serial.print("D:");
  Serial.println(SensorD(p1D,p2D,p3D,p4D,p5D,q1D,q2D),1);  // Write  pressureD value to app
  Serial.print("mean:");
  Serial.println(average(),1);
 
  delay(800);


Testproject (1).aia (3.0 MB)

Thanks a lot ABG! I have tried what you advised. Now, the arduino serial monitor and the app screen look as shown in the attached pictures.


What are the maximum pressure values?

The maximum pressure is in double digits somewhere around 15 kPa.

Maybe try something like this:

  Serial.print((String(SensorA(p1A,p2A,p3A,p4A,p5A,p6A,q1A,q2A),1)).toFloat()* 10);  // Write  pressureA value to app
  Serial.print("|");
  Serial.print((String(SensorB(p1B,p2B,p3B,p4B,p5B,p6B,q1B,q2B),1)).toFloat()* 10);  // Write  pressureB value to app
  Serial.print("|");
  Serial.print((String(SensorC(p1C,p2C,p3C,p4C,p5C,p6C,q1C,q2C,q3C),1)).toFloat()* 10);  // Write  pressureC value to app
  Serial.print("|");
  Serial.print((String(SensorD(p1D,p2D,p3D,p4D,p5D,q1D,q2D),1)).toFloat()* 10);  // Write  pressureD value to app
  Serial.print("|");
  Serial.println((String(average(),1)).toFloat()* 10);
  delay(800);

The @ABG approach should work too, you haven't shown us the updated aia project and updated arduino code so we can see what could have gone wrong.

1 Like

Thanks a lot Patryk_F. I have tried what you advised. It works, hurrah. I am also trying ABGs approach. This time I don't see any thing on the app screen. Please find attached files.
Testproject_230906.aia (3.0 MB)

TestProject_ABG.ino (8.9 KB)

Try modifying the code in Arduino:

  Serial.println("A:" + String(SensorA(p1A,p2A,p3A,p4A,p5A,p6A,q1A,q2A),1));  // Write  pressureA value to app
  Serial.println("B:" + String(SensorB(p1B,p2B,p3B,p4B,p5B,p6B,q1B,q2B),1));  // Write  pressureB value to app
  Serial.println("C:" + String(SensorC(p1C,p2C,p3C,p4C,p5C,p6C,q1C,q2C,q3C),1));  // Write  pressureC value to app
  Serial.println("D:" + String(SensorD(p1D,p2D,p3D,p4D,p5D,q1D,q2D),1));  // Write  pressureD value to app
  Serial.println("mean:" + String(average(),1));
1 Like

It still doesn't work. Anyhow, we have solution that works perfectly. Thanks a lot!

I have some doubts as to how print and println might work in BLE as opposed to plain old BlueTooth.

image

I wonder where and when null terminator bytes might be appearing in the AI2 input stream, and what the items in the stringsReceived value look like.

Here is a copy of your project, with logging to a List Picker's Elements list of every item received in a stringsReceived value.

Would you mind running this and showing us the log?

Testproject_230906 (1).aia (3.0 MB)


My hypothesis is that the A: and associated data are being separated out into separate list items.

Thank you ABG for your support.
I am using Adafruit Bluefruit LE (Adafruit Bluefruit LE UART Friend - Bluetooth Low Energy (BLE) : ID 2479 : $17.50 : Adafruit Industries, Unique & fun DIY electronics and kits). I have tried to run what you suggested. Please see the attached pictures. The log was very long and still growing. I have just attached 3 photos. I can send you more. BTW, is there a way to download the entire log?




Thank you, the screen shots of the log were very informative and surprising.

Notice how each time stamped entry in the log can contain anywhere from 0 to several readings (B:06) separated by line feeds.
The code I supplied wrongly assumed the line feeds would be filtered out and would contribute to breaking items in the stringValues list properly.
Instead, the line feeds were treated no differently than | or comma delimiters (ignored.)

Furthermore, I see item breaks in the middle of numbers and in the middle of readings.

From what I see, this requires a different approach to dealing with the input stream, introducing a global string variable fed at its end from incoming stringValues items by concatenation, and depleted in front by splitting at application delimiters (line feeds.)

Code to follow.

I think the line feed (empty line) is due to the delay or processing time in Arduino nano to start printing the sensor values on the serial monitor. I am also trying to somehow reduce this delay.

Here is a revised approach, using a global buffer, untested.
global reading
global stringValuesBuffer


Testproject_230908.aia (3.0 MB)

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