User avatar
CasaDelGato
Posts: 49
Joined: Mon Jul 16, 2012 9:36 pm
Contact: Website

1-Wire setup questions.

Mon Mar 06, 2017 1:25 am

I'm going to be doing a few projects using 1-wire devices (including the DS18B20).
My searches show there are at least 2, possibly more, ways of setting up a Pi to work with 1-wire devices.
What I can't seem to find is which one is the CURRENT way to do it! Most of the articles don't have dates on them, and the ones that do don't mention what they had to do to get the Pi to talk 1-wire.
Seems like there should be a Pi 1-Wire FAQ somewhere.
Is there one?
Worlds only All Electric Ford F250

peterlite
Posts: 722
Joined: Sun Apr 17, 2016 4:00 am

Re: 1-Wire setup FAQ?

Mon Mar 06, 2017 2:42 am

From what I can see of 1 wire, there are lots of variables. For instance, a Pi can work with 5 volt or 3.3 volt while the attached device might work with only one of those voltages. Some devices have an earth return while others do not. You would need people who have worked with each variation to talk about the specifics of each variation.

User avatar
DougieLawson
Posts: 41898
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: 1-Wire setup FAQ?

Mon Mar 06, 2017 8:12 am

The current way is

Code: Select all

dtoverlay=w1-gpio
in /boot/config.txt

Read /boot/overlays/README for details of how to use that device tree overlay (changing pins, using parasitic power etc.).
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

User avatar
CasaDelGato
Posts: 49
Joined: Mon Jul 16, 2012 9:36 pm
Contact: Website

Re: 1-Wire setup FAQ?

Mon Mar 06, 2017 4:12 pm

Thank you, that is exactly what I needed.
Worlds only All Electric Ford F250

User avatar
CasaDelGato
Posts: 49
Joined: Mon Jul 16, 2012 9:36 pm
Contact: Website

Re: 1-Wire setup FAQ?

Tue Mar 07, 2017 1:53 am

Okay, digging into it more, I find that I can use w1-gpio or w1-gpio-pullup.
The only description I can find of the 2 is:
"w1-gpio
If you require the external pullup
dtoverlay=w1-gpio-pullup,gpiopin=x,pullup=y
otherwise
dtoverlay=w1-gpio-pullup,gpiopin=x"

So, does this mean that you can get by without an external pullup if you use the 1st choice?
What are the consequences?
Worlds only All Electric Ford F250

User avatar
CasaDelGato
Posts: 49
Joined: Mon Jul 16, 2012 9:36 pm
Contact: Website

Re: 1-Wire setup FAQ?

Tue Mar 07, 2017 5:37 am

Did a bunch more searching, and found this (which is more complete than what I found in my README file.):
Name: w1-gpio
Info: Configures the w1-gpio Onewire interface module.
Use this overlay if you *don't* need a GPIO to drive an external pullup.
Load: dtoverlay=w1-gpio,<param>=<val>
Params: gpiopin GPIO for I/O (default "4")

pullup Non-zero, "on", or "y" to enable the parasitic
power (2-wire, power-on-data) feature


Name: w1-gpio-pullup
Info: Configures the w1-gpio Onewire interface module.
Use this overlay if you *do* need a GPIO to drive an external pullup.
Load: dtoverlay=w1-gpio-pullup,<param>=<val>,...
Params: gpiopin GPIO for I/O (default "4")

pullup Non-zero, "on", or "y" to enable the parasitic
power (2-wire, power-on-data) feature

extpullup GPIO for external pullup (default "5")
Worlds only All Electric Ford F250

User avatar
CasaDelGato
Posts: 49
Joined: Mon Jul 16, 2012 9:36 pm
Contact: Website

Re: 1-Wire setup FAQ?

Tue Mar 07, 2017 5:40 am

AND after the above overlay handling, you use these 2 commands to enable the DB18S20 support:
sudo modprobe w1-gpio
sudo modprobe w1-therm
Worlds only All Electric Ford F250

