3

How do I force the system to detect a GPIO device has been connected or disconnected?

For instance, I'm playing with the DS18B20 temperature sensor, and I noticed that immediately after connecting it, it does not show in /sys/bus/w1/devices, it only appears after a few seconds.

When I disconnect it, it seems to take much longer (more than 10 seconds) until it finally disappears from the w1 devices list.

I'd like to know exactly how long it takes, or to force a refresh of the list of connected devices.

PS: I'm using Raspbian, in case it is relevant for the answer.

1
  • I see the same behaviour after disconnecting the sensor, it takes around 100 seconds to recognise disconnection of a sensor, new sensor is recognised almost immediately. Any solution since then?
    – Lukas
    Oct 3 '16 at 22:21
1

Wish I had a 1 wire device to test this on, but I am going to take a stab in the dark here. Does this reduce the interval time:

modprobe wire timeout=1

or add to your /etc/modules.conf:

wire timeout=1

I could not find any relevant settings in the w1_gpio module (and rightly so) and I am assuming "w1_master_timeout - the delay in seconds between searches" in the wire (w1.c) module is the right setting. You can view the current setting by running:

cat /sys/bus/w1/drivers/w1_master_driver/w1_bus_master1/w1_master_timeout
1
  • I tried doing it, but it didn't seem to help much. I tried timing more precisely the detection times: disconnection was detected after about 90 seconds, while reconnection only took about 5 seconds to be detected. The time seems to be unaffected by the value set with modprobe. Reading the current setting of the master timeout yields 10.
    – anol
    Apr 20 '14 at 16:06
1

I did experience this problem too and found an answer here:

https://www.raspberrypi.org/forums/viewtopic.php?t=117353#p980819

Add or update the following file: /etc/modprobe.d/w1.conf

options wire timeout=1 slave_ttl=3

After this reboot your Pi and then the timeout will change from 10 to 1:

cat /sys/bus/w1/drivers/w1_master_driver/w1_bus_master1/w1_master_timeout
1

Now when I remove a w1 sensor it will disappear in a matter of seconds:

# I pull out the sensor and instantly issue an `ls`
pi@thing:~$ date && ls /sys/bus/w1/devices/

# Firstly it shows up
Sun Dec 22 23:41:28 CET 2019
28-00000ff00ff0  w1_bus_master1
pi@thing:~$ date && ls /sys/bus/w1/devices/

# Two seconds later it's still here
Sun Dec 22 23:41:30 CET 2019
28-00000ff00ff0  w1_bus_master1

# 4 seconds later it's gone
pi@thing:~$ date && ls /sys/bus/w1/devices/
Sun Dec 22 23:41:32 CET 2019
w1_bus_master1
pi@thing:~$ date && ls /sys/bus/w1/devices/
1
  • Thank you. I have the same problem and I resolved by this solution. Now I'm using five DS2431. If I plug out it, it will disappear after 3 seconds. Now I'm using the following. Then it will removed after 1 second. options wire timeout=1 slave_ttl=1.
    – Hans
    yesterday

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.