Using 1-Wire DS18B20+PAR Sensors In Parasitic Mode on RasPi with Custom GPIO Pin

Using 1-Wire DS18B20+PAR Sensors In Parasitic Mode on RasPi with Custom GPIO Pin

Wow, that’s a mouthful. But yes, Folks, it can be done.

All of it. Although Google would have you thinking otherwise, there really isn’t too much to it. Like all things geek – Señor Diablo is in the details. Let’s look at these items in chunks.  If you’ve followed Adafruits write-up then you’re heading into non-parasitic mode territory.  That write-up is great for the prep work but we’ll veer off course here.

Parasitic Mode


This really shouldn’t be this hard. Arduino makes this seem like child’s play. RasPi – not so much. If you come from Arduino and DS18B20+PAR in parasitic mode and you can’t get it working in your RasPi, this is the magic you’re missing… and it sucks that it’s so simple.

First a little background on parasitic mode. The DS18B20+PAR we’re talking about here is a three-pin TO-92 package with GND, DQ and VDD pins as pins 1, 2 & 3 respectively. Just about every write up for this sensor on RasPi talks about wiring it up as a three-wire circuit. That’s easy enough, ground it, shock it and poll it with a GPIO pin. But if, like me, you have an existing two-wire bus (aka Parasitic Mode) already installed, what do you do? You already have VDD and GND shorted, and you hooked up DQ to GPIO 4 on the RasPi, and you have a 4K7Ω pullup resistor in place (or better yet – a 5KΩ potentiometer, trust me on this one) but the darn sensor only returns 85000. Yep. This sucks. Now what?

Very little as it turns out. Nothing to the infrastructure you’re already wired out with. The changes occur at the RasPi and the commands are just simple additions to the Adafruit write-up.

When you’re testing, instead of:

pi@pi-squared ~ $ sudo modprobe w1-gpio
pi@pi-squared ~ $ sudo modprobe w1-therm
pi@pi-squared ~ $ cat /sys/bus/w1/devices/28-0000051011af/w1_slave
c6 01 4b 46 7f ff 0a 10 17 : crc=17 YES
c6 01 4b 46 7f ff 0a 10 17 t=85000

Use this:

pi@pi-squared ~ $ sudo modprobe w1-gpio pullup=1
pi@pi-squared ~ $ sudo modprobe w1-therm strong_pullup=1
pi@pi-squared ~ $ cat /sys/bus/w1/devices/28-0000051011af/w1_slave
c6 01 4b 46 7f ff 0a 10 17 : crc=17 YES
c6 01 4b 46 7f ff 0a 10 17 t=28375

And there you have it. Parasitic mode – all with two little operators added to the same modprobe commands.

Changing GPIO Pins

More stupid stuff here, too.  Back in Arduino you can change a pin by swapping out the current pin number for another.  Easy as Arduino Pi.  RasPi, difficult as usual.

Here’s the thing.  GPIO libraries are made up of multiple files.  You can follow endless threads telling you to edit w1-gpio.c or other surgical coding experiments that may actually mess other things up.  Ask me how I know.  All of this on top of the GPIO library not referencing the pins by their assigned header humber.  Perfect.  So pin 7 is GPIO pin 4 and pin 11 is GPIO pin 17?  Ohhh, that’s fucking great.  Maybe it’s because of the metric system…

Back on track here, here’s how to do it.  Edit /boot/cmdline.txt.  This is easy.

pi@pi-squared ~ $ sudo nano /boot/cmdline.txt

In NANO, arrow over to the end of the line. After “rootwait” add a space and then enter “bcm2708.w1_gpio_pin=XX” where XX = the GPIO pin number (not the header pincmdline number). I changed mine to 17.

Obviously don’t enter the quotes. Ctl-X, Yes, Enter, Reboot.

And there you have it! DS18B20+PAR actually in parasitic mode, on a RasPi, not using GPIO 4. How about that?


  1. Harald

    Hi Jason,
    thanks, that really works!

    However, I’d like to access the temps through OWFS, but this seems to fail. Any tricks to make that work?

  2. why the 5k pot in place of the resistor? It works for me with neither – this was going to be the last piece I hooked up but the sensor was already registering! With or without the resistor or pot the temperature readings work fine and there seems to be no difference in value. Curious to see your thoughts on this. Btw – thanks for writing this up, I was looking for general parasitic power info trying to accomplish this exact setup but instead found it already completed 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *