User avatar
frazelle09
Posts: 70
Joined: Mon May 07, 2012 5:04 am
Location: Mexicali, Baja California, Mexico

Need help with Raspi B and DS1820

Sat Dec 12, 2015 8:15 am

i've got this thing soldered up and connected to the Raspi with the 4.7K resistor (although this one only has the stripes gold, red and blue). Am running an updated system.

However when i go into /sys/bus/w1/devices and use ls there is nothing there. i've already run the modprobe w1-gpio and the modprobe w1-therm but to no avail.

What do i need to do to check this thing?

Have a great evening! :)
"The earth is one country and mankind its citizens."
Bahá'u'lláh
"La tierra es un sólo país y la humanidad sus ciudadanos."

User avatar
RogerW
Posts: 285
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: Need help with Raspi B and DS1820

Sat Dec 12, 2015 10:44 am

Have you added the line
dtoverlay=w1-gpio

to the file
/boot/config.txt

This code may help you:

Code: Select all

# ds18b20.py
# written by Roger Woollett

import os
import glob
import time

class DS18B20:
	# much of this code is lifted from Adafruit web site
	# This class can be used to access one or more DS18B20 temperature sensors
	# It uses OS supplied drivers and one wire support must be enabled
	# To do this add the line
	# dtoverlay=w1-gpio
	# to the end of /boot/config.txt
	#
	# The DS18B20 has three pins, looking at the flat side with the pins pointing
	# down pin 1 is on the left
	# connect pin 1 to GPIO ground
	# connect pin 2 to GPIO 4 *and* GPIO 3.3V via a 4k8 (4800 ohm) pullup resistor
	# connect pin 3 to GPIO 3.3V
	# You can connect more than one sensor to the same set of pins
	# Only one pullup resistor is required
	
	def __init__(self):
		# load required kernel modules
		os.system('modprobe w1-gpio')
		os.system('modprobe w1-therm')
		
		# Find file names for the sensor(s)
		base_dir = '/sys/bus/w1/devices/'
		device_folder = glob.glob(base_dir + '28*')
		self._num_devices = len(device_folder)
		self._device_file = list()
		i = 0
		while i < self._num_devices:
			self._device_file.append(device_folder[i] + '/w1_slave')
			i += 1
		
	def _read_temp(self,index):
		# Issue one read to one sensor
		# you should not call this directly
		f = open(self._device_file[index],'r')
		lines = f.readlines()
		f.close()
		return lines
		
	def tempC(self,index = 0):
		# call this to get the temperature in degrees C
		# detected by a sensor
		lines = self._read_temp(index)
		retries = 5
		while (lines[0].strip()[-3:] != 'YES') and (retries > 0):
			# read failed so try again
			time.sleep(0.1)
			#print('Read Failed', retries)
			lines = self._read_temp(index)
			retries -= 1
			
		if retries == 0:
			return 998
			
		equals_pos = lines[1].find('t=')
		if equals_pos != -1:
			temp = lines[1][equals_pos + 2:]			
			return float(temp)/1000
		else:
			# error
			return 999
			
	def device_count(self):
		# call this to see how many sensors have been detected
		return self._num_devices
It is a class that can read one or mor ds18b20s. You may find the comments helpful.

Put that code in the same diorectory as

Code: Select all

# Temp.py

from ds18b20 import DS18B20	
	
# test temperature sensors
x = DS18B20()
count=x.device_count()
i = 0
while i < count:
	print(x.tempC(i))
	i += 1
and you should be able to test the sensor.

User avatar
frazelle09
Posts: 70
Joined: Mon May 07, 2012 5:04 am
Location: Mexicali, Baja California, Mexico

Re: Need help with Raspi B and DS1820

Sat Dec 12, 2015 5:00 pm

RogerW - first off, Roger, thanks for replying i certainly appreciate this help.

Secondly, this is a DS1820, not a DS18b20 - so i hope this doesn't make any difference.

Thirdly - yes, we have added the line: dtoverlay=w1-gpio to the config.txt file.

Fourthly, while the DS1820 is connected to the Pi, is there any way of using my little Commercial Electric MAS830B multimeter probe to figure out if the wiring is alright? i already tried between + and - (ground) and have 3.3V. The reason i say this is i don't know if i used the proper techniques to solder the resister and DS - my techniques are from before electronics - lol.

i suspect that if we can be sure that the wiring and components are alright, we can then move on to the code.

Again, thanks for taking the time to help and have a great morning! :)
"The earth is one country and mankind its citizens."
Bahá'u'lláh
"La tierra es un sólo país y la humanidad sus ciudadanos."

User avatar
frazelle09
Posts: 70
Joined: Mon May 07, 2012 5:04 am
Location: Mexicali, Baja California, Mexico

Re: Need help with Raspi B and DS1820

Sat Dec 12, 2015 9:48 pm

After more fiddling we have under .../bus/w1/drivers/

these two subdirs> w1_master_driver and w1_slave_driver, each of which contains

bind, uevent, unbind. They appear to be files but even though i become su i still don't have permission to read them.

Have a great afternoon! :)

User avatar
rpdom
Posts: 15169
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Need help with Raspi B and DS1820

Sat Dec 12, 2015 10:00 pm

frazelle09 wrote:Secondly, this is a DS1820, not a DS18b20 - so i hope this doesn't make any difference.
I think that might be the problem. From what I've been able to find out, the DS1820 doesn't support the resolution that the Pi DS18B20 drivers require.

User avatar
frazelle09
Posts: 70
Joined: Mon May 07, 2012 5:04 am
Location: Mexicali, Baja California, Mexico

Re: Need help with Raspi B and DS1820

Sat Dec 12, 2015 10:36 pm

After a check of the net, i do see these being used, however they have been reporting errors...

viewtopic.php?t=30332&p=338214

This user has three of them connected...
viewtopic.php?f=63&t=91005

Have a super afternoon! :)

Return to “Beginners”