NSLU2-Linux
view · edit · print · history

Add USB-to-1-Wire Adapter

This is how to configure a NSLU2 running slugos/be 4.8 beta to act as a temperature monitor using DigiTemp and a http://www.homechip.com/catalog/product_info.php?cPath=22&products_id=30(approve sites) DS9490R? USB-to-1-wire adapter.

The same steps probably apply to an Unslung NSLU2 but I haven't tried that. They probably also apply to other USB-to-1-Wire adapters.

Feel free to contact me at lee atnospam kimberconsulting.com with comments and ideas for improvement. One thing I am seeing is that the system is sometimes unable to print a response from the second sensor of my two-sensor 1-wire LAN, as can bee seen from the output reproduced below.

Some points to note:

  • I wasted a lot of time trying to configure to NSUL2? to present a /dev/ttyUSB0 device for drivers to use to comunicate to the DS9490R? USB-to-1-wire adapter. I cracked this problem when I stopped loading usbserial, stopped trying to figure out what vendor and productID arguments to feed usbserial when I loaded it it; stopped loading a device driver (pl2303 or ftdi_sio) and stopped chmodding the resulting /dev/ttyUSB0. I blame Google for misdirecting me down those paths and merely nod towards the role played by my own incompetence.
  • It also helped me to run the /opt/bin/digitemp_DS2490 binary installed by 'ipkg-opt digitemp', rather than the /opt/bin/digitemp_DS9097 and /opt/bin/digitemp_DS9097U binaries also installed by that package.

Wire up the sensors to the DS9490R? USB-to-1-wire adapter and plug the adapter into the NSLU2.

Turn it on. You can hot plug the USB-to-1-wire adapter if you want. While I was in the fruitless 'hunt for the USB port and load the correct drivers' loop described above, I did hot plug the DS9490R? USB-to-1-wire adapter so that I could identify what the NSLU2 saw it as by listing /dev/ and catting /dev/bus/usb/devices.

With the DS9490R? USB-to-1-wire adapter installed, on first run of digitemp, 'walk' it up the sensor network to see what sensors it can find. To do that, run it with the following '-w' argument:

/opt/bin/digitemp_DS2490 -w

You should see an output something like this:

root@deflation:~$ /opt/bin/digitemp_DS2490 -w
DigiTemp v3.4.0 Copyright 1996-2005 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Found DS2490 device #1 at 3/2
Turning off all DS2409 Couplers
...
Devices on the Main LAN
1092495500080011 : DS1820/DS18S20/DS1920 Temperature Sensor
10E71C5500080025 : DS1820/DS18S20/DS1920 Temperature Sensor
818B302A00000057 : Unknown Family Code

Looks like it found my two temperature sensors!

Now write a /root/.digitemprc file by running digitemp like this:

/opt/bin/digitemp_DS2490 -a -q -i

You should see an output that looks something like this:

root@deflation:~$ /opt/bin/digitemp_DS2490 -a -i
Found DS2490 device #1 at 3/2
1092495500080011 : DS1820/DS18S20/DS1920 Temperature Sensor
10E71C5500080025 : DS1820/DS18S20/DS1920 Temperature Sensor
ROM #0 : 1092495500080011
ROM #1 : 10E71C5500080025

You should also now find that there is a file called .digitemprc in your current directory. It's contents will look something like this:

root@deflation:~$ cat /root/.digitemprc
TTY USB
READ_TIME 1000
LOG_TYPE 1
LOG_FORMAT "%b %d %H:%M:%S Sensor %s C: %.2C F: %.2F"
CNT_FORMAT "%b %d %H:%M:%S Sensor %s #%n %C"
HUM_FORMAT "%b %d %H:%M:%S Sensor %s C: %.2C F: %.2F H: %h%%"
SENSORS 2
ROM 0 0x10 0x92 0x49 0x55 0x00 0x08 0x00 0x11
ROM 1 0x10 0xE7 0x1C 0x55 0x00 0x08 0x00 0x25

It's not hard to see in the above that digitemp has stored the ROM numbers of the devices that it found, as well as a default output format for the displaying the values that it finds.

We can now run digitemp in continuous mode by issuing commands like:

root@deflation:~$ /opt/bin/digitemp_DS2490 -a -d 30 -n 0

and should see an output something like this:

root@deflation:~$ /opt/bin/digitemp_DS2490 -a -d 30 -n 0
DigiTemp v3.4.0 Copyright 1996-2005 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Found DS2490 device #1 at 3/2
Jun 29 13:16:26 Sensor 0 C: 25.75 F: 78.35
Jun 29 13:16:28 Sensor 1 C: 20.88 F: 69.57
Jun 29 13:16:56 Sensor 0 C: 25.75 F: 78.35
Jun 29 13:16:57 Sensor 1 C: 20.88 F: 69.57

with the lines incrementing every 30 seconds.

The temperature format is being set by that .digitemprc file. We can change the .digitemprc file to give us more control over the output. For example, changing the line: LOG_FORMAT "%b %d %H:%M:%S Sensor %s C: %.2C F: %.2F" to LOG_FORMAT "%b %d %H:%M:%S Sensor %s C: %.2C"

gives us a Centigrade-only output thusly:

root@deflation:~$ /opt/bin/digitemp_DS2490 -a -d 30 -n 0
DigiTemp v3.4.0 Copyright 1996-2005 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Found DS2490 device #1 at 3/2
Jun 29 13:18:37 Sensor 0 C: 25.75
Jun 29 13:18:38 Sensor 1 C: 20.88
Jun 29 13:19:37 Sensor 0 C: 25.75
Jun 29 13:19:38 Sensor 1 C: 20.88

We can log the output to a file (and tail the file, which is helpful if we make intermittent connections to the NSLU2) by starting digitemp like this:

root@deflation:~$ /opt/bin/digitemp_DS2490 -a -d 30 -n 0 -l /var/log/temperature
DigiTemp v3.4.0 Copyright 1996-2005 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Found DS2490 device #1 at 3/2

And tail the file like this:

root@deflation:~$ tail -f /var/log/temperature
Jun 29 13:22:50 Sensor 0 C: 25.75
Jun 29 13:23:20 Sensor 0 C: 25.75
Jun 29 13:23:22 Sensor 1 C: 20.88
Jun 29 13:23:50 Sensor 0 C: 25.69
Jun 29 13:23:51 Sensor 1 C: 20.88

To start digitemp automatically when the NSLU2 is booted, a simple script can be added to the init.d directory, as follows:

#!/bin/sh

if [ -n "`pidof digitemp_DS2490`" ] ; then
    killall digitemp_DS2490 2>/dev/null
fi

sleep 2
/opt/bin/digitemp_DS2490 -q -a -d 300 -n 0 -r 1000 -c /root/.digitemprc -l /var/log/temperature &

The parameters passed to the command will need to be modified to suit your requirements.

There's more you can do to modify the output of digitemp, and you can see the full range of modifier arguments by just typing:

/opt/bin/digitemp_DS2490

You can also read DigiTemp? author Brian Lane's usage notes at http://www.debian-doc.org/packages/d/digitemp/README.html(approve sites), noting as you do that the comments there about supplying a '-s /dev/ttyS0' port do not apply in our scenario.

Note: I found that setting argument -d to 10 or less occasionally prompted messages saying the software needed up to second seconds to read the sensors.

view · edit · print · history · Last edited by Neil Ronketti.
Based on work by Neil Ronketti and Lee Kimber.
Originally by Lee Kimber.
Page last modified on January 10, 2009, at 12:01 AM