Matthew Moisen
Posts: 7
Joined: Fri Jun 14, 2013 6:50 am

How is DS18B20 different on RPI 3 vs RPI2 ?

Sat Oct 01, 2016 6:54 pm

I had a few Raspberry Pi 2's and had lots of issues with using DS18B20 temperature sensors. Initially they didn't work at all, and then I followed a tutorial that recommended I add certain settings to /boot/config.txt. It started to work but couldn't handle more than 1 or 2 probes. Then I searched on these forums and changed the settings again. A few months later the probes seemed to stop working, and searching the error message lead to yet another set of /boot/config.txt settings. Then I upgraded the RPI 2 and everything broke once again, and lead to a final change in the /boot/config.txt settings.

When I bought the Raspberry Pi 3, all I remember doing was plugging in the probes and everything worked just fine. Unfortunately, I don't totally remember, but I am pretty sure that I didn't have to mess around with blindly copy and pasting settings into /boot/config.txt.

I bought another RPI 3 and would like to know how the set up procedure for DS18B20s differ from the set up procedures on RPI 2. Notably, is it true that I don't have to do anything and that it will just work right out of the box? If that is the case, why is it so? Why didn't it work right out of the box with RPI 2?

User avatar
joan
Posts: 14878
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How is DS18B20 different on RPI 3 vs RPI2 ?

Sat Oct 01, 2016 6:59 pm

The DS18B20 has never worked out of the box. It has always required configuration.

Apart from correctly wiring the sensor to the Pi the only other thing you have to do is make the appropriate entry in /boot/config.txt.

Look in /boot/overlays/README for details, in particular for w1-gpio.

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

Re: How is DS18B20 different on RPI 3 vs RPI2 ?

Sat Oct 01, 2016 7:10 pm

joan wrote:The DS18B20 has never worked out of the box. It has always required configuration.
I have a feeling that one of the official images did have that line in config.txt, but it may have been taken out now.

I could be wrong, and don't fancy trawling through all the image files to check it.

User avatar
joan
Posts: 14878
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How is DS18B20 different on RPI 3 vs RPI2 ?

Sat Oct 01, 2016 7:23 pm

rpdom wrote:
joan wrote:The DS18B20 has never worked out of the box. It has always required configuration.
I have a feeling that one of the official images did have that line in config.txt, but it may have been taken out now.

I could be wrong, and don't fancy trawling through all the image files to check it.
If it wasn't commented out it would be a mistake. It's bad enough when people forget they put the line there themselves and wonder later why GPIO 4 doesn't work properly.

philipBC
Posts: 14
Joined: Fri Aug 12, 2016 1:15 pm

Re: How is DS18B20 different on RPI 3 vs RPI2 ?

Wed Oct 05, 2016 10:41 am

The latest kernel(s) and releases of Raspbian Jessie have Device Tree enabled.
The only configuration required for DS18B20 temperature probes is a line at the end of /boot/config.txt

Code: Select all

# Enable 1-wire bus on GPIO 17
dtoverlay=w1-gpio,gpiopin=17
Do yourself a favour and add a comment too, so you remember why this line is here.
If you miss out the gpiopin=17 bit then the driver will use the default pin which is GPIO4.

You can use raspi-config to enable the 1-wire bus which just adds

Code: Select all

dtoverlay=w1-gpio
with no comment or explanation.

If your wiring is right then you will then find your device in the folder /sys/bus/w1/devices

Code: Select all

pi@RASP:/ $ ls /sys/bus/w1/devices
28-8000000476a4  w1_bus_master1
and you can read the raw data provided by the kernel loaded driver ...

Code: Select all

pi@RASP:/ $ cat /sys/bus/w1/devices/28-8000000476a4/w1_slave
4f 01 ff ff 7f ff ff ff 45 : crc=45 YES
4f 01 ff ff 7f ff ff ff 45 t=20937
There are a number of code libraries that will decipher the w1_slave file for you, but i prefer to read it directly.
I have some examples written in nodejs if anyone is interested.

IcarusR
Posts: 1
Joined: Tue Feb 10, 2015 10:57 pm

Re: How is DS18B20 different on RPI 3 vs RPI2 ?

Sat May 06, 2017 7:21 pm

philipBC wrote:The latest kernel(s) and releases of Raspbian Jessie have Device Tree enabled.
The only configuration required for DS18B20 temperature probes is a line at the end of /boot/config.txt

Code: Select all

# Enable 1-wire bus on GPIO 17
dtoverlay=w1-gpio,gpiopin=17
Do yourself a favour and add a comment too, so you remember why this line is here.
If you miss out the gpiopin=17 bit then the driver will use the default pin which is GPIO4.

You can use raspi-config to enable the 1-wire bus which just adds

Code: Select all

dtoverlay=w1-gpio
with no comment or explanation.

If your wiring is right then you will then find your device in the folder /sys/bus/w1/devices

Code: Select all

pi@RASP:/ $ ls /sys/bus/w1/devices
28-8000000476a4  w1_bus_master1
and you can read the raw data provided by the kernel loaded driver ...

Code: Select all

pi@RASP:/ $ cat /sys/bus/w1/devices/28-8000000476a4/w1_slave
4f 01 ff ff 7f ff ff ff 45 : crc=45 YES
4f 01 ff ff 7f ff ff ff 45 t=20937
There are a number of code libraries that will decipher the w1_slave file for you, but i prefer to read it directly.
I have some examples written in nodejs if anyone is interested.
This no longer works, at least not for me. Raspbain Jessie latest. Kernel 4.9.24-v7+

Can not get DS18B20 to work on alternative gpio what ever I do.

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

Re: How is DS18B20 different on RPI 3 vs RPI2 ?

Sun May 07, 2017 6:29 am

Fire it up as a new topic with the 4.9 in the title. See if other see the same as it's not really related to Pi2 Vs Pi3 from last year.

You should now be able to use more than one GPIO pin at a time as I'm sure they did some work on that a while back.
Though post if it works from the default port when you just enable it in raspi-config.

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

Re: How is DS18B20 different on RPI 3 vs RPI2 ?

Sun May 07, 2017 8:33 am

IcarusR wrote:This no longer works, at least not for me. Raspbain Jessie latest. Kernel 4.9.24-v7+

Can not get DS18B20 to work on alternative gpio what ever I do.
I've just installed the 4.9.24-v7+ kernel on a Pi 3B using rpi-update and I don't have any problems with using a DS18B20 on an alternate GPIO.

In my config.txt I've got:

Code: Select all

# Enable w1 driver
dtoverlay=w1-gpio,gpiopin=17
I connected the sensor and resistor as follows:
+V Pin 1
GND Pin 6
Data Pin 11 (GPIO 17)
4K7 resistor between +V and Data

The device shows up as /sys/bus/w1/devices/28-0316852f6eff and gives a sane reading

Code: Select all

cat /sys/bus/w1/devices/28-0316852f6eff/w1_slave
2d 01 4b 46 7f ff 0c 10 21 : crc=21 YES
2d 01 4b 46 7f ff 0c 10 21 t=18812
I used rpi-update bbd611a2289947e593ebd9071cd60f9a26d8f80c to pull in the 4.9.24 kernel and firmware (the current one is a 4.9.25 kernel).

Code: Select all

cat /boot/.firmware_revision
bbd611a2289947e593ebd9071cd60f9a26d8f80c
Is your setup different to this? Are you using a different firmware_revision? Which physical pins are you connecting your sensor to and what have you got in your config.txt?

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

Re: How is DS18B20 different on RPI 3 vs RPI2 ?

Sun May 07, 2017 11:36 am

rpdom wrote:
IcarusR wrote:This no longer works, at least not for me. Raspbain Jessie latest. Kernel 4.9.24-v7+

Can not get DS18B20 to work on alternative gpio what ever I do.
I've just installed the 4.9.24-v7+ kernel on a Pi 3B using rpi-update and I don't have any problems with using a DS18B20 on an alternate GPIO.

In my config.txt I've got:

Code: Select all

# Enable w1 driver
dtoverlay=w1-gpio,gpiopin=17
I connected the sensor and resistor as follows:
+V Pin 1
GND Pin 6
Data Pin 11 (GPIO 17)
4K7 resistor between +V and Data

The device shows up as /sys/bus/w1/devices/28-0316852f6eff and gives a sane reading

Code: Select all

cat /sys/bus/w1/devices/28-0316852f6eff/w1_slave
2d 01 4b 46 7f ff 0c 10 21 : crc=21 YES
2d 01 4b 46 7f ff 0c 10 21 t=18812
I used rpi-update bbd611a2289947e593ebd9071cd60f9a26d8f80c to pull in the 4.9.24 kernel and firmware (the current one is a 4.9.25 kernel).

Code: Select all

cat /boot/.firmware_revision
bbd611a2289947e593ebd9071cd60f9a26d8f80c
Is your setup different to this? Are you using a different firmware_revision? Which physical pins are you connecting your sensor to and what have you got in your config.txt?
I assume the op is not using rpi-update as the latest default is 4.9.24 (just so the op knows not to run rpi-update)

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

Re: How is DS18B20 different on RPI 3 vs RPI2 ?

Sun May 07, 2017 1:10 pm

bensimmo wrote:I assume the op is not using rpi-update as the latest default is 4.9.24 (just so the op knows not to run rpi-update)
Hmm, it is, isn't it. I didn't realise we were on that version yet, I thought it was an earlier one. I don't recommend running rpi-update unless you really know what you are doing. I don't even run it myself. That was the first time in a few years that I've done so.

Still, the DS18B20 stuff works on both versions.

Return to “General discussion”