1-Wire (owfs) working via gpio under Ubuntu; mysteries remain...

643 views
Skip to first unread message

Loren Amelang

unread,
Mar 22, 2014, 12:22:38 AM3/22/14
to beagl...@googlegroups.com
I've installed owfs and can read DS18B20 temperatures via 1-Wire on my A5C BBB with Ubuntu 12.04 - even over the web! 

The dts overlay loads at startup:
---
[  760.176601] bone-capemgr bone_capemgr.9: part_number 'w1', version 'N/A'
[  760.176888] bone-capemgr bone_capemgr.9: slot #7: 'Override Board Name,00A0,Override Manuf,w1'
[  760.181051] bone-capemgr bone_capemgr.9: slot #7: Requesting part number/version based 'w1-00A0.dtbo
[  760.181119] bone-capemgr bone_capemgr.9: slot #7: Requesting firmware 'w1-00A0.dtbo' for board-name 'Override Board Name', version '00A0'
[  760.189259] bone-capemgr bone_capemgr.9: slot #7: dtbo 'w1-00A0.dtbo' loaded; converting to live tree
---

And the owfs modules load:
---
 * Starting 1-Wire FTP server owftpd        [ OK ]
 * Starting 1-Wire HTTP Daemon owhttpd        [ OK ]
 * Starting 1-Wire TCP Server owserver        [ OK ]
---

And they show up in ps:
---
root       469     1  0 21:20 ?        00:00:00 /usr/bin/owftpd -c /etc/owfs.conf
root       521     1  0 21:20 ?        00:00:00 /usr/bin/owhttpd -c /etc/owfs.conf
root       549     1  0 21:20 ?        00:00:00 /usr/bin/owserver -c /etc/owfs.conf
---
Note they were called with the config file /etc/owfs.conf...  

I can start the 1-Wire access to gpio 45:
---
--> Verify HDMI disabled:
ubuntu@ubuntu-armhf:~$ cat /sys/devices/bone_capemgr.9/slots
...
 5: ff:P-O-- Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
 6: ff:P-O-- Bone-Black-HDMIN,00A0,Texas Instrument,BB-BONELT-HDMIN
-->     no L on HDMI slots

--> The sudo and sh tricks don't work for me; full su is required:
ubuntu@ubuntu-armhf:~$ su
Password:
root@ubuntu-armhf:/home/ubuntu# echo w1 >/sys/devices/bone_capemgr.9/slots
---
The 1-Wire activity on GPIO45 P8_11 is instantly active.

Verifying device tree override:
---
ubuntu@ubuntu-armhf:~$ cat /sys/devices/bone_capemgr.9/slots
...
 7: ff:P-O-L Override Board Name,00A0,Override Manuf,w1
---


I can try to read temperature; using the default GPIO pullup, or anything over 5K ohms:
---
ubuntu@ubuntu-armhf:~$ cat /sys/devices/w1_bus_master1/28-000000884d88/w1_slave
50 05 4b 46 7f ff 0c 10 1c : crc=1c YES
50 05 4b 46 7f ff 0c 10 1c t=85000
---
It has accurately read the ID of my 1-Wire chip, but the temperature reading is always 85C - the default value when the 18B20 chip has not been told to make a conversion, or has not been given enough time or power to complete it. 

With the 4.7K pullup that most sites seem to recommend, I get a different but stable value:
---
ubuntu@ubuntu-armhf:~$ cat /sys/devices/w1_bus_master1/28-000000884d88/w1_slave
ff 07 4b 46 7f ff 01 10 2f : crc=2f YES
ff 07 4b 46 7f ff 01 10 2f t=127937
---

Clipping my 4.7K and 10K resistors in parallel for 3197 ohms, I get real temperatures!
---
ubuntu@ubuntu-armhf:~$ cat /sys/devices/w1_bus_master1/28-000000884d88/w1_slave
e5 01 4b 46 7f ff 0b 10 be : crc=be YES
e5 01 4b 46 7f ff 0b 10 be t=30312
---


There are several threads on the web saying the default time allowed between the setup of the 18B20 conversion and the attempt to read it is too short. The times they quote don't match what I see at all. On my scope the full read takes just over 20 mS, with a pause from the 0.5 mS point to about 4 mS; the individual pulses are roughly 5 or 25 uS. Since the quoted conversion time for the 18B20 at 12 bits is 750 mS, that 3.5 mS pause can't be the conversion. The software must read the chip first, and then request the conversion to take place during the interval between reads, which by default is ten seconds. 

I suspect the reports I found were on the edge of not enough pullup rather than not enough conversion time, but I'd like to explore further. With a reading only once every ten seconds, it is hard to debug this issue using my ancient analog scope, so I want to increase the read frequency. 

