Serial Port Temperature Sensors - Software
This page describes the linux software required to interface
to the temperature sensors via a PC's serial port.
If you are using a USB-serial adapter instead of a serial port interface circuit,
refer to the USB hardware interface page for information on
using digitemp with a USB-serial adapter.
Overview
On linux, the digitemp application is required to query the temperature sensor.
As the the serial port interface circuit
described previously is equivalent to the DS9097U 1-wire serial port adapter,
we'll use the binary designed for the 9097 adapter, namely
digitemp_9097.
Note that a Windows version of digitemp is also available.
Installing digitemp
Installing on Debian / Ubuntu
On debian and Ubuntu, digitemp can be installed using apt-get:
apt-get install digitemp
This will install three binaries into /usr/bin, one for each
type of 1-wire interface adapter.
Installing on RedHat / Fedora
Download the latest tarball from the
digitemp website
(when this page was first created, this was
digitemp-3.4.0.tar.gz),
and copy or SCP this tarball into /usr/src on your linux box.
Note that the digitemp tarball contains three spec files
(digitemp_2490.spec,
digitemp_9097.spec and
digitemp_9097u.spec),
and rpmbuild will default to the first one, but we want digitemp_9097, which
is for the serial port adapter.
Because of this, we can't just build the rpm directly from the tarball, but need
to extract the required spec file from the tarball.
Copy the digitemp tarball into /usr/src/redhat/SOURCES/
(this is the default directory rpmbuild will use when building from a
spec file).
Extract the required spec file into /tmp:
tar zxvf /usr/src/digitemp-3.4.0.tar.gz -C /tmp digitemp-3.4.0/digitemp_9097.spec
Then build the digitemp_9097 RPM, specifying the appropriate spec file:
rpmbuild -bb /tmp/digitemp-3.4.0/digitemp_9097.spec
and install the resulting RPM:
rpm -Uvh /usr/src/redhat/RPMS/i386/digitemp-3.4.0-1_ds9097.i386.rpm
This will install the binary as
/usr/local/bin/digitemp_DS9097.
Installing on other Linux distributions
If using another linux distribution, you'll need to manually compile from the source.
Download the latest tarball from the
digitemp website,
and SCP into /usr/src/ on your linux box.
Extract the contents of the tarball:
cd /usr/src
tar zxvf digitemp-3.4.0.tar.gz
and compile it:
cd digitemp-3.4.0
make ds9097
make install
Note that the make install is likely to fail for digitemp 3.4.0,
so manually copy the binary:
cp digitemp_DS9097 /usr/local/bin
Create Symbolic Link
Create a digitemp symbolic link to the
digitemp_DS9097 binary:
ln -s /usr/local/bin/digitemp_DS9097 /usr/local/bin/digitemp
Configuring digitemp
Initialise digitemp
First we need to configure the interface by telling digitemp the serial port that
the interface is connected to.
By default, digitemp will look for a configuration file (.digitemprc)
in the current working directory, so we'll explicitly specify the location of the
configuration file.
Assuming the interface is connected to COM1 (ie, ttyS0):
digitemp -i -s /dev/ttyS0 -q -c /etc/digitemp.conf
You should see output similar to this:
Turning off all DS2409 Couplers
.
Searching the 1-Wire LAN
100486B60008009E : DS1820/DS18S20/DS1920 Temperature Sensor
ROM #0 : 100486B60008009E
This will create a file /etc/digitemp.conf
containing the configuration information for digitemp.
Permissions
If you attempt to run digitemp from a user account which doesn't
have access to the serial port, you'll see something similar to this
when you run digitemp:
Error, you don't have +rw permission to access /dev/ttyS0
The solution is to either run digitemp as root,
or relax the permissions on the serial port.
To allow everyone read/write access to COM1 (ie, /dev/ttyS0),
run the following as root:
chmod a+rw /dev/ttyS0
Adjust Read Delay
Note that the DS18S20 temperature sensor has a slightly slower response time
(to convert its reading to a temperature) than the original
DS1820 sensor
The DS18S20 sensor takes approx 750ms to do the temperature conversion,
and digitemp defaults to a 1000ms read delay.
If you are occasionally getting temperature readings of 85 degrees Celsius (which is the sensor's error code),
you'll need to slow down the read delay performed by digitemp from
the default 1000ms.
To set the read delay to 2000ms and store this configuration in
/etc/digitemp.conf, run the following:
digitemp -i -q -r2000 -c /etc/digitemp.conf
With relatively short wire runs between the sensor and the serial interface
circuit, I've found that the default read delay of 1000ms provides reliable
temperature readings.
Reading Temperatures
Query Temperature
The sensor can now be queried for the current temperature (the "-a" tells
digitemp to read all connected sensors):
digitemp -a -q -c /etc/digitemp.conf
and output similar to this should be displayed:
Apr 17 23:09:56 Sensor 0 C: 26.69 F: 80.04
Handling Errors
Note that occasionally the DS18S20 temperature sensor will return an error code,
returning a value of 85 degrees Celsius, instead of a valid temperature reading.
If this occurs, re-reading the temperature will normally return the correct value.
last updated 13 Jun 2015
|