Comments on: Raspberry Pi: Temperature Readings with DS18B20 Sensor (Python) https://randomnerdtutorials.com/raspberry-pi-ds18b20-python/ Learn ESP8266, ESP32, Arduino, and Raspberry Pi Tue, 26 Mar 2024 14:58:13 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: Sara Santos https://randomnerdtutorials.com/raspberry-pi-ds18b20-python/#comment-900958 Tue, 26 Mar 2024 14:58:13 +0000 https://randomnerdtutorials.com/?p=133368#comment-900958 In reply to Alessandro.

Thanks for sharing this info.
Regards,
Sara

]]>
By: Alessandro https://randomnerdtutorials.com/raspberry-pi-ds18b20-python/#comment-900767 Mon, 25 Mar 2024 14:12:04 +0000 https://randomnerdtutorials.com/?p=133368#comment-900767 Hi,

ended up here following the comments of one of my students. Great work, I especially like the description of the hardware setup.

I think the code has a possible pitfall: when the RPi has seen two sensors of the same family, this code might return the the data of a sensor that has been removed (e.g. replaced due to damage). This is not a scenario where two sensor are on the bus, but a maintenance scenario when only one sensor is deployed.

Furthermore, for people who are just interested in getting things done, pypi.org/project/w1thermsensor/ might be a better starting point.

]]>
By: Brian https://randomnerdtutorials.com/raspberry-pi-ds18b20-python/#comment-884501 Wed, 17 Jan 2024 02:31:37 +0000 https://randomnerdtutorials.com/?p=133368#comment-884501 In reply to Mark.

I haven’t had a issue since I replaced the 4.7k ohm pull with a 2.2k I am powering my 1-wire buss with 3.3v and not parasitic.

]]>
By: Mark https://randomnerdtutorials.com/raspberry-pi-ds18b20-python/#comment-884431 Tue, 16 Jan 2024 19:17:29 +0000 https://randomnerdtutorials.com/?p=133368#comment-884431 In reply to Brian.

Did you ever figure this one out? I have the one sensor setup working fine, but would like to have 2 sensors (two aquariums).

]]>
By: Sara Santos https://randomnerdtutorials.com/raspberry-pi-ds18b20-python/#comment-883227 Wed, 10 Jan 2024 23:43:42 +0000 https://randomnerdtutorials.com/?p=133368#comment-883227 In reply to Benoit.

Hi.
Yes. I tried, but I get better results with “normal” mode.
You can try both ways and see which one works best for your scenario.
Regards,
Sara

]]>
By: Benoit https://randomnerdtutorials.com/raspberry-pi-ds18b20-python/#comment-883127 Wed, 10 Jan 2024 12:25:36 +0000 https://randomnerdtutorials.com/?p=133368#comment-883127 HI? Great job !
Are you try to use the parasite mode to supply ?
Tks

]]>
By: Brian https://randomnerdtutorials.com/raspberry-pi-ds18b20-python/#comment-874632 Tue, 28 Nov 2023 04:18:37 +0000 https://randomnerdtutorials.com/?p=133368#comment-874632 I have modified the code to read multiple sensors. The trouble is the function randomly returns a value of 85c. Any suggestions?

#!/usr/bin/python3
import os
import glob
import time
base_dir = ‘/sys/bus/w1/devices/’

os.system(‘modprobe w1-gpio’)
os.system(‘modprobe w1-therm’)

device_folder = glob.glob(base_dir + ’28‘)
NumDev=(len(glob.glob(base_dir + ’28
‘)))
#values=range(NumDev)

def read_temp_raw(device):
f = open(device, ‘r’)
lines = f.readlines()
f.close()
return lines

def read_temp(device):
global temp_c
lines = read_temp_raw(device)
while lines[0].strip()[-3:] != ‘YES’:
time.sleep(0.2)
lines = read_temp_raw()
equals_pos = lines[1].find(‘t=’)
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
temp_f = temp_c * 9.0 / 5.0 + 32.0
return temp_c, temp_f

#list comprehension
device_file = [x + ‘/w1_slave’ for x in device_folder]\

print(‘Found ‘,NumDev,’Sensors’)

for a in device_file:
print(read_temp(a))

#print(read_temp(device))

]]>