MLX90614 Thermometer Program
Humanoido
Posts: 5,770
The MLX90614 demo (attached) is also found here at the Parallax product page:
www.parallax.com/Store/Sensors/TemperatureHumidity/tabid/174/CategoryID/49/List/0/Level/a/ProductID/520/Default.aspx?SortField=ProductName%2cProductName
You will see this section in the demo:
I want to display the left digit and then the right digit of the "decimal only."
But it seems the decimal portion does not act as a normal number.
For example, if the original number is 91.42, then
f2 is 42
f2a is 92
f2b is 2
(f2a should be 4)
I tried this but it is only working on the second decimal digit and not the first.
Unfortunately there are no comments in the author's demo program.
Any ideas how to make it work correctly?
Thanks sincerely.
humanoido
Post Edited (humanoido) : 4/8/2009 7:05:32 AM GMT
www.parallax.com/Store/Sensors/TemperatureHumidity/tabid/174/CategoryID/49/List/0/Level/a/ProductID/520/Default.aspx?SortField=ProductName%2cProductName
You will see this section in the demo:
overWordsize: Celsius = ((27315-(temperature*2))/100) CelsiusDec = (27315-(temperature*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
I want to display the left digit and then the right digit of the "decimal only."
But it seems the decimal portion does not act as a normal number.
For example, if the original number is 91.42, then
f2 is 42
f2a is 92
f2b is 2
(f2a should be 4)
I tried this but it is only working on the second decimal digit and not the first.
Unfortunately there are no comments in the author's demo program.
f2 = CelsiusDec DEBUG " f2 is ", DEC2 f2, CR f2a = f2/10 DEBUG " f2a is ",DEC f2a,CR f2b = f2//10 DEBUG " f2b is ",DEC f2b,CR
Any ideas how to make it work correctly?
Thanks sincerely.
humanoido
Post Edited (humanoido) : 4/8/2009 7:05:32 AM GMT
Comments
how to convert the number to the right of the decimal point into a whole number?
An example, convert 22.57 to 57.
It looks like you're working from the belief that CelsiusDec containes a floating point number like 91.42, when it actually contains, in your example, the number ~9142. The only reason that the debug statement displays .42 is that the decimal point is hard coded and the "Formatter" DEC2 is used to display the·last two·digits of the variable.
If you work through the code with a raw "temperature" value of say, 18,000, you'll see what's going on.
Relying on the formula: C = K -273.15
Celsius = (18000/100*2)-273·········or 87
CelsiusDec = (18000*2)-27315······ or 8685
The DEBUG line above would display 87.85
Since the thermometer is returning values in .02 degrees Kelvin, the programmer could just have easily·done the calculation as you tried to do:
Which would display 86.85
I'm not sure which approach would be more accurate without some testing.
Duffer
humanoido
If your code constantly produces a pec fail, it's likely
the EEPROM value is not properly initialized. Review the
storage parameters and you'll see what's happening.
You'll need to rewrite the code anyway. Once its
properly initialized, it works every time.
humanoido
I never got the MLX90614 to work. Can you maybe email me/post any simple code that works? I would be forever grateful. I have wasted over 40 hours to no avail whatsoever. Humanoido: you are the only one on the discussion forum who has made ths work at all. Can you help, please?
Rupert
The demo code works. Exactly what is it doing or not doing? Which stamp, stamp board, and which demo program are you running? Is your battery new? (first priority check with a meter and the battery under load) Did you initialize the EEPROM? What is your wiring? You should post the code, and a photo of your setup and show which wiring schematic you followed. My code is for the Penguin robot, has some additional changes and features, and is currently on hold until it appears in the Penguin Book. The main issue is all about initializing it, otherwise it gives the PEC fail. After figuring that out, the temperature sensor works excellent! There is another post that spells out how to do that, and gives snippets of code, found here in the Sensor Forum.
humanoido
Post Edited (humanoido) : 5/27/2009 1:25:03 PM GMT
humanoido
Post Edited (humanoido) : 6/1/2009 7:46:52 PM GMT
As commented elsewhere, to get the device to work using the Parallax programs as supplied, you MUST use the "write eeprom" program first if the "demo simple" program is to work. This is because the "demo simple" program reads address $35, which has to be set up using the "write EEPROM" program first.
I suggest Parallax put up a simpler program to make the sensor work out of the box: "demo SUPER-simple": The Melexis device actually defaults to $5A as the address (see Melexis data sheets). I suggest you skip the Parallax-supplied "write EEPROM" program which sets up $35 instead and·just use the "demo simple" program, but this time addressing $5A instead of $35. See Humanaido's comments about unnecessary overcomplication.
Best, Rupert
Rupert
PS: neo=non-inverted, even parity, open drain.
'Basic Micro Atom 28
' =========================================================================
'
[noparse][[/noparse] I/O Definitions ]
Reset······· CON···· 1
Alr········· CON···· 2
Sensor······ CON···· 3
'
[noparse][[/noparse] Variables ]
temperature· VAR··· Word
tempL······· VAR··· temperature.LOWBYTE
tempH······· VAR··· temperature.HIGHBYTE
pec········· VAR··· Byte
slave·· VAR Byte
Main:
·gosub Init
·gosub gettemperature
end
Init:
·LOW Reset
·pause 1000
·INPUT Reset
·pause 50
·return
getTemperature:
· SEROUT Sensor,neo2400,[noparse][[/noparse]0,"!TEMR",$5A,$07]
· pause 50
·
· again:
· ·SERIN Sensor,neo2400,1000,PECfail,[noparse][[/noparse]tempL,tempH,pec]
· ·pause 40
·
·displayTemperature:
··serout s_out,i9600,[noparse][[/noparse]DEC temperature, " , ", dec pec, 10,13]
·goto again
return
·
pecfail:
serout s_out,i9600,[noparse][[/noparse]"pecfail", 10,13]
return
I suggest you post your code and question in THEIR forum
and someone there will quickly provide the answer.
humanoido
greetz ting
Ting: instead of checking address 07 try 03. The Melexis datsheet states this is the sensor temperature. Haven't tried myself. Let us know if that works. Have you got the sensor to work with your processor?