Connecting the Dallas DS18B20 1-Wire Digital Thermometer to the PICAXE
Here we're going to connect a Dallas DS18B20 1-Wire Digital Thermometer to a PICAXE microcontroller. This is very easy because the M2 series of parts have a direct, single line command to access the part. It has an operating temperature range of -55°C to +125°C. Here I'm not concerned with the really advanced features of the DS18B20 but the main feature that will be used 90 percent of the time; to simply read the temperature. To use the really advanced features use the Arduino microcontroller.
The commands READTEMP pin, variable and READTEMP12 pin, word variable are explained on pages 184-185 in the PICAXE literature. Here I'm simply concerned with READTEMP because to use READTEMP12 is a mess and just not worth the effort. Understand the PICAXE microcontroller has a built-in interpreted basic that in the smaller versions I use have limitations. This is more than offset by ease of use and easy to learn.
About the readtemp command:
This command only functions at 4MHz. M2, X1 and X2 parts automatically use the internal 4MHz resonator for this command.
The temperature is read back in whole degree steps, and the sensor operates from -55 to + 125 degrees Celsius. Note that bit 7 is 0 for positive temperature values and 1 for negative values (ie negative values will appear as 128 + numeric value).
Note the readtemp command does not work with the older DS1820 or DS18S20 as they have a different internal resolution. This command is not designed to be used with parasitically powered DS18B20 sensors, the 5V pin of the sensor must always be connected.
symbol DS18B20_Pin = C.1 main: readtemp DS18B20_Pin, w1 ; read value into w1 if w1 > 127 then negative ; test for negative w1 = w1 * 9 / 5 + 32 ; covert to Fahrenheit sertxd ("+", #w1, " degrees ", 13, 10) ; transmit value to term goto main negative: ; label let w1 = w1 - 128 ; adjust neg value w1 = w1 * 9 / 5 + 32 ; covert to Fahrenheit sertxd ("-", #w1, " degrees ", 13, 10) ; transmit to term goto main
If using this material on another site, please provide a link back to my site.