0

I have temperature sensor (DS18B20), also known as a 'one-wire sensor'. I've connected it to pin 4. I am using this code that someone wrote (source).

#!/usr/bin/env python

import time
DS18B20="/sys/bus/w1/devices/28-000005d34cd2/w1_slave"

r = 0

while True:

   r += 1

   f = open(DS18B20, "r")
   data = f.read()
   f.close()

   (discard, sep, reading) = data.partition(' t=')

   t = float(reading) / 1000.0

   print("{} {:.1f}".format(r, t))

   time.sleep(3.0)

It works as it should. But everytime I reboot the Pi I have to setup the sensor by using : modprobe w1-gpio and modprobe w1-therm. I want the Pi to do this automatically while booting up (or in the python script above). How can I do this?

2 Answers 2

3

Add the following lines to /etc/modules

w1-gpio
w1-therm

You'll need root privileges to do so (e.g. sudo vi /etc/modules or sudo nano /etc/modules).

0

Additionally, you will also need to add the following line to /boot/config.txt

dtoverlay=w1-gpio,gpiopin=4

Your Answer

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

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