User avatar
agdyer
Posts: 4
Joined: Wed Jul 24, 2013 4:25 am

1wire: w1-gpio talking to a DS2438

Wed Jul 24, 2013 6:29 am

My first post to this forum, Hi! I have found other discussions useful.

Short version of my question: Is there documentation or examples on using the rw file to talk to arbitrary 1-wire devices?

I've successfully connected several DS18S20 temperature sensors to the 1-wire bus on GPIO-4 and used the w1-gpio and w1-therm to read them. So simple when someone's done the hard work of writing the kernel modules.

Now I'm trying to use a DS2438 with a Honeywell humidity sensor to measure humidity. I connected them up, and I can see the DS2438 in the filesystem:

Code: Select all

ls /sys/bus/w1/devices
10-0008029dbea3  26-0000016027b3  w1_bus_master1
There is no kernel module for the DS2438, so I see the generic files:

Code: Select all

ls /sys/bus/w1/devices/26-0000016027b3
driver  id  name  power  rw  subsystem  uevent
The kernel documentation says the rw file is "created for slave devices which do not have appropriate family driver. Allows to read/write binary data." but gives no more details.
I assumed that the generic driver would take care of selecting the 1-wire device I wanted to talk to (using the Match ROM command), so I could write commands and data. The DS2438 datasheet explains that, after some commands (Copy Scratchpad, Convert T, Convert V) the device returns "0" while it is busy, and "1" when it is done. How would I know when the device had finished?

After some experimentation, I found that I could read from the rw file until it gave non-zero data. So, this Perl fragment:

Code: Select all

open( DS2438, "+>/sys/bus/w1/devices/26-0000016027b3/rw")
print DS2438 "\x44";
for (my $b="\x00"; $b eq "\x00"; ) { read DS2438, $b, 1; }
print DS2438 "\xb4";
for (my $b="\x00"; $b eq "\x00"; ) { read DS2438, $b, 1; }
print DS2438 "\xb8\x00";
for (my $b="\x00"; $b eq "\x00"; ) { read DS2438, $b, 1; }
print DS2438 "\xbe\x00";
read DS2438, $data, 9;
my ($status, $t, $v, $c, $th, $crc) = unpack('CvvvCC', $data);
initiates temperature conversion, voltage conversion, recalls memory 0, reads scratchpad zero and unpacks the 9 bytes (including the CRC) it receives.

This method works (more details on my website: http://rants.dyer.com.hk/rpi/humidity_1w.html), but each wait line takes about 2 seconds (I assume I'm actually waiting for a bus timeout, rather than correctly recognising when the devices is not busy). To complete a humidity reading, including changing which voltage I'm converting, takes 26 seconds overall.

There must be a faster way, perhaps some ioctl() call for finer control of the 1wire bus? Which brings me back to the short version of my question: Is there documentation or examples on using the rw file to talk to arbitrary 1-wire devices?

Thanks for your help.

Gadgetman
Posts: 2
Joined: Mon Oct 28, 2013 8:12 pm
Location: Johannesburg, SA

Re: 1wire: w1-gpio talking to a DS2438

Mon Oct 28, 2013 8:15 pm

I am trying to do a similar thing....talking to DS2438 using the w1-gpio and w1-therm.
Did you get anywhere further?

xtrasns
Posts: 5
Joined: Fri Feb 07, 2014 5:15 pm

Re: 1wire: w1-gpio talking to a DS2438

Thu Feb 13, 2014 1:30 am

Hi !

Do you guyed know of any C libraries wher I can call "modprobe w1-gpio" and "modprobe w1-therm" from ? I have seen examples written in python, but none in C ...

koozaaa
Posts: 1
Joined: Sat Feb 13, 2016 11:29 am

Re: 1wire: w1-gpio talking to a DS2438

Sat Feb 13, 2016 11:34 am

Hi guys,
if anyone can tell what is the reason that it is not visible "power" module?

ls /sys/bus/w1/devices/26-0000016027b3
driver id name power rw subsystem uevent

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