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.