TLOG - Utility to measure and log Temperature.

by Geoff Hitchcox Christchurch, New Zealand.


Background:

For my current R&D project I needed accurate temperature measurements at many locations on the equipment I am developing. I decided on the DALLAS DS18S20 that allows multiple sensors to share the same wiring.

This webpage presents a program TLOG that I developed from learning how to communicate with the DS1820 (DS18S20) temperature sensor. I have now incorporated my software routines into my much larger R&D project where I measure many sensors. However I have made TLOG available as FREEWARE on this page for anyone wanting a quick temperature logging system (to 0.06 degree resolution) for hobby or science experiments. My concept is to use old junk DOS PC's to gather the data, and not tie up a larger Windows machine - which (as we all know ;-) can have reliability issues long term.

Multiple sensors:

TLOG is a quick and easy solution if you just want to measure ONE temperature sensor. For those wanting to use more sensors, I have now completed a program similar to TLOG called MLOG that can read/log up to 20 DS1820 sensors.

The DS18S20 sensor:

is a small 3 terminal device that looks like a transistor. It contains a calibrated temperature sensor, an analogue to digital converter and a serial "one wire" protocol for communication. The cost of the DS1820 bought locally in Christchurch, New Zealand was US$7. For the electronic experimenter it is an absolute delight to "play" with.

Interface software for the DS1820 made available on the "net", tends to use the PC serial port (plus many additional components). However I wanted to use the parallel port with NO additional components. Careful attention to timing issues in the software makes the "wiring" much simpler for the user.


You can see from the following circuit how simple the interface is - no power supply or extra components are required. [DS1820 to PC Interface]
An example of using TLOG: I connected a 20 metre cable from the printer port to the DS1820 as per above wiring. I placed the DS1820 on a table in my lounge and ran TLOG for a 24 hour period from 6pm to 6pm. I requested it to sample at 1 minute intervals logging temperature in degrees Centigrade. The data is saved in a file called TLOG.CSV, the beginning and end of the file is shown here.
08-01-2003 18:00:00, 26.25
08-01-2003 18:01:00, 26.31
08-01-2003 18:02:00, 26.25

< SNIP of intervening numbers >

Format of the data is
DD-MM-YYYY HH:MM:SS, Temperature (degrees Centigrade)

09-01-2003 17:58:00, 25.56
09-01-2003 17:59:00, 25.56
09-01-2003 18:00:00, 25.62
TLOG.CSV is a "comma separated value" file that EXCEL will pull in without requiring the format. After the 24 hr sampling, I placed the file on my big Windows machine and "clicked" on the TLOG.CSV file which started EXCEL and automatically loaded the file. Within seconds I produced the following graph, showing that a picture is worth a thousand words (or 1,440 numbers in this case ;-) [Geoff's Lounge Temperature over 24 hrs]
The temperature peaked at 26.31 and went down to 19.44 just before the sun started to warm the house again. This matched my mercury "Max-Min" thermometer (thanks again John) to within 1/4 degree. Another click of the mouse in Excel showed the average temperature over the 24 hours was 22.36 degrees, showing Christchurch is a nice place to live (at this time of year). Let's look a little closer at the data, using Excel to graph the temperature as the room cooled from 21 to 20 degrees. [21to20 detail]
We can clearly see the full resolution of the DS1820 at 0.0625 degrees Centigrade. Note that it took 150 minutes (2.5 hours) for the room to cool just one degree.

Here are the Menu options of TLOG
             TLOG - Prototype DS1820 Temperature Monitor          Ver 0.2


     Logging Data is saved to TLOG.CSV to allow direct input to EXCEL


1 - Printer Port Testing Function

2 - Raw data from DS1820 sensor, continuous sampling, NO logging

3 - Log Temperature (Centigrade) every second
4 - Log Temperature (Centigrade) every minute

5 - Log Temperature (Fahrenheit) every second
6 - Log Temperature (Fahrenheit) every minute


ENTER number for function required or ESC key to quit.

A screen shot of Option 2
                   DS1820 Raw Data Monitor                  ESC key for menu

Scratchpad Values (in Hexadecimal)

Byte 0 = 2A   LSB Temperature
Byte 1 =  0   MSB Temperature
Byte 2 = 4B   Th Register
Byte 3 = 46   Tl Register
Byte 4 = FF   Reserved
Byte 5 = FF   Reserved
Byte 6 =  D   Count Remain
Byte 7 = 10   Count per degree C
Byte 8 = D1   CRC (Cyclic Redundancy Check)

Samples = 33027     CRC Errors = 0

    MIN Temperature =  20.31 C  =  68.56 F
    AVG Temperature =  21.37 C  =  70.46 F
    MAX Temperature =  23.19 C  =  73.74 F

Current Temperature =  20.94 C  =  69.69 F

Discussion: I have implemented two logging speeds. For fast changing temperature situations, TLOG can log once per second (which is the fastest we can sample the DS1820 anyway). For slower changing situations, sampling at one minute intervals is provided. I have found this perfect to do a range of temperature coefficient measurements using the natural diurnal change that occurs in a house. In a room not facing the sun the temperature changes are nice and slow allowing thermal equilibrium in the device being measured. So one can do quite advanced measurements in a home "without" having to need a precision oven system. You only need to monitor the temperature accurately, which I think you will find TLOG and the DS1820 can do quite nicely. I have had a lot of enjoyment writing the software and also using it - I hope others may find it useful as well.

The data from the DS1820 has a Cyclic Redundant Check made on each byte transmitted, TLOG does the CRC check on the received data and reports any errors, it will not log faulty data.

Requirements: TLOG was compiled as a 16bit DOS application, requiring DOS 3.0 or above. The PC does not have to be state of the art, any old pc/laptop AT and above is okay, even a 20 MHz '286' 15 year old AT can easily meet spec. TLOG can make that old "junk" PC suddenly have a purpose in life!

As a DIY hobby project it should only take a few minutes to put together. After obtaining a DS1820, just wire the three terminals via a cable to a DB25 parallel printer connector as per the above drawing.

The program should not be run from a W9x/ME DOS window because the program auto calibrates its timing based on the CPU clock speed. This process is "ruined" by the W9x/ME operating system time sharing the CPU. To use the program from W9x, you must click on "Start" and "Shut Down" to "restart in MSDOS Mode".


Installation:

Copy TLOG.ZIP (Version 0.3) to a new (any name) directory on your PC. Unzip contents and read the file README.TXT for further information.

Source Code:

I get many requests for the source code for TLOG. However, because it uses some of my commercial code, I do not release the source code under any circumstance.

Support and Additional Information:

TLOG written by Geoff Hitchcox, Christchurch, New Zealand, South Pacific.

Windows Users:

Many readers of this page are wanting to measure multiple temperatures with a WINDOWS box. So if this is your requirement, then may I suggest you have a look at this Windows Thermometer from Finland. I have personally not used it, however it appears to be a well done project. It uses the serial port hardware to do the critical timing, which is why it can be run on a Windows box.
Sensor Information:

Dallas DS1820 information Page

Complete DS1820 Data Sheet (PDF format)
[DS1820 Package Styles]
Hosted by www.Geocities.ws

1