The Green Shed

Dallas 18B20 Temp Sensors on an RPi2

May 20, 2015

I’ve have a handful of Raspberry Pis around, and several of them have Dallas 18B20 temperature sensors connected for data collection. Up to this point I’ve used all of them in 3-wire mode (Vcc, Data, Ground).

I just recieved my first Raspberry Pi 2 yesterday, and went to connect it to a network of 4 sensors to replace an Arduino I was previously using.

I ran into a few snags. Here are my notes:

1. Device Tree vs Modprobe

The old way to get this all working was to setup the modules to load, either after boot via sudo modprobe w1-gpio etc, or setting those up to load on boot.

The new way to do this is via Device Tree. You can read all about the changes here. The changes are myriad, as are the reasons behind them.

In any case, to get things working I added this to my /boot/config.txt:

dtoverlay=w1-gpio,gpiopin=17,pullup=on

2. Using parasitic mode without an external pull-up resistor just didn’t work.

In 3-wire mode I’ve never needed to use an external pull-up resistor to get things to work on the RPi. That wasn’t the case with the parasitic mode. I had to use a 4.7k pull-up.

3. The built-in kernel driver only supports loading the 1-wire bus on a single pin at a time.

I had 4 sensors, and I had hoped to run 4 separate networks. My experience has been that more networks is typically more reliable than many sensors on a single network.

At this time, that isn’t possible without compiling your own kernel. I had to wire all 4 of my sensors together into a single star-network. Thankfully, the sensors have proven to be reliably pinged so far.

4. A few references that were helpful for me.

https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=65137

https://www.kernel.org/doc/Documentation/w1/w1.generic

https://superpiboy.files.wordpress.com/2014/07/raspberry-pi-rev2-gpio-pinout.jpg

https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README

https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=97314

https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=98407

https://github.com/raspberrypi/firmware/issues/348

https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=97216&sid=4a4e0a6dcf11c1dbdf8c60552f75f11d&start=50

https://github.com/raspberrypi/firmware/issues/338#issuecomment-71920412

http://wiringpi.com/