View Full Version : PS4 UDP to Arduino - bytes and Ints working, Floats NOT... Please help..

24-02-2016, 16:37
Hi Guys..

I'm really hoping you can help me with this, because it was all going well, but this has had me stumped for days...

I'm successfully reading the UDP from a PS4, via an ESP8266 Wifi module. Its reading a few bit's n bytes from the game/race/car states and deciding what and when to send data, serially to another , more pokey, Teensy3.1 (Arduino turbo-clone).

I'm just moving a specific byte from the UDP, to a specific byte in my serial byte array, and sending (Serial.write).... NO processing, or re-ordering of the original data 'bytes'...

I'm getting the correct packets, and sizes, etc on the Teensy..

byte fields are copied like for like - byte -> byte..
Ints are byte2 + byte1, using word() conversion..

These work fine, and i've successfully read RPM, pulled bits from CarFlags, etc, but i'm having issues with the floats..

So, eg, one of my 'Dash' packets consists of byte and int data, some floats, then more bytes and ints..

I'm getting valid data for all these fields, before AND AFTER the float fields..

I've tried the following -

float = byte0, byte1, byte2, byte3.

float = byte3, byte2, byte1, byte0.

float = byte1, byte0, byte3, byte2.

float = byte3, byte2, byte1, byte0.

THEN - reversed the bits in each byte ( 00010011 = 11001000) - BigEndian/LittleEndian..?????

and tried it all again...

Lots of rubbish looking results..

If you display the byte and int data as a Binary, it's easy to figure out whats what, but the float bytes appear to be random..??

I've been posting my code in this post ( which may be useful )

Maybe I missed something while pulling my hair out...

Chrisie.. xx

24-02-2016, 17:48
Ok, got it.. I hope..

Bitshifting the float in, was giving a different result to a Union..

I've re-tried the Union method, and low and behold, I've got inc/dec values for Speed...


union { // Converts 4bytes into Float
byte uBytes[4];
float uFloat;
} uData;

ubyte0 = inBuffer[11]
ubyte1 = inBuffer[12]
ubyte2 = inBuffer[13]
ubyte3 = inBuffer[14]

In that order..

uFloat = the Float you want..

More investigation has found 'Speed' is Metres/Second NOT KPH/MPH, so a quick multiplication ( x 2.236936) and i've got MPH to 3dp....

I need to check the other Float fields, but this is looking good...

Chrisie.. xx