DS18S20 Temp Display
SG09
Posts: 11
I am a complete beginner in both electronics and programming (please bear with me).· I am trying to log temperatures from several DS18S20s throughout a solar thermal heating system I am building.· To get my feet wet, I first went the route of building a simple serial COM port type device that I could just plug in to the back of a computer.·After I could not get it to work, I learned that the notebook I have does not put out enough voltage...· I then stumbled upon the Basic Stamp (BS2 Homework Board). What a great way to get started in this hobby!· I have had alot of fun assembling the simple circuits with my 12 year old son and we are learning a little more each time we sit down with it.· I also learned that you can't just plug in a sensor and go!
I then found Peter Anderson's parts kit (about $8) to enable the BS2 to talk with several DS18S20s (via a PIC 16F88) and have just finished it.· I took the example code from his site and ran it and it actually works, but it is not showing an accurate reading.· I have searched the archives but had no luck in figuring out what is wrong; it responds to changes in temperature, but it is way off.· My digital thermometer in my kitchen reads 23.3 C and the output from the BS2·is showing·2.87 ( I am assuming C).· If I put my finger on it, it will climb to around 3, or so.
Can anyone point me in the right direction?
Thanks!
Bill
I then found Peter Anderson's parts kit (about $8) to enable the BS2 to talk with several DS18S20s (via a PIC 16F88) and have just finished it.· I took the example code from his site and ran it and it actually works, but it is not showing an accurate reading.· I have searched the archives but had no luck in figuring out what is wrong; it responds to changes in temperature, but it is way off.· My digital thermometer in my kitchen reads 23.3 C and the output from the BS2·is showing·2.87 ( I am assuming C).· If I put my finger on it, it will climb to around 3, or so.
Can anyone point me in the right direction?
Thanks!
Bill
Comments
Be sure to distinguish the DS18S20 from the DS18B20. They have quite different scale factors.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Here is the code I am using.· I thought I was using DS18S20s, as that is what I ordered; what I received was a bag of (10) sensors marked "DS1820/DS18S20".· On the particular chip I am using it says "DS1820".
' {$STAMP BS2}
' {$PBASIC 2.5}
·················· BaudMode· CON· 84········· '9600 True
··· X VAR Word
··· Y VAR Word
··· SignBit VAR Byte
··· Whole VAR Byte
··· Fract VAR Byte
··· DIR7 = 0· ' serial input
··· DIR8 = 1· ' serial output
··· OUT8 = 0· ' be sure SerOut pin is stable at zero
··· PAUSE 1000
· DO
AGN:
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"P0", "W0cc", "S044"]· 'perform temp meas
·········································· ' note strong pullup
··· PAUSE 1100······· ' wait for conversion to complete
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"P0", "W0cc", "W0be"]·· ' send temperature data
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"R0"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [noparse][[/noparse]DEC X.LOWBYTE]
··· PAUSE 100
··· SEROUT 8, BaudMode, 10, [noparse][[/noparse]"R0"]·· ' fetch data
··· SERIN 7, Baudmode, 1500, TimeOut, [noparse][[/noparse]DEC X.HIGHBYTE]
··· PAUSE 100
··· ' now do the calculations
··· SignBit = X / 256 / 128
··· IF SignBit = 1 THEN ' its negative
······ X = X ^ $ffff + 1 ' take the two's comp
··· ENDIF
··· ' multiply by 6.25 - This is 100 * Tc
··· Y = X / 4·· ' 0.25
··· X = X * 6 + Y
··· Whole = X / 100
··· Fract = X // 100
··· IF SignBit = 1 THEN
······ DEBUG "-", DEC Whole, ".", DEC2 Fract, CR
··· ELSE
······ DEBUG DEC Whole, ".", DEC2 Fract, CR
··· ENDIF
··· PAUSE 3000 ' wait 3 secs
· LOOP
TimeOut:
··· DEBUG "Timeout Error", CR
··· GOTO AGN
·
' now do the calculations
DEBUG SDEC x,CR ' signed integer
That will show what is there before the calculation.
It looks to me that this is code for the DS18B20, which at 12 bit resolution is 0.0625 degree Celsius per bit. That is the multiply time 6.25 in the calculation. The DS1820 and DS18S20 have 9 bit resolution, 0.5 degree Celsius per bit. Here is a calculation done is a more streamlined way for resolution of 0.5 per bit:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Someday, I will figure out exactly how!!
Just two more quick things:
· -First, instead of just showing for example "23.5", it is showing "47" and then "23.5" on the line below with every output.
· -How do I change the display to Fahrenheit?
Many Thanks,
Bill
REP "-"\x.bit15 ' if x is negative, the sign bit (bit15 will be negative), and the REP modifier will display the - sign
DEC ABS x/10 ' displays all but the ones digit of the absolute value of x
"." ' decimal point
DEC1 ABS x ' displays the ones digit
To Fahrenheit...
degF = x + 178 * 9 / 5
DEBUG REP "-"\degF.bit15, DEC ABS degF/10, ".", DEC1 ABS degF
That formula will work down to -17.8 degrees Celsius (=zero degF). If you use the standard formula,
degF = x * 9/5 + 320 ' convert tenths Celsius to tenths Fahrenheit
that will work down to 0 degrees Celsius, 32 Fahrenheit, but will fail below that because /5 does not work correctly on negative numbers on the Stamp.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
A small start, but now I can't wait to·get·some more sensors set up and maybe delve into controlling pumps when I get some more experience.
Thanks,
Bill