problem Converting byte array to float value

I have exhausted my research and reading forums options so I am asking for a little help if possible, obviously by this post.

I am working on a project using a inovonics temperature sensor connected to a feather 32u4 proto via uart pins. I send a hex command to sensor from feather and read in response to a uint8_t array[8]. This array holds four bytes at indexes 3 - 7 that are the resistance value for the temperature sensor. I need to convert these byte values to a float so I can then convert to the actual temperature. The bytes should convert to a IEEE-754 float value as is common with this type of device.

Here is what byte array holds when I read in:

60 7 E 42 82 99 9A 6C of course this is HEX values not the bytes from Serial1.read()

The temperature is the 42 82 99 9A in my code I call the array incoming[8]

I know I should be getting roughly 65.30000305175781 but am currently getting values like 1115855232.00

here is the part of my code related to this:

  Serial1.flush();
   Serial1.write(outBytes, sizeof(outBytes));
   while (!Serial1.available() && jj == 4); // wait for serial
   for (int i = 0; i < 8; i++) {

     incoming[i] = Serial1.read();

   }

I have then tried to convert using bit shifting, union in several forms.

 temp = ((incoming[3]) << 24 |
          (incoming[4] << 16) |
          (incoming[5] << 8) |
          incoming[6]);

  inValue = (float)temp;  //inValue is a float = 0

also tried:

inValue = decodeIEEE754(&incoming[3]);

...other code...

///
/// Converts an IEEE 754 floating-point value into a decimal value.
/// Take the address of the first byte, and uses the next 3 bytes for a total of 4 bytes.
///
float decodeIEEE754(uint8_t *data)
{
  union Temp value;
  value.i = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + (data[3]);

  return ( value.f );
}

This last method is what I use for the same thing in another solution, but it won't work in feather for some reason. The temp sensors trasmit a timed response to a receiver and I have a raspbery pi with code that does a similar thing to send back to a website collector.

For this solution I have the requirement to display the temperature from the sensor. Hence the feather connected to the uart pins of the temp sensor.

Thanks for any help...

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Do not cross-post. Other thread removed.

Try the other byte order.

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
unsigned long x = 0x4282999A;
float y = *(float*)&x;
Serial.print (y, 4);  //prints 65.3000
}

void loop() {
  // put your main code here, to run repeatedly:

}

Based on your last snippet (use of element called 'i'), you seem to use integers instead of bytes in your union. But as you did not post complete code, it's difficult to say.

I also suspect that your first conversion snippet should use a cast (probably treat temp as a pointer to a long because you do 'integer' shifting; I've not played with that).

Using a union

byte data[] = {0x60, 0x07, 0x0E, 0x42, 0x82, 0x99, 0x9A, 0x6C};

union TEMP
{
  float f;
  byte b[4];
};

void setup()
{
  Serial.begin(9600);
  while (!Serial);

  TEMP temp;

  // copy the relevant data
  for (int cnt = 0; cnt < sizeof(TEMP); cnt++)
  {
    temp.b[cnt] = data[6 - cnt];
  }

  // print hex values of float
  for (int cnt = 0; cnt < sizeof(TEMP); cnt++)
  {
    Serial.println(temp.b[cnt], HEX);
  }
  // print float
  Serial.println(temp.f);

}

void loop()
{
}

Result: 65.30

Thank you very much. Reading in bytes in reverse order before union worked. Appreciate the help. David