MLX90614 Sensor Displaying in Fahrenheit
No trouble communicating with the sensor and getting data in Kelvin and Celsius but I would like to display the temperature in Fahrenheit as well. I am close to the goal but there is something small I have overlooked and cannot put my finger on it. When I run the program I have modified I get a reading for Fahrenheit but it is not correct. Example: When celsius reads 20, fahrenheit reads 37.
What else do I need to modify?
Find file attached
Thanks!
What else do I need to modify?
Find file attached
Thanks!
Comments
Init:
LOW Reset
INPUT Reset
DEBUG CLS, ' setup report screen
"MLX90614 Infra Red Thermometer", CR,
"=============================", CR,CR,
"Kelvin......... ", CR,
"Celsius........ ", CR,
"Fahrenheit..... ", CR,
"PEC test....... ", CR
'
[ Program Code ]
getTemperature:
SEROUT Sensor,baud,[0,"!TEMR",xslave,$07]
SERIN Sensor,baud,1000,PECfail,[tempL,tempH,pec]
checkPEC:
z=0
y = xslave<<1+0
GOSUB calculateCRC
y = $07
GOSUB calculateCRC
y = xslave<<1+1
GOSUB calculateCRC
y = tempL
GOSUB calculateCRC
y = tempH
GOSUB calculateCRC
IF z<>pec THEN PECfail
GOTO convertTemperatures
calculateCRC:
w=z^y
READ w,z
RETURN
convertTemperatures:
Kelvin = (temperature/100)*2
KelvinDec = temperature*2
IF (temperature < 13650) THEN overWordsize
Celsius = (temperature/50)-273
CelsiusDec = (temperature//50*2)
Fahrenheit = ((((temperature/50)-273) * 18) + 32) / 10
FahrenheitDec = (((temperature//50*2) * 18) + 32) / 10
GOTO displayTemperatures
overWordsize:
Celsius = (273-(temperature/50) )
CelsiusDec = (temperature//50*2)
DEBUG CRSRXY, 23, 4,"-",DEC Celsius,".",DEC2 CelsiusDec, CLREOL
displayTemperatures:
DEBUG CRSRXY, 23, 3,DEC Kelvin,".",DEC1 KelvinDec,CLREOL
DEBUG CRSRXY, 23, 4,DEC Celsius,".",DEC2 CelsiusDec, CLREOL
DEBUG CRSRXY, 23, 5,DEC Fahrenheit,".",DEC3 FahrenheitDec, CLREOL
DEBUG CRSRXY, 23, 6,"Pass",CLREOL
PAUSE 1000
GOTO getTemperature
PECfail:
DEBUG CRSRXY, 23, 3,CLREOL,CR
DEBUG CRSRXY, 23, 4,CLREOL,CR
DEBUG CRSRXY, 23, 5, CLREOL,CR
DEBUG CRSRXY, 23, 6,"Fail",CLREOL,CR
PAUSE 500
GOTO getTemperature
I think the other formulas and debugs are a little off, too. For example, it appears that the raw temperature value is returned in units of 0.02 Kelvin. Here is how I would write the conversions and the debugs...
note that the REP operator is used to handle the negative sign if needed, depending on the sign bit, bit15 of the number.