Bluetooth data glitch, please help

Hello, I am working on a project in wich i am sending continuos data to the android app using Bluetooth.
I am using Arduino NANO and Bluetooth HC-05.
The problem that i have is that when data is flowing the information keeps jumping on the screen and is not sent corectly, by that i mean that the text and the numbers keep dissapearing
The phone should receive for Label 2 "Temperatura: ..." and a growing number
and for Label 5 "RPM : ..." and a growing number.
I have tried using a different bluetooth module but it did not change a thing.

Bluetooth (1).aia (14.2 KB)

image

Your BlueTooth text reception needs a message delimiter.

Here is the standard advice for that:

Please see the Delimiter article in FAQ

Be sure to use println() at the end of each message to send from the sending device, to signal end of message. Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
BlueToothClient1_Properties
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

To SendText try this Slider

Hello Sebastian,

In the App:

What is the time interval of Clock1? It should be:

  1. 20% shorter than the Arduino loop time interval;
  2. As long as is practical for the Project to work satisfactorily. Note that very fast value changes cannot be tolerated by the human eye, so there is no point in displaying them.

In the Sketch:

  1. Do not send anything other than values. Labels are completely unnecessary (they can simply be in the App) and can take your data beyond the 20 byte limit.

  2. Do not use delay(), it stops everything and can have an adverse effect on sensor readings. Instead, use elapsed time.

  3. The final print line should be empty (no space, nothing).

So your Serial comms should look like this:

unsigned long lgUpdateTime;

void setup()
{
               //setup here
               lgUpdateTime = millis();
}

void loop()
{
	           if(millis() - lgUpdateTime > 4000)      //Loop approx every 4 seconds
               {
                         lgUpdateTime = millis();


                         //Sensor data collect here

                         //To Android App via Bluetooth
                         bluetoothSerial.print(rxBuf[2], DEC);
                         bluetoothSerial.print("|");              //Value delimiter
                         bluetoothSerial.print(rxBuf[1], DEC);
                         bluetoothSerial.println();               //Last line tells App "End of Data" = Ascii LineFeed Char Number 10
               }
}