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?