-----
An OWFS configuration file is specified on the command line:
owfs -c config_file [other options]
The file name is arbitrary, there is no default configuration file used.
-----

I added "timeout_volatile 1" to /etc/owfs.conf, and now my owserver shows the new value:
-----
volatile 1 CHANGE
-----

But the actual readings on GPIO45 are still at the 10 second default value. Here's the interesting part - all of the owfs documentation says the default value is 15 seconds, not 10! It looks like the BBB implementation is ignoring both the standard default 15 and my new timeout_volatile of 1 second. What controls BBB w1 timing? 


Everything I read about generic owfs says you must choose one or more of TTY, USB, I2C, address:port, FAKE, or TESTER. None of those seem appropriate for my BBB installation, which seems to be referred to as "w1" or "w1_bus_master1". My owfs is obviously reading the device ID and the temperature from my 1-Wire chip, but the owserver is not reporting it to the web interface. 

Turns out editing /etc/owfs.conf to include:
-----
! server: FAKE = DS18S20,DS2405
server: usb = all
server: w1
-----
will make the actual w1 (that's w<one>, not w<ell>) readings show up in owserver and owhttpd. (And allow for use of USB adapters simultaneously.) But the FAKE bus devices still show up for me even though they are commented! They don't show in the filesystem, so the owserver must be making them up. 

I wasted a huge amount of time on that issue, because all the web instructions say you can just 
/etc/init.d/owserver restart
to test your changes. That command does indeed report that it has restarted the server, BUT IT DOES NOT USE THE CHANGED CONFIG FILE! When I finally tried shutdown -r, (and the correct conf edits!) my owserver connected to my hardware properly. 


I did not, however try this full sequence of kill/umount/restart:
[Modified with what I think would be the BBB file locations, but I haven't tried this!]
[I'm NOT sure how to add the "w1" hardware alongside the -u USB hardware! Anyone??]
-----
If you are talking specifically about owfs (the file system), you kill 
owfs, then umount the directory, then restart. Works well. 

#owfs start 
sudo /usr/bin/owfs -m /sys/devices/w1_bus_master1 -u --allow_other 

#owfs cleanup 
sudo killall owfs 
sudo umount /sys/devices/w1_bus_master1

#owfs restart 
sudo /usr/bin/owfs -m /sys/devices/w1_bus_master1 -u --allow_other 
-----

The visible file system mounted part of "owfs" is volatile, so if it had never been started, it should not be visible. Mine clearly is alive and functioning. Maybe "running owfs" simply means mounting that volatile structure, and no process remains active? 

Somehow my hardware is not responding to the read timing setting it looks like I've successfully changed. Hopefully someone will be able to suggest what I'm missing. 



Solved mysteries, for reference...


(Disabling the HDMI device tree entries to make space for w1)

So far dynamically removing device tree entries is not working. 
You must disable them at boot time, via (in uEnv.txt):
optargs=capemgr.disable_partno=BB-BONELT-HDMI,BB-BONELT-HDMIN 

Restart the BBB and verify HDMI is disabled:
---
ubuntu@ubuntu-armhf:~$ cat /sys/devices/bone_capemgr.9/slots
 0: 54:PF---
 1: 55:PF---
 2: 56:PF---
 3: 57:PF---
 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
 5: ff:P-O-- Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
 6: ff:P-O-- Bone-Black-HDMIN,00A0,Texas Instrument,BB-BONELT-HDMIN
-->     no L on HDMI slots
---


(Hardware connection)

The default data pin on the BBB is P8_11. I have my 18B20 sensor connected from there to ground, using the default BBB internal pullup, or added pullup to 3.3 volts, in the normal "1-Wire" (plus ground) configuration. 

P8_11 is GPIO1_13 on the BBB schematic. 
--> To get to the GPIO number that should be exported from the kernel, we must add 32 to each GPIO (64 for gpio2, and 96 for gpio3). Therefore gpio1[13] = 32 + 13 = 45.


(Installing owfs)

---
ubuntu@ubuntu-armhf:/var/www$ sudo apt-get install owfs
...
Creating config file /etc/owfs.conf with new version
Setting up owfs-fuse (2.8p13+dfsg1-5build1) ...
Setting up owserver (2.8p13+dfsg1-5build1) ...
 * Starting 1-Wire TCP Server owserver
   ...done.
Setting up owhttpd (2.8p13+dfsg1-5build1) ...
 * Starting 1-Wire HTTP Daemon owhttpd
   ...done.
Setting up owftpd (2.8p13+dfsg1-5build1) ...
 * Starting 1-Wire FTP server owftpd
   ...done.
Setting up owfs (2.8p13+dfsg1-5build1) ...
...
---
Installation should also include editing the /etc/owfs.conf file to match your hardware. But you can test the readings by displaying the 
cat /sys/devices/w1_bus_master1/<your device ID>/w1_slave
file without having a proper conf file. 

Editing /etc/owfs.conf to include:
-----
! server: FAKE = DS18S20,DS2405
server: usb = all
server: w1
-----
will make the actual w1 (that's w<one>, not w<ell>) readings show up in owserver and owhttpd. (And allow for use of USB adapters simultaneously.) But the FAKE bus devices still show up even though they are commented! 


(Compiling the device tree overlay)

---
ubuntu@ubuntu-armhf:~$ dtc -O dtb -o w1-00A0.dtbo -b 0 -@ w1.dts
dtc: invalid option -- '@'
ubuntu@ubuntu-armhf:~$ dtc -O dtb -o w1-00A0.dtbo -b 0  w1.dts
DTC: dts->dtb  on file "w1.dts"
Error: w1.dts:12.2-8 syntax error
FATAL ERROR: Unable to parse input tree
ubuntu@ubuntu-armhf:~$ 
--
Guess I need the patched dtc...

To enable/disable the GPIOs without recompiling the bootloader device tree you need the @ option in dtc. This is included in current Angstrom versions. For Ubuntu you may either compile the file on Angstrom, and copy it across, or use Robert Nelson's patched dtc. 

I've seen several .dts files for 1-Wire, but they do basically the same thing, just with different names. I've also seen other dtc patching scripts, but the others are not as thorough in checking for possible problems as the Robert C Nelson version. 

RCN device tree compiler clues:

[I grabbed a version of the script via Windows, and it ended up with CRLF line endings. 
If you see:
/bin/sh: 0: Illegal option -
you need to convert to Linux line endings!]

---
ubuntu@ubuntu-armhf:~$ chmod +x dtc.sh 
ubuntu@ubuntu-armhf:~$ ./dtc.sh
Installing: bison flex git-core
...
[amazing script runs]
...
---

The repo version of device-tree-compiler will install it to: 
/usr/bin/dtc 
The script installs it to: 
/usr/local/bin/dtc 
such that they will not collide.. 

When you go to use it, be sure you call it from the proper directory! 
---
ubuntu@ubuntu-armhf:~$ /usr/local/bin/dtc -O dtb -o w1-00A0.dtbo -b 0 -@ w1.dts
---


(Installing the device tree overlay)

Until you automate this, you will need to repeat it on every boot...
---
ubuntu@ubuntu-armhf:~$ sudo echo w1 >/sys/devices/bone_capemgr.9/slots
-bash: /sys/devices/bone_capemgr.9/slots: Permission denied
ubuntu@ubuntu-armhf:~$ sudo sh -c echo w1 >/sys/devices/bone_capemgr.9/slots
-bash: /sys/devices/bone_capemgr.9/slots: Permission denied
---

The sudo and sh -c tricks failed, I needed real root (and continue to need it):
---
ubuntu@ubuntu-armhf:~$ su
Password:
root@ubuntu-armhf:/home/ubuntu# echo w1 >/sys/devices/bone_capemgr.9/slots
root@ubuntu-armhf:/home/ubuntu# cat /sys/devices/bone_capemgr.9/slots
 0: 54:PF---
 1: 55:PF---
 2: 56:PF---
 3: 57:PF---
 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
 5: ff:P-O-- Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
 6: ff:P-O-- Bone-Black-HDMIN,00A0,Texas Instrument,BB-BONELT-HDMIN
 7: ff:P-O-L Override Board Name,00A0,Override Manuf,w1
root@ubuntu-armhf:/home/ubuntu# cat /sys/kernel/debug/gpio
GPIOs 0-31, gpio:
 gpio-6   (mmc_cd              ) in  lo

GPIOs 32-63, gpio:
 gpio-45  (w1                  ) in  hi
...
---

 
(Controlling owserver)

I'm starting owserver with a shell script /etc/init.d/owserver, 
and using /etc/owfs.conf.

Start/stop/restart apparently works - but it will NOT respond to a changed conf file:
---
ubuntu@ubuntu-armhf:~$ /etc/init.d/owserver
Usage: /etc/init.d/owserver {start|stop|restart|force-reload|status}
ubuntu@ubuntu-armhf:~$ /etc/init.d/owserver status
 * owserver is running
ubuntu@ubuntu-armhf:~$ /etc/init.d/owserver status force-reload
 * Restarting 1-Wire TCP Server owserver        [ OK ]
---

Server is alive at <http://localhost:2121/> and seems controllable via http. But the timing changes don't affect my hardware!


If you're searching for more information about the owfs on BBB, include the terms TI and OMAP in your search. The OWFS developers think of us as a branch of the OMAP kernel module, which is officially supported though it hasn't made its way into much of the documentation. 

Reply all
Reply to author
Forward
0 new messages