Showing results for 
Search instead for 
Did you mean: 

Arduino send xbee packet of double to Labview

Go to solution

I'm a newbie and use a union code to send a double number to labview using arduino uno .
this code
union {
   double f;
   byte b[4];
} stuff;

stuff.f = number to send;

payload[1] = stuff.b[0];
payload[2] = stuff.b[1];
payload[3] = stuff.b[2];
payload[4] = stuff.b[3];

and in my Labview vi i receive:

sending number        payload 1   payload 2   payload 3    payload 4
0                                     0               0                  0                   0
1                                     0               0                128                 63
2                                     0               0                   0                 64
3                                     0               0                   64               64
4                                     0               0                  128              64
3,14159                        208             15                 73                64

how can I get the double in my vi??? I've tried join numbers ..and didn't work....


0 Kudos
Message 1 of 4
Accepted by JÞB

Well, there are some things very wrong here.  What does a "dbl" mean to you?  To LabVIEW, this is a Double-Precision Float, which is a 64-bit, 8-byte representation of a number in floating-point format.  To represent it, you would need to send 8 bytes.


There is also the LabVIEW "sgl", a Single-Precision 32-bit, 4-byte floating-point representation.  If your Arduino number really occupies 4 bytes, it is what LabVIEW would call a "sgl".  I don't know what the Arduino code you quote means, but "double f" seems to be a 4-byte float.


Next, byte order.  There is something call "endian", referring to "big-endian" and "little-endian", which says "Which end in a multi-byte number representation is stored first, in the lowest byte address".  LabVIEW stores Big-Endian, that is, the single-precision number 3.0 results in a 4-byte array 64, 64, 0, 0.


Note that your example code gives what appear to be that "double[3]" is 0, 0, 64, 64.  So if you attempt to take these four bytes into an array in the order 0, 0, 64, 64 (the value at index 0 is 0, at index 3 is 64), you'd need to reverse the array before trying to convert it to a Sgl.  [It doesn't have enough bytes to be a Dbl].


So here is some code (with part blacked out for you to fill in yourself -- the answers are all in this post).

Byte Conversion.png

The first shows a Sgl, 3.14159, run through a TypeCast into an Array of Bytes (the thing going into the TypeCast is ... an Array of U8, or Byte).  The output is brought to an Array of Bytes indicators (which you can see is an Array of U8), then another TypeCast (the 0 is of type Sgl), and the Sgl Result that come back (guess what -- it is 3.14159).  The second line is the array you suggested for 3.14159.  When I run this code, I get (in the variable "Pi?") 3.14159.  What's hidden in the Black Box?


Bob Schor

0 Kudos
Message 2 of 4

Thank you Bob


a nice bunch of infotmation for a newbie like me.

I'll try your concepts.

I'll let you know if the sgl works ( i believe this is the main problem..i was using I32 to convert it...and reverse order...)


thanks again..and happy new year


0 Kudos
Message 3 of 4

... and a happy new year to you, too.


Bob Schor

Message 4 of 4