1wire DS1822 temperature
Karl_T
Posts: 7
Hi,I'm trying to get a DS1822 1wire tmeperature sensor to work with my
BS2Px stamp. So far, without success. I've done a bunch of reading
just to get mostly confused at this point. I've got an example program
from page 175 of "Basic Stamp 2p Commands, features, and Projects"·
It runs but doesn't acutally read the temperature, always returning
24.45.
Page 12 of this document has the DS1822 1wire commands
http://datasheets.maxim-ic.com/en/ds/DS1822.pdf
It looks like the convert T <44h> doesn't work with parasite power
This command is used in the example program. Or there may be other issues.
Has anyone got a DS1822 temp senosr to work with a stamp?
Bonus question, I'll need more than one temp. sensor. This is more complex.
Anyone done that?
Karl
·EXAMPLE PROGRAM
' File...... ds1920.bsp
' Purpose... Measuring of Temperature with DS1920 iButton
' Author.... Claus Kuehnel
' Started... 2001-08-11
' Updated...
'
[noparse][[/noparse] Program Description ]
'
' This program demonstrates the periodic measuring of ambient
' temperature with DS1920 iButton and calculation of high-
' resolution temperature value in degree C.
'
[noparse][[/noparse] Revision Hisory ]
'
' 2001-08-11
'
[noparse][[/noparse] Directives ]
'
'{$STAMP BS2p} 'specifies a BS2p
'
[noparse][[/noparse] Constants ]
'
OWpin con 15 '1-wire device pin
LED con 12 'Pin for LED
OWFERst con %0001 'Front-End Reset
OWBERst con %0010 'Back-End reset
OWBitMode con %0100
SkipROM con $CC 'Skip ROM Command
ReadScratch con $BE 'Read Scratch Pad
ConverT con $44 'Convert Temperature
'
[noparse][[/noparse] Variables ]
'
temp var word 'Temperature Value
CRem var byte 'Counts remaining value
CPerC var byte 'Counts per degree C value
'
[noparse][[/noparse] Initialization ]
'
init:
pause 1000 'open debug window
low LED 'LED off
'
[noparse][[/noparse] Main Code ]
'
Start:
'Send Convert Temperature command
OWOUT OWpin, OWFERst, [noparse][[/noparse]SkipROM, ConverT]
high LED
debug cls
CheckForDone:
'Wait until conversion is done
pause 25
OWIN OWpin, OWBitMode, [noparse][[/noparse]Temp]
'debug bin temp 'uncomment to see conversion time
IF Temp = 0 THEN CheckForDone
'Send Read Scratch Pad command
OWOUT OWpin, OWFERst, [noparse][[/noparse]SkipROM, ReadScratch]
OWIN OWpin, OWBERst, [noparse][[/noparse]Temp.lowbyte,Temp.highbyte,CRem,CRem,CRem,CRem,CRem,CPerC]
debug cr,"Temperature count (0.5°C) is ", dec Temp
'Calculate temperature in degrees C
Temp = Temp>>1*100-25+((CPerC*100-(CRem*100))/CPerC)
debug cr, "Actual Temperature is ", DEC Temp/100, ".", DEC2 Temp-(Temp/100*100), "C", CR
low LED
pause 5000 'next measurement in 5 sec
goto Start
BS2Px stamp. So far, without success. I've done a bunch of reading
just to get mostly confused at this point. I've got an example program
from page 175 of "Basic Stamp 2p Commands, features, and Projects"·
It runs but doesn't acutally read the temperature, always returning
24.45.
Page 12 of this document has the DS1822 1wire commands
http://datasheets.maxim-ic.com/en/ds/DS1822.pdf
It looks like the convert T <44h> doesn't work with parasite power
This command is used in the example program. Or there may be other issues.
Has anyone got a DS1822 temp senosr to work with a stamp?
Bonus question, I'll need more than one temp. sensor. This is more complex.
Anyone done that?
Karl
·EXAMPLE PROGRAM
' File...... ds1920.bsp
' Purpose... Measuring of Temperature with DS1920 iButton
' Author.... Claus Kuehnel
' Started... 2001-08-11
' Updated...
'
[noparse][[/noparse] Program Description ]
'
' This program demonstrates the periodic measuring of ambient
' temperature with DS1920 iButton and calculation of high-
' resolution temperature value in degree C.
'
[noparse][[/noparse] Revision Hisory ]
'
' 2001-08-11
'
[noparse][[/noparse] Directives ]
'
'{$STAMP BS2p} 'specifies a BS2p
'
[noparse][[/noparse] Constants ]
'
OWpin con 15 '1-wire device pin
LED con 12 'Pin for LED
OWFERst con %0001 'Front-End Reset
OWBERst con %0010 'Back-End reset
OWBitMode con %0100
SkipROM con $CC 'Skip ROM Command
ReadScratch con $BE 'Read Scratch Pad
ConverT con $44 'Convert Temperature
'
[noparse][[/noparse] Variables ]
'
temp var word 'Temperature Value
CRem var byte 'Counts remaining value
CPerC var byte 'Counts per degree C value
'
[noparse][[/noparse] Initialization ]
'
init:
pause 1000 'open debug window
low LED 'LED off
'
[noparse][[/noparse] Main Code ]
'
Start:
'Send Convert Temperature command
OWOUT OWpin, OWFERst, [noparse][[/noparse]SkipROM, ConverT]
high LED
debug cls
CheckForDone:
'Wait until conversion is done
pause 25
OWIN OWpin, OWBitMode, [noparse][[/noparse]Temp]
'debug bin temp 'uncomment to see conversion time
IF Temp = 0 THEN CheckForDone
'Send Read Scratch Pad command
OWOUT OWpin, OWFERst, [noparse][[/noparse]SkipROM, ReadScratch]
OWIN OWpin, OWBERst, [noparse][[/noparse]Temp.lowbyte,Temp.highbyte,CRem,CRem,CRem,CRem,CRem,CPerC]
debug cr,"Temperature count (0.5°C) is ", dec Temp
'Calculate temperature in degrees C
Temp = Temp>>1*100-25+((CPerC*100-(CRem*100))/CPerC)
debug cr, "Actual Temperature is ", DEC Temp/100, ".", DEC2 Temp-(Temp/100*100), "C", CR
low LED
pause 5000 'next measurement in 5 sec
goto Start
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen