Android Bluetooth

Let’s say your Arduino has 4 sensors.
In the main loop of the arduino sketch, you will add a ‘!’ delimitor only at the first sensor data, because this is the main delimiter. On the subsequent ones you use the ‘#’ delimiter, like:

while (mySerial.available() <= 0) { 
    y_1 = int(data_sensor_1);
    mySerial.print(String(y_1) + '!');

    y_2 = int(data_sensor_2);
    mySerial.print(String(y_2) + '#');

    y_3 = int(data_sensor_3);
    mySerial.print(String(y_3) + '#');

    y_4 = int(data_sensor_4);
    mySerial.print(String(y_4) + '#' );
  }

In the processing sketch, in the plot() function, you will receive a string to be split only on the ‘#’ delimiter, because the main delimiter ‘!’ was already captured, spit and removed in the connect() function.
The channel data can now be split in the plot() function as follows.

void plot(String r_str) {
  if (r_str.length() < 7 || r_str == null) r_str =  "0#0#0#0";
  if (plotting) {
    y_values = split(r_str, "#");
    y_1 = int(y_values[0])
    y_2 = int(y_values[1])
    y_3 = int(y_values[2])
    y_4 = int(y_values[3])
  }
}

Please if you have further questions post them here, to not extend this topic too much.

1 Like