Easiest way to send a float data from Raspberry Pi to Arduino (UART)?

So recently I find the need to send float number to Arduino, from a Python script, using serial communication.
Right now the way I'm using is just basically decomposed the number into 2 bytes (for numbers bigger than 255) and also another byte that indicates the sign of that number (positive or negative number).

But as time goes by, I find that this method is not very readable. It's a big project and I want it to be more maintainable for future developers.

So now I'm looking into what other ways I can do this. For example in Python, if I want to receive 2.55, I can just write:

b = ser.readline()
b = b.decode("utf-8")

And from the Arduino:

a = 2.55;
Serial.println(a);

Any ideas?

What's wrong with the code you just suggested?

Also, please confirm which direction the data is being sent. Initially, you said "send float number to Arduino, from a Python script" but then later in the post, you seem to be saying the data is going in the opposite direction, from the Arduino to the Python script...

Have a look at this Python - Arduino demo
and at Serial Input Basics which is more recent.

It makes debugging much easier if you send data as human readable text and I would only use binary data if I really need the extra performance.

If you need to send binary data the Python struct.pack() function is useful.

...R

PaulRB:
What's wrong with the code you just suggested?

Also, please confirm which direction the data is being sent. Initially, you said "send float number to Arduino, from a Python script" but then later in the post, you seem to be saying the data is going in the opposite direction, from the Arduino to the Python script...

It supposed to communicate both ways. The way I wrote (Pi to Arduino) it's good enough for me but I'm not sure how to do the same with the other way around.

vitsensei:
It supposed to communicate both ways. The way I wrote (Pi to Arduino) it's good enough for me but I'm not sure how to do the same with the other way around.

Ok. It would have been good to have understood that from the first post.

What kind of Arduino are you using? The basic 8-bit models have limited ram and program memory, so the functions to translate between float and string have been reduced to the minimum. The more modern 32-bit Arduino often have a wider choice, making things more user-friendly.

Have a look at Serial.parseFloat()