Sending float ROCK SOLID over Bluetooth

michinyon:
(...)
Your sending piece of code also looks strange. You don't seeming to be "printing" the value of the variable you supposedly got from the sensor.

You are absolutly right, what I posted up to now was imo the only important part for the transfer.
My real sketch is a lot larger than this. But I was afraid that no one would even bother looking at it...

If you guys want, I can post both sketches completely.... But be aware and please don't run away :sweat_smile:

PaulS:
None of this is true. When the argument is a float, you can supply a second argument defining how many characters after the decimal point.

forum.arduino.cc/index.php/topic,42733.0.html
See Yot's (Global Moderator) comment. He says that we can't transfer more than 2 digits (after the comma) over serial

You could use println() instead of print(), to automatically append a carriage return and line feed - they are good end of packet markers.

Thats a great idea! So I could send with println instead of print.
But how do I even receive the carriage return?! will it be a ascii-character like the others?!

You could use dtostrf() to convert the float to a string, and then send the string, formatted however you like.

Yes, I read about that (and about itoa, atoi, atof....), but dtostrf() needs parameters like the length of the char-array/String...but how do I get the length of a float...! That was the reason why I searched for another solution

You could use more than one call to Serial.print() to send a start of packet marker, to send the float, and then to send an end of packet marker.

Thought about that too, but I would need to implement 3 times the while (mySerial.available() >0) (see my YUN-sketch), then each time read the received data and then each time check wether its the "start", the float or the "end" (or non) ... That must be a lot more unreliable than what I already got ...and take longer. So I forgot about that idea

There are many ways to skin this cat.
I hope to find at least one! :slight_smile: