# Re: A simple serial protocol library

Usefull, maybe you could add a small story / tutorial about it on the playground. I did not dive into the code but have the following question:

3) All numeric data are in hexadecimal and have a fixed length (2 characters for bytes, 4 for words)

How are floats handled? e.g. a temperature sensor returns 32.45 degrees ?

I remember the old SDK 85, i got my 8085 microcontroller course with this kit, what a piece of instrument… those were the days… and tkx´s for sharing your code and all the rest !

GMV

How are floats handled?

In fact, I never used a float in 30 years of embedded system programming,

Embedded 30 years ago is not to be compared to today’s, imho. I understand floats can be avoided, but I want to use them when they have semantics in the real physical world. Volts, Lux, Pressure or a distance or the angle of a servo, (running) averages, temperature % etc … So I just want to send them over some line.

I agree 100% that floats affect performance and precision, but that is to be decided on a project to project basis when using floats. imho code becomes easier to understand - debug & maintain - when using the real world model. Furthermore the range of floats - on an Arduino - is far greater than a long. (although it can’t be displayed properly at all times)

The only solution I can think of is to dissect a float to its sign, mantisse and exponent, these are all integer /long in the end. e.g. IEEE754 formatted

“Edsger Dijkstra once said, only use integers in your code as there are enough of them”

Think you should write an article on the playground with this material.

Rob

Hi, Haven't had time to try it out, but it sure looks useful. Thanks for your effort !

As for the float discussion…

1. All numeric data are in hexadecimal and have a fixed length (2 characters for bytes, 4 for words)

I see a way to send floats as-is.
If I recall correctly, floats are usually written using the binary 2’s compliment system. Which uses 32 bits for the float (do correct me if I’m wrong).
32bits… 4 bytes. You can send it as a word.
Admittedly, it wouldn’t adhere to the ‘printable’ ASCII only requirement… but if you’re screwing around with floats being sent in a compressed state, you don’t want to be decoding those messages yourself anyways, so it probably wouldn’t hurt the protocol one bit.