Skip to main content
added 281 characters in body
Source Link

I'm guessing the line arrayOne=bluetoothSerial.read(); is converting the received value to a string (character array of ASCII charachters terminated with the '\0' character). Then, you copy that string to another string variable. If you want to split the string you should:

  • define a starting character > 0
  • and/or: define an ending character < the total string size.

See this link for more info.

You could try the following. I'm sure it's far from perfect but it might get you a bit further.

void setup()
{
    bluetoothSerial.begin(9600);
    Serial.begin(9600);
}

void loop()
{
    if (bluetoothSerial.available)
    {
        delay(100); // wait a little for the serial buffer to saturate. This value should be as short as possible

        // Save the buffer bytes as the float (Big Endian!)
        double received_float = (bluetoothSerial.read() << 24) | (bluetoothSerial.read() << 16) | (bluetoothSerial.read() << 8) | (bluetoothSerial.read());
        Serial.println(received_float);
    }
}

Some conciderations:

  • The nr of bytes a float occupies may differ on your phone and your Arduino. The example above uses a 32-bit float
  • If possible you'd want to start the transmission with a sequency of starting characters. That way, you can be sure to read the proper value.

I'm guessing the line arrayOne=bluetoothSerial.read(); is converting the received value to a string (character array of ASCII charachters terminated with the '\0' character). Then, you copy that string to another string variable. If you want to split the string you should:

  • define a starting character > 0
  • and/or: define an ending character < the total string size.

See this link for more info.

You could try the following. I'm sure it's far from perfect but it might get you a bit further.

void setup()
{
    bluetoothSerial.begin(9600);
    Serial.begin(9600);
}

void loop()
{
    if (bluetoothSerial.available)
    {
        delay(100); // wait a little for the serial buffer to saturate. This value should be as short as possible

        // Save the buffer bytes as the float (Big Endian!)
        double received_float = (bluetoothSerial.read() << 24) | (bluetoothSerial.read() << 16) | (bluetoothSerial.read() << 8) | (bluetoothSerial.read());
        Serial.println(received_float);
    }
}

I'm guessing the line arrayOne=bluetoothSerial.read(); is converting the received value to a string (character array of ASCII charachters terminated with the '\0' character). Then, you copy that string to another string variable. If you want to split the string you should:

  • define a starting character > 0
  • and/or: define an ending character < the total string size.

See this link for more info.

You could try the following. I'm sure it's far from perfect but it might get you a bit further.

void setup()
{
    bluetoothSerial.begin(9600);
    Serial.begin(9600);
}

void loop()
{
    if (bluetoothSerial.available)
    {
        delay(100); // wait a little for the serial buffer to saturate. This value should be as short as possible

        // Save the buffer bytes as the float (Big Endian!)
        double received_float = (bluetoothSerial.read() << 24) | (bluetoothSerial.read() << 16) | (bluetoothSerial.read() << 8) | (bluetoothSerial.read());
        Serial.println(received_float);
    }
}

Some conciderations:

  • The nr of bytes a float occupies may differ on your phone and your Arduino. The example above uses a 32-bit float
  • If possible you'd want to start the transmission with a sequency of starting characters. That way, you can be sure to read the proper value.
Source Link

I'm guessing the line arrayOne=bluetoothSerial.read(); is converting the received value to a string (character array of ASCII charachters terminated with the '\0' character). Then, you copy that string to another string variable. If you want to split the string you should:

  • define a starting character > 0
  • and/or: define an ending character < the total string size.

See this link for more info.

You could try the following. I'm sure it's far from perfect but it might get you a bit further.

void setup()
{
    bluetoothSerial.begin(9600);
    Serial.begin(9600);
}

void loop()
{
    if (bluetoothSerial.available)
    {
        delay(100); // wait a little for the serial buffer to saturate. This value should be as short as possible

        // Save the buffer bytes as the float (Big Endian!)
        double received_float = (bluetoothSerial.read() << 24) | (bluetoothSerial.read() << 16) | (bluetoothSerial.read() << 8) | (bluetoothSerial.read());
        Serial.println(received_float);
    }
}