See the following link. Tracy Allen posted a link to a Digital Thermometer and I posted one as well to a project (Digital Thermostat) he actually helped me with the conversion code on. I hope this helps. Take care.
1) You have to know the formula for converting from Celsius to Fahrenheit
2) Because the Stamp only does 16-bit integer arithmetic, you have to decide how much precision you want (tenths of a degree or degrees or what?)
3) Have a look at EmeSystems' website (www.emesystems.com) for all kinds of information on doing fixed point arithmetic with the Stamp, particularly the webpage on math. There are lots of practical examples with sample code for the Stamp.
From the code I linked to, here is the routine which reads the temperature from the DS1620 and then converts the C temp to F. Thanks to Tracy Allen for offering improvements to my original code. Resolution is much improved although in this application I am only using 1 degree of resolution anyway. Take care.
Get_Temp:
HIGH Reset ' Select DS1620
SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdTemp] ' Send Read Temp Command
SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]tempIn\9] ' Read Temp Data
LOW Reset ' Deselect DS1620
tempIn.BYTE1 = -tempIn.BIT8 ' Extend Sign To 16 Bits
tempC = tempIn * 5 ' Convert To C * 5 (Resolution 0.5 C)
tempF = tempC + 2732 * 9 / 50 - 459 ' C * 10 to F (First To Kelvin * 10)
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Chris Savage Parallax Tech Support
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
Tom
http://forums.parallax.com/showthread.php?p=646324
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
2) Because the Stamp only does 16-bit integer arithmetic, you have to decide how much precision you want (tenths of a degree or degrees or what?)
3) Have a look at EmeSystems' website (www.emesystems.com) for all kinds of information on doing fixed point arithmetic with the Stamp, particularly the webpage on math. There are lots of practical examples with sample code for the Stamp.
celcius to F
double it and add 32 (ie 20C = 72F)
F to celcius
subtract 32 then halve it (ie 80F = 24C)
2. more generally: c to F
F= (9/5 * C) +32
F to C
C= (F-32)*5/9
As Mike has pointed out, watch your variable sizes and anticipate the maximum possible result of any calculations.
Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Whit+