View Full Version : 1wire DS1822 temperature

01-22-2010, 12:03 AM
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

Page 12 of this document has the DS1822 1wire commands
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?


' File...... ds1920.bsp
' Purpose... Measuring of Temperature with DS1920 iButton
' Author.... Claus Kuehnel
' Started... 2001-08-11
' Updated...
' -----[ Program Description ]--------------------------------
' This program demonstrates the periodic measuring of ambient
' temperature with DS1920 iButton and calculation of high-
' resolution temperature value in degree C.
' -----[ Revision Hisory ]-----------------------------------
' 2001-08-11
' -----[ Directives ]-----------------------------------------
'{$STAMP BS2p} 'specifies a BS2p
' -----[ 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
' -----[ Variables ]------------------------------------------
temp var word 'Temperature Value
CRem var byte 'Counts remaining value
CPerC var byte 'Counts per degree C value
' -----[ Initialization ]-------------------------------------
pause 1000 'open debug window
low LED 'LED off
' -----[ Main Code ]------------------------------------------
'Send Convert Temperature command
OWOUT OWpin, OWFERst, [SkipROM, ConverT]
high LED
debug cls
'Wait until conversion is done
pause 25
OWIN OWpin, OWBitMode, [Temp]
'debug bin temp 'uncomment to see conversion time
IF Temp = 0 THEN CheckForDone
'Send Read Scratch Pad command
OWOUT OWpin, OWFERst, [SkipROM, ReadScratch]
OWIN OWpin, OWBERst, [Temp.lowbyte,Temp.highbyte,CRem,CRem,CRem,CRem,CRe m,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

01-22-2010, 11:56 AM
First off don't use parasitic power while you are testing it will only complicate things. Second your code is not for the chip you are using. Sit down with the data sheet and figure out what you need to send to the chip and what you get back. The OWIN and OWOUT commands are well documented and not too hard to use so start by just querying the chip for its address and make that part work.

- Stephen