0
pi@raspberrypi:~/Desktop/iot $ sudo modprobe w1-gpio
pi@raspberrypi:~/Desktop/iot $ sudo modprobe w1-therm
pi@raspberrypi:~/Desktop/iot $ cd /sys/bus/w1/devices
pi@raspberrypi:/sys/bus/w1/devices $ ls
00-280000000000  00-c80000000000  w1_bus_master1
pi@raspberrypi:/sys/bus/w1/devices $ ls -l
total 0
lrwxrwxrwx 1 root root 0 May 21 06:51 00-280000000000 -> ../../../devices/w1_bus_master1/00-280000000000
lrwxrwxrwx 1 root root 0 May 21 06:37 w1_bus_master1 -> ../../../devices/w1_bus_master1


pi@raspberrypi:~/Desktop/iot $ sudo python 7_temperature.py
Traceback (most recent call last):
  File "7_temperature.py", line 9, in <module>
    device_folder = glob.glob(base_dir + '28*')[0]
IndexError: list index out of range
  • 1
    After editing your post so a human can read it, I see the line base_dir + '28*' ... there's nothing in the folder with the name starting with 28* - perhaps it should be 00-28* – Jaromanda X May 21 '16 at 7:52
  • Welcome to Raspberry Pi! Please take the tour and visit the helpcenter. – Ghanima May 21 '16 at 9:04
1

There is no DS18B20 connected to the 1-wire bus.

You should be using device tree now rather than modprobing. See /boot/overlays/README for details.

When you connect the DS18B20 correctly the following code will give a reading.

#!/usr/bin/env python

import glob
import time

# DS18B20.py
# 2016-04-25
# Public Domain

# Typical reading
# 73 01 4b 46 7f ff 0d 10 41 : crc=41 YES
# 73 01 4b 46 7f ff 0d 10 41 t=23187

while True:

   for sensor in glob.glob("/sys/bus/w1/devices/28-00*/w1_slave"):
      id = sensor.split("/")[5]

      try:
         f = open(sensor, "r")
         data = f.read()
         f.close()
         if "YES" in data:
            (discard, sep, reading) = data.partition(' t=')
            t = float(reading) / 1000.0
            print("{} {:.1f}".format(id, t))
         else:
            print("999.9")

      except:
         pass

   time.sleep(3.0)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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