Hello Happy People! A little brainteaser for you. Parallax has made available a rather nifty IR temp sensor package with a coprocessor to manage the serial comms. Using their code, I have been able to get the sensor to work on a basic stamp 2, no problem. Difficulty is in getting it to work on the Atom 28. I seemed to have tried everything and I only ever seem to get zeroes. Since this is Kelvin, ie. Absolute Zero, this is unlikely!
I have checked all the obvious things like power and continuity and have tried a lot of variations on timings, pauses (Atom faster than Basic Stamp 2), baudrates, differerent baudmodes, external and internal pullups. Still no joy.
More info on parallax site; melexis datasheets and parallax app note. (can't upload a pdf to this forum). Be happy to email you everything I have. If so, email me at
rupert@ruperthart.com.
My head hurts from trying everything; am on version 102 of the code. Would be happy to provide a small reward for anybody who solves the problem. Will it be you?!?
Hope you can help.
Best regards,
Rupert
Below are 1. Basic Stamp 2 code and then 2. Basic Atom code.
1. Basic Stamp 2 Code (simplified from Parallax site; works fine using BS2):
' =========================================================================
'
' File....... MLX90614_Demo-Simple.BS2
' Purpose.... Demo Code for MLX90614 Infra Red Thermometer Module
' E-mail.....
support@parallax.com' Started....
' Updated.... 01 SEPT 2008
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
'
' This program demonstrates the MLX90614 Infra Red Themometer Module by
' reading the temperature, calculating C and K, and running a CRC check on
' the PEC value for data integrity.
'
' -----[ I/O Definitions ]-------------------------------------------------
Reset CON 1
Alarm CON 2
Sensor CON 3
' -----[ Constants ]-------------------------------------------------------
baud CON 84
xslave CON $5A 'slave address
' -----[ Variables ]-------------------------------------------------------
temperature VAR Word
tempL VAR temperature.LOWBYTE
tempH VAR temperature.HIGHBYTE
pec VAR Byte
Kelvin VAR Word
KelvinDec VAR Word
Celsius VAR Word
CelsiusDec VAR Word
w VAR Byte
x VAR Byte
y VAR Byte
z VAR Byte
' -----[ Initialization ]--------------------------------------------------
Init:
LOW Reset
INPUT Reset
DEBUG CLS, ' setup report screen
"MLX90614 Infra Red Thermometer", CR,
"=============================", CR,CR,
"Kelvin......... ", CR,
"Celsius........ ", 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*2) < 27315 THEN overWordsize
Celsius = (temperature/100*2)-273
CelsiusDec = (temperature*2)-27315
GOTO displayTemperatures
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
DEBUG CRSRXY, 23, 5,"Pass",CLREOL
PAUSE 1000
GOTO getTemperature
PECfail:
DEBUG CRSRXY, 23, 3,CLREOL,CR
DEBUG CRSRXY, 23, 4,CLREOL,CR
DEBUG CRSRXY, 23, 5,"Fail",CLREOL,CR
PAUSE 500
GOTO getTemperature
2. Basic Micro Code for Atom 28. Can't get it to work.
'Basic Micro Atom 28
' =========================================================================
' -----[ I/O Definitions ]-------------------------------------------------
Reset CON 1
Alr CON 2
Sensor CON 3
' -----[ 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,[0,"!TEMR",$5A,$07]
pause 50
again:
SERIN Sensor,neo2400,1000,PECfail,[tempL,tempH,pec]
pause 40
displayTemperature:
serout s_out,i9600,[DEC temperature, " , ", dec pec, 10,13]
goto again
return
pecfail:
serout s_out,i9600,["pecfail", 10,13]
return