4

There are loads of examples of using the ds18b20 temp probe, or even multiples all to GPIO pin 4, and then running:

modprobe w1-gpio
modprobe w1-therm
cat /sys/bus/w1/devices/28-*/w1_slave

The issue I have on my project, is I have multiple sensors in different areas (outside, floor, ceiling). I plan on having them connect to the Pi through a RJ45 connector through a simple housing. I don't want to have to track each sensor serial number separately. I would rather just query different GPIOs. Is this possible?

So is there a way to change the modprobe commands to use different/multiple GPIO ports for these one wire sensors?

6 Answers 6

3

An idea I once had for a similar problem was the following - I have no idea if it will work in this specific case, though:

Connect the data wire of all sensors to pin 4 (parallel), but the power wires to different GPIOs. Now, you can use software to turn off all power to the sensors but one (by turning off the respective GPIO digital output), then query the data wire. Do that in turn for all sensors connected.

Of course, you won't get simultaneous data from all sensors, but for temperature, you should be fine.

I hope this is clear, good luck!

2

From what I understand, it is not possible to connect any 1 wire interface type component in other than the GPIO pin 4. I've been looking into this myself and have not found a solution.

But for your solution, if you really don't want to use the 1 wire interface, you should think of another sensor, even if analog, use something like an MCP3008 and you can "talk to the pi" via serial interface and transmit analog readings.

2

You can change the default GPIO pin with an entry in /boot/cmdline.txt like this:

bcm2708.w1_gpio_pin=8
Reference - https://github.com/raspberrypi/linux/pull/457

but you can't have more than one onewire bus, as there is no support for that.

To your underlying question, you don't "query a GPIO" with onewire, unless you want to write a raw driver. The benefit of using a protocol like onewire is that the details of the messages on the w1 bus are isolated from your code by the driver and you have a simple filesystem interface.

1

There are a few advantages to running separate 1wire busses, including fault isolation, noise and other problems which can be caused by funky shaped busses (e.g. with "branches" - especially long ones).

Since a bug fix in the 4.9.28 Raspberry pi firmware image packages, it's now fairly easy to do this using device table overlays. e.g. create three busses on gpio 4, 17, 27 using device (not parasitic) power - at a root shell (or with sudo) execute the following commands to setup multiple gpio 1wire busses:

dtoverlay w1-gpio gpiopin=4 pullup=0
dtoverlay w1-gpio gpiopin=17 pullup=0
dtoverlay w1-gpio gpiopin=27 pullup=0

You can then see each device here (and you can see that there are two devices connected to bus 3) with ls -l /sys/bus/w1/devices/

10-00080257e469 -> ../../../devices/w1_bus_master3/10-00080257e469
28-02146311b1ff -> ../../../devices/w1_bus_master3/28-02146311b1ff
w1_bus_master1 -> ../../../devices/w1_bus_master1
w1_bus_master2 -> ../../../devices/w1_bus_master2
w1_bus_master3 -> ../../../devices/w1_bus_master3

... as usual, each bus will require pull-ups (and termination - especially for long busses).

Other solutions (which are likely to be more robust due to hardware differences) are to use a DS2482-800 i2c to 1Wire adaptor chip instead of gpio based busses, and/or to use logic level shifters to run the 1wire busses at 5 volts instead of the 3.3 volts which the pi gpio pins dictate.

0

You can connect the sensors to multiple gpio by recompiling the linux kernel module see here:

Or do what this video shows and use a bit banging method.

-1

You do not need to have different GPIOs, each device in your 1w bus will show up as a separate dir in /sys/bus/w1/devices/.

1
  • You failed to read the question properly.
    – goldilocks
    Commented Oct 29, 2015 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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