User avatar
rpdom
Posts: 19278
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: 1-Wire setup FAQ?

Tue Mar 07, 2017 6:16 am

CasaDelGato wrote:AND after the above overlay handling, you use these 2 commands to enable the DB18S20 support:
sudo modprobe w1-gpio
sudo modprobe w1-therm
If you have "dtoverlay=w1-gpio" in place when the Pi is booted, you don't need to use either of those commands. The modules will be loaded automatically.

Regarding the pull-ups, generally you just use the basic w1-gpio and a single 4K7 resistor pulling up to 3V3. The w1-gpio-pullup option appears to mean you can connect that external resistor to another gpio pin instead of 3V3 and the driver will set that pin as output high when it wants to access the w1 bus.

User avatar
bensimmo
Posts: 5490
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: 1-Wire setup FAQ?

Tue Mar 07, 2017 6:34 am

It depends what you want to do.
The default method is wire it up
Ground to ground
+ve to 3V3
data to GPIO4 (pin7)

Then connect a 4K7 resistor between data and +ve.

Additional sensors should be placed in parallel with the first.

Then run either
sudo raspi-config and enable 1-wire in there.
Reboot.

Or do the same but from Raspberry Configuration in Setting in Pixel desktop.

Oddly it doesn't (last time I set it up) the mod probe parts you mention, why not I don't know given it needs it. That may have changed or I've not noticed and it work straight away, I forget.

That should have the basics setup.


(Of course the manual method, edit config.txt for more advanced settings for example using a different pin for data).


For python I just use
https://timofurrer.github.io/w1thermsensor/
As it does the faff for me.

User avatar
CasaDelGato
Posts: 49
Joined: Mon Jul 16, 2012 9:36 pm
Contact: Website

Re: 1-Wire setup FAQ?

Wed Mar 08, 2017 2:26 am

If you have "dtoverlay=w1-gpio" in place when the Pi is booted, you don't need to use either of those commands. The modules will be loaded automatically.
Thanks, I was just able to verify that.
Interesting that adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing.pdf shows using the modprobe commands.
That's one of the reasons that I was hoping to find a 1-wire FAQ.
Worlds only All Electric Ford F250

garynl
Posts: 7
Joined: Wed Mar 30, 2016 10:59 am

Re: 1-Wire setup questions.

Wed Mar 08, 2017 11:03 pm

I dont wish to hijack this thread, but I have been having so many problems getting a DS18B20 working with the one wire interface. I have seen it working but then it would stop after 10 or 15 minutes. I have tried different pi's (a pi1 and a pi3) wheezy, jessie, different gpiopins, different sensors. Its driving me mad, so I leave it for a couple of week then come back and start again. I tried again today. I get readings in the sys log like:

w1_master_driver w1_bus_master1: Family 0 for 00.800000000000.8c is not registered

a new one gets added every 60 secs or so (it varies). When you look in /sys/bus/w1/devices you see some of them; they disappear regularly so there is only 2 or 3 in the directory. I have seen lots of people of the forum have had this problem, but none of the solutions have worked for me.

What's different this time is there is NOTHING connected to the gpio header. Is my pi damaged?

At the moment I am using a pi1 (512MB) running the latest version of Jessie. The firmware is the latest. I can use the gpio command to change the modes and values of pins and see the changes with 'gpio readall'.

Does any one have any ideas or suggestions?

gary

User avatar
rpdom
Posts: 19278
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: 1-Wire setup questions.

Wed Mar 08, 2017 11:23 pm

garynl wrote:What's different this time is there is NOTHING connected to the gpio header. Is my pi damaged?
That's what you get when there are no devices attached. Phantom devices due to the pin floating. Either disable the drivers if you aren't using them, connect at least one device, or just put in the pull-up 4K7 resistor.

garynl
Posts: 7
Joined: Wed Mar 30, 2016 10:59 am

Re: 1-Wire setup questions.

