evfit
Posts: 1
Joined: Sun Jul 15, 2012 7:20 pm

Reading a 1-wire DS18B20 temperature sensor using OWFS

Fri Dec 28, 2012 11:57 pm

I have been monitoring my solar panels for some time using the now discontinued DALLAS/MAXIM TINI board (see my web site http://www.eausolaire.eu). Now I would like to do the same thing with the Raspberry Pi. As a first step, I set out to interface my 1-wire microLAN on the RPI using the OWFS program (One Wire File System, http://www.owfs.org/).
Here is the sequence of operations to be completed in order to install OWFS, to connect to a DS9490R USB 1-wire adapter, to read the temperature measured by a DS18B20 and to display it on the terminal using a small Python script.

Make sure you have the latest RPI firmware (earlier firmware apparently caused my DS9490R USB adapter to disconnect in a random fashion). For an easy way to update the firmware of your Raspberry, install rpi-update (https://github.com/Hexxeh/rpi-update). Then, on the terminal promt, type :

Code: Select all

pi@raspberrypi ~ $ sudo rpi-update
and reboot.

In order to prevent the the system to automatically launch modules that may interfere with OWFS, create a file in the "etc/modprobe.d" directory using the nano editor:

Code: Select all

pi@raspberrypi ~ $ sudo nano etc/modprobe.d/ds2490
containing the three lines:

Code: Select all

blacklist ds2490
blacklist ds9490r
blacklist wire
Next, install OWFS

Code: Select all

sudo apt-get install owfs
and verify that it has been properly installed using

Code: Select all

pi@raspberrypi ~ $ aptitude show owfs
and where it has been installed:

Code: Select all

pi@raspberrypi ~ $ ls -l /usr/local/bin
owtap       owdir  owget             easy_install  rs232    owwrite   owread
owexternal  .      owpresent         ..            owhttpd  owserver
sjinn       owfs   easy_install-2.7  owftpd        owexist  owmon
Edit the "owfs.conf" file located in "/etc" using:

Code: Select all

pi@raspberrypi ~ $ sudo nano /etc/owfs.conf 
Comment the lines containing "FAKE" and uncomment the lines containing "server : usb = all", "mountpoint = /mnt/1wire" and "allow_other" as shown hereunder:

Code: Select all

# Sample configuration file for the OWFS suite for Debian GNU/Linux.
# This is the main OWFS configuration file. You should read the
# owfs.conf(5) manual page in order to understand the options listed
# here.
######################## SOURCES ########################
# With this setup, any client (but owserver) uses owserver on the
# local machine...
! server: server = localhost:4304
# ...and owserver uses the real hardware, by default fake devices
# This part must be changed on real installation
#server: FAKE = DS18S20,DS2405
# USB device: DS9490
server: usb = all
# Serial port: DS9097
#server: device = /dev/ttyS1
# owserver tcp address
#server: server = 192.168.10.1:3131
# random simulated device
#server: FAKE = DS18S20,DS2405
######################### OWFS ##########################
mountpoint = /mnt/1wire
allow_other
####################### OWHTTPD #########################
http: port = 2121
####################### OWFTPD ##########################
ftp: port = 2120
####################### OWSERVER ########################
server: port = localhost:4304
Edit the "fuse.conf" file in directory "/etc" in order to allow using the "--allow_other" option when invoking the OWFS program at the terminal prompt later on.

Code: Select all

pi@raspberrypi ~ $ sudo nano /etc/fuse.conf 
Uncomment the line containng "user_allow_other" as shown hereunder:

Code: Select all

# Set the maximum number of FUSE mounts allowed to non-root users.
# The default is 1000.
#
#mount_max = 1000  

# Allow non-root users to specify the 'allow_other' or 'allow_root'
# mount options.
#

user_allow_other
Now it is the right time to insert the DS2490 USB adapter. To check whether the USB adapter is recognized by the RPI, type:

Code: Select all

pi@raspberrypi ~ $ sudo lsusb
Next, create the directory where OWFS will create its file system:

Code: Select all

pi@raspberrypi ~ $ sudo mkdir /mnt/1wire
Finally, it is time to start OWFS by typing "sudo owfs -C -uall -m /mnt/1wire --allow_other":

Code: Select all

pi@raspberrypi ~ $ sudo owfs -C -uall -m /mnt/1wire --allow_other
DEFAULT: ow_usb_msg.c:(295) Opened USB DS9490 bus master at 1:7.
DEFAULT: ow_usb_cycle.c:(191) Set DS9490 1:7 unique id to 81 22 65 2D 00 00 00 5C
The option "-C" is for expressing temperature in Celsius degree, "-uall" is for probing all USB ports, "-m /mnt/1wire" specifies where the OWFS directory tree is going to be built and "--allow_other" enables users other than the root to access OWFS directories. "81 22 65 2D 00 00 00 5C" has two parts: " 22 65 2D 00 00 00 5C" is the ID of my DS9490 USB adapter and "81" is a code specifying what kind of device it is.
Now let us explore the tree which has been created by OWFS:

Code: Select all

pi@raspberrypi ~ $ ls /mnt/1wire
28.2B7814020000  alarm  settings      statistics  system
81.22652D000000  bus.0  simultaneous  structure   uncached

pi@raspberrypi ~ $ ls /mnt/1wire/28.2B7814020000
address  errata    id       r_address  temperature    temperature12  templow
alias    family    locator  r_id       temperature10  temperature9   type
crc8     fasttemp  power    r_locator  temperature11  temphigh
In addition to the adapter ("81.22652D000000"), a second device is present on the 1-wire ("28.2B7814020000"). This second device is the DS18B20 temperature sensor. "28" is the code given by Dallas (the conceptor of the 1-wire) to the family of temperature sensing device to which DS18B20 belongs and "2B7814020000" is the ID of the device I am using (each Dallas 1-wire device exemplar possesses a unique ID). "temperature" is the name of the ASCII file that contains the measured temperature. I can be read using the "cat" command.

Code: Select all

pi@raspberrypi ~ $ cat /mnt/1wire/28.2B7814020000/temperature
     21.4375
Here is a short Python script (named owtemp.py) which displays the measured temperature and updates the reading every minute:

Code: Select all

#!/usr/bin/env python

# owtemp.py. This script prints the measured temperature in °C and updates every minute.

import time
import os

file_name=os.path.join("/","mnt","1wire","28.2B7814020000","temperature")

while 1:
    file_object=open(file_name,'r')  
    line=file_object.read()
    print(line+'C')
    time.sleep(60) 
    file_object.close()
To start the Python script, type at the terminal prompt:
python owtemp.py
. To stop the script, type:
ctrl c
If you experience some problem after starting OWFS and you want to restart it, an error message will be issued :

Code: Select all

pi@raspberrypi ~ $ sudo owfs -C -uall -m /mnt/1wire --allow_other
........................
.........................
pi@raspberrypi ~ $ sudo owfs -C -uall -m /mnt/1wire --allow_other
DEFAULT: ow_usb_msg.c:(295) Opened USB DS9490 bus master at 1:7.
DEFAULT: ow_usb_cycle.c:(213) Set DS9490 1:7 unique id to 28 2B 78 14 02 00 00 7A
fuse: mountpoint is not empty
fuse: if you are sure this is safe, use the 'nonempty' mount option
To avoid this error message you should unmount the OWFS directories before restarting OWFS:

Code: Select all

pi@raspberrypi ~ $ sudo umount /mnt/1wire
Several other 1-wire devices can be accessed in the same way using OWFS. I tested sucessfully the DS2423 (a dual counter), the DS2438 and DS2760 (both including a temperature sensor, an A/D converter and a current accumulator) and the DS2450 (a quad A/D converter). Next, I put these devices on the same 1-wire microLAN (i.e. connected in parallel to the data wire and to the ground wire), along with the DS18B20 temperature sensor, and I could access all of them sequentially using OWFS.

peterwit
Posts: 5
Joined: Mon May 14, 2012 2:26 am

Re: Reading a 1-wire DS18B20 temperature sensor using OWFS

Wed Jan 09, 2013 1:12 am

have you tried the owpython package for OWFS? I'm trying to get a similar setup as you have described, but i've never done python or anything with 1wire before. Is the owpython binding just a way to talk to OWFS without mounting and dealing with directory trees?

migube
Posts: 29
Joined: Tue Jul 17, 2012 7:02 am

Re: Reading a 1-wire DS18B20 temperature sensor using OWFS

Sun Feb 24, 2013 1:58 pm

tx for this guide ! working well :)

small Question
my ls shows
05.4AEC29CDBAAB 1D.C0A806000000 29.8B1000000000 10.67C6697351FF 20.FC4D05000000 2C.AE9B05000000
devices

while the http page only shows the 10.X & 05.X, not the other :(
I need to access the DS2450 20.x but it does not appear, neither in the owserver

any idea?
tx

Stefan_PI
Posts: 2
Joined: Thu Feb 13, 2014 6:18 pm

Re: Reading a 1-wire DS18B20 temperature sensor using OWFS

Thu Feb 13, 2014 6:20 pm

HI!

Do you have any idea what rrdtool to get for python?

Stefan

Illico
Posts: 1
Joined: Thu Feb 27, 2014 7:48 pm

Re: Reading a 1-wire DS18B20 temperature sensor using OWFS

Thu Feb 27, 2014 8:05 pm

I would like to use OWFS with direct GPIO interface using kernel w1 module, to read DS2423 counter values.

I use the following command :

Code: Select all

sudo owfs -C --w1 -m /mnt/1wire --allow_other
But that freeze and have to make a CTRL+C to quite.
With debug option :

Code: Select all

pi@illicorasp /opt/owfs/bin $ sudo ./owfs -C --w1 -m /mnt/1wire --allow_other --debug
DEBUG MODE
libow version:
        2.9p2
CONNECT: owfs.c:(96) fuse mount point: /mnt/1wire
CONNECT: ow_avahi_link.c:(68) No Avahi support. Library libavahi-client couldn't be loaded
CONNECT: ow_dnssd.c:(82) Zeroconf/Bonjour is disabled since dnssd library isn't found
   CALL: ow_parsename.c:(99) path=[]
  DEBUG: owlib.c:(81) Globals temp limits 0C 100C (for simulated adapters)
  DEBUG: fuse_line.c:(82) Added FUSE option 0 OWFS
  DEBUG: fuse_line.c:(82) Added FUSE option 1 /mnt/1wire
  DEBUG: fuse_line.c:(82) Added FUSE option 2 -o
  DEBUG: fuse_line.c:(82) Added FUSE option 3 direct_io
  DEBUG: fuse_line.c:(82) Added FUSE option 4 -f
  DEBUG: fuse_line.c:(82) Added FUSE option 5 -d
  DEBUG: owfs.c:(121) fuse_mnt_opt=[(null)]
  DEBUG: owfs.c:(123) fuse_open_opt=[(null)]
  DEBUG: fuse_line.c:(82) Added FUSE option 6 -o
  DEBUG: fuse_line.c:(82) Added FUSE option 7 allow_other
  DEBUG: ow_w1_list.c:(54) Sending w1 bus master list message
  DEBUG: ow_w1_send.c:(132) Netlink send -----------------
NLMSGHDR: len=48 type=3 (NLMSG_DONE) flags=5 seq=0|1 pid=3199
CN_MSG: idx/val=3/1 (CN_W1_IDX) seq=0|1 ack=1 len=12 flags=0
W1_NETLINK_MSG: type=6 (W1_LIST_MASTERS) len=0 id=0
W1_NETLINK_CMD: NULL w1c field
NULL data
  DEBUG: ow_w1_send.c:(143) NETLINK sent seq=1
  DEBUG: ow_w1_dispatch.c:(173) Dispatch loop
  DEBUG: ow_w1_parse.c:(113) Wait to peek at message
  DEBUG: ow_w1_parse.c:(121) Pre-parse header: 16 bytes len=52 type=3 seq=0|1 pid=0
  DEBUG: ow_w1_parse.c:(142) Netlink read -----------------
NLMSGHDR: len=52 type=3 (NLMSG_DONE) flags=0 seq=0|1 pid=0
CN_MSG: idx/val=3/1 (CN_W1_IDX) seq=0|1 ack=0 len=16 flags=30309
W1_NETLINK_MSG: type=6 (W1_LIST_MASTERS) len=4 id=29033
W1_NETLINK_CMD: NULL w1c field
Byte buffer Data, length=4
--000: 01 00 00 00
   <....>
  DEBUG: ow_w1_dispatch.c:(88) Netlink message directed to root W1 master
  DEBUG: ow_w1_dispatch.c:(126) Sending this packet to root bus
  DEBUG: ow_w1_dispatch.c:(173) Dispatch loop
  DEBUG: ow_w1_parse.c:(113) Wait to peek at message
  DEBUG: ow_w1_parse.c:(121) Pre-parse header: 16 bytes len=48 type=3 seq=0|1 pid=0
  DEBUG: ow_w1_parse.c:(142) Netlink read -----------------
NLMSGHDR: len=48 type=3 (NLMSG_DONE) flags=0 seq=0|1 pid=0
CN_MSG: idx/val=3/1 (CN_W1_IDX) seq=0|1 ack=1 len=12 flags=0
W1_NETLINK_MSG: type=6 (W1_LIST_MASTERS) len=0 id=0
W1_NETLINK_CMD: NULL w1c field
NULL data
  DEBUG: ow_w1_dispatch.c:(88) Netlink message directed to root W1 master
  DEBUG: ow_w1_dispatch.c:(126) Sending this packet to root bus
  DEBUG: ow_w1_dispatch.c:(173) Dispatch loop
  DEBUG: ow_w1_parse.c:(113) Wait to peek at message
  DEBUG: ow_w1_scan.c:(54) Netlink (w1) list all bus masters
  DEBUG: ow_w1_list.c:(64) W1 List 0 masters
  DEBUG: ow_w1_scan.c:(54) Netlink (w1) list all bus masters
  DEBUG: ow_w1_list.c:(64) W1 List 1 masters
  DEBUG: ow_w1_addremove.c:(55) Setup structure for w1_bus_master1
  DEBUG: ow_w1_addremove.c:(80) Request master be added: w1_bus_master1.
  DEBUG: ow_add_inflight.c:(26) Request master be added: w1_bus_master1
FUSE library version: 2.9.0
nullpath_ok: 0
nopath: 0
utime_omit_ok: 0
unique: 1, opcode: INIT (26), nodeid: 0, insize: 56, pid: 0
INIT: 7.22
flags=0x0000f7fb
max_readahead=0x00020000
   INIT: 7.18
   flags=0x00000011
   max_readahead=0x00020000
   max_write=0x00020000
   max_background=0
   congestion_threshold=0
   unique: 1, success, outsize: 40


A also try with w1_ds2423, with following command line but I always have the same answer.

Code: Select all

pi@illicorasp ~ $ sudo modprobe wire
pi@illicorasp ~ $ sudo modprobe w1-gpio
pi@illicorasp ~ $ sudo modprobe w1-ds2423
pi@illicorasp ~ $ cat /sys/devices/w1_bus_master1/1d-01000084d9a2/w1_slave
00 00 00 00 00 00 00 00 00 ec e1 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff crc=YES c=0
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff crc=NO
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff crc=NO
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff crc=NO
pi@illicorasp ~ $
Does anyone have an idea?

using Linux 3.10.30+ with owfs 2.9p2


Thanks

xyzzy2020
Posts: 1
Joined: Tue Nov 03, 2015 12:50 am

Re: Reading a 1-wire DS18B20 temperature sensor using OWFS

Tue Nov 03, 2015 1:02 am

Hi Thanks in advance for the help. I have followed the instructions here very closely but I still can not see the my 1wire adapter.
lsusb reveals the following:
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 04fa:2490 Dallas Semiconductor DS1490F 2-in-1 Fob, 1-Wire adapter


after running owfs : $sudo owfs [-c owfs.conf] -F -u -m /mnt/1wire --allow_other
as ls of the /mnt/1wire shows:
bus.0 bus.1 settings statistics structure system uncached

but no devices!!!
owfs.conf
# Sample configuration file for the OWFS suite for Debian GNU/Linux.
#
#
# This is the main OWFS configuration file. You should read the
# owfs.conf(5) manual page in order to understand the options listed
# here.

######################## SOURCES ########################
#
# With this setup, any client (but owserver) uses owserver on the
# local machine...
! server: server = localhost:4304
#
# ...and owserver uses the real hardware, by default fake devices
# This part must be changed on real installation
#server: FAKE = DS18S20,DS2405
#
# USB device: DS9490
server: usb = all
#
# Serial port: DS9097
#server: device = /dev/ttyS1
#
# owserver tcp address
#server: server = 192.168.10.1:3131
#
# random simulated device
#server: FAKE = DS18S20,DS2405
#
######################### OWFS ##########################
#
mountpoint = /mnt/1wire
allow_other
#
####################### OWHTTPD #########################

http: port = 2121

####################### OWFTPD ##########################

ftp: port = 2120

####################### OWSERVER ########################

server: port = localhost:4304

cat /etc/fuse.conf
# Set the maximum number of FUSE mounts allowed to non-root users.
# The default is 1000.
#
#mount_max = 1000

# Allow non-root users to specify the 'allow_other' or 'allow_root'
# mount options.
#
user_allow_other

So anyone what am I missing. I should be seeing the Fob and 2 temp sensors.

Thank again.
David

Return to “Interfacing (DSI, CSI, I2C, etc.)”