padelt/temper-python

Incorrect result when temperature drops below freezing

Closed this issue · 4 comments

I'm using a 0c45:7401 Microdia device. temper-poll 1.5.2 works great above freezing, but when the temperature drops below 32F/0C, it returns 498 as the Fahrenheit temperature and 254 as the Centigrade temperature. Am I missing something?

Alan

The problem is at line 308 in temper.py. The data[offset] and data[offset+1] values go with temperature (in Celcius) as
temp data[offset] data[offset+1]
0.2 0 64
0.1 0 32
0.0 0 0
-0.1 255 224
-0.2 255 192

Ie, when the temp drops below 0C, 256 needs to be subtracted from the temperature like

        celsius = data[offset] + data[offset+1] / 256.0
    if data[offset] > 127:
	celsius = celsius - 256
        celsius = celsius * self._scale + self._offset
smeek commented

I also ran into this and have an open pull request (#68) to fix it.

roques committed on Jan 8, 2016 a wrong change.
this is how it must be:
celsius=struct.unpack_from('>h',data,offset)[0]/256.0

This should be fixed in the new master revision. If the issue re-appears, please open the issue again.