Fri Mar 10, 2017 7:23 pm

Thanks rpdom, that's worth knowing. It was very easy to verify. I then plug in a sensor but it doesnt get detected. I've tried in normal mode (3.3V to the sensor and "dtoverlay=w1-gpio" in config.txt) and parasitic mode (no volts to the sensor and "dtoverlay=w1-gpio,pullup=1" in config.txt). I tried it with 5 different sensors with the same result.

This suggests that all the sensors are dead (but I have seen some of them work in the past) or the wiring is wrong. I have checked the wiring multiple times and cleared the breadboard and re-wired multiple times. (It's not difficult; ground on the sensor to the ground, volts to the Vcc on the sensor when not in parasitic mode, not connected otherwise. Data goes to the gpio pin but with a 4k7 ohm pullup).

Is there anyway to verify that the sensors work by some other means?

User avatar
bensimmo
Posts: 5490
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: 1-Wire setup questions.

Fri Mar 10, 2017 8:32 pm

Assuming by pullup you mean GPIO pin - 4k7 - 3v3 pin

User avatar
bensimmo
Posts: 5490
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: 1-Wire setup questions.

Fri Mar 10, 2017 8:41 pm

In parasitic mode, i believe you tie VCC and ground together at the sensor you don't leave it floating.

You also still need the 4k7 resistor from data line to a 3v3 pin.

That way you only need to run the data and GND cables.
Basically same for both except VCC on the device is connected to GND.

User avatar
rpdom
Posts: 19278
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: 1-Wire setup questions.

Fri Mar 10, 2017 9:04 pm

bensimmo wrote:In parasitic mode, i believe you tie VCC and ground together at the sensor you don't leave it floating.
You are correct.
ds18b20 datasheet wrote: (+V pin) must be grounded for operation in parasite power mode.

garynl
Posts: 7
Joined: Wed Mar 30, 2016 10:59 am

Re: 1-Wire setup questions.

Sat Mar 11, 2017 10:36 am

Aah, thanks Ben and rpdom. I missed that, but easily fixed. Just quickly tried it, but it doesn't seem to make a difference. I'll have another look when I have more time. (and maybe I should read the datasheet more carefully, instead of skimming through it).

garynl
Posts: 7
Joined: Wed Mar 30, 2016 10:59 am

Re: 1-Wire setup questions.

Sat Mar 11, 2017 9:05 pm

Found it! My sensors have 3.5mm ("stereo") jack plugs and I had expected the data signal to be on the tip based on info I found on the internet; there was no info with the sensors. When I checked the jacks, the colours of the wires suggested the tip was actually ground! A quick check with a multimeter and a rewire and the sensors started providing data! Its always the hardware, huh! ;)

Thanks for your help.

User avatar
CasaDelGato
Posts: 49
Joined: Mon Jul 16, 2012 9:36 pm
Contact: Website

Re: 1-Wire setup questions.

Sat Mar 11, 2017 10:22 pm

Where do you find the sensors with the stereo plugs? I could use some of those.
Worlds only All Electric Ford F250

garynl
Posts: 7
Joined: Wed Mar 30, 2016 10:59 am

Re: 1-Wire setup questions.

Sat Mar 11, 2017 11:10 pm

I got mine from AliExpress. There were loads of companies selling them when I got them before Christmas. Sometimes you have to buy a minimum quantity but I got 5 for €10 including post. (Locally they wanted €7 a sensor and €1.50 for a jack plug).
You should find them using a query "DS18B20 waterproof jack" though I just tried that and it only found 2 sellers.

It's a bit hard to see who you are actually buying from, but they do have a rating system (but most companies get 5 stars or close to). I would be cautious and spend only what you can afford to lose. That said, just before Christmas I bought the sensors, 5V channel relays and LED strip lighting. Everything arrived on time (but can take a month - hey some were free postage from China). The only 'problem' was a rubbish remote control for a LED strip, and temp sensors wired differently.

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