I'm trying to send data from an arduino via USB to a PC program which will read the data points.
The question I have is relating to how much precision I can get from sending a given number of bits from the UART port.
Since the data I'll be writing to the UART port will be variables of type double, and I send 2 bytes of data per data point to the PC's program, I wanna know how much precision I can achieve.
How are double and floating-point values represented in binary? I assume some bits of data will be used up to indicate the position of the decimal in the number, right? So how much precision for variable of type double can be achieved with 2 bytes of data sent?
thanks, /g/
>>55173226
>how are double and floating point values represented in binary
IEEE 754
this sounds like actual technology and not linux
>>>/anywhere but here/
Why do you have to use 16 bit floats? Anyhow if your data can be unsigned you could probably get 2x as much precision.
>>55173226
>sjwuino
>>>/reddit/
thanks, /g/
>>55173274
don't you mean signed?
sorry if it's a stupid question but doesn't unsigned require extra for representing it?
>>55173226
You cannot send a 'double' value in 2B, because a double is by definition 8B (64 bits). You can send a so-called half-precision floating point value (as opposed to double-precision) in 16b.
Floating point values are generally represented by a sign bit, a number of bits for the exponent and the rest (largest part) for the "fraction" or "mantissa", google it for a proper explanation on the format and the precision you can expect.
Just use 8bit blocks for sending data.
If you use PySerial, you can easily set it. The UART comms doesn't know anything about signed or unsigned or lengths, so when you receive the data from your microcontroller you have to keep polling the port, and interpreting it correctly when you have the next n amount of bits.