Getting 85C/185F readings with DS18B20 sensor at lower temperatures

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
rpi_nerd
Posts: 35
Joined: Sat Jul 29, 2017 2:05 pm

Getting 85C/185F readings with DS18B20 sensor at lower temperatures

Post by rpi_nerd » Thu Jun 16, 2022 9:27 pm

For some strange reason, when the temperature gets around -24C/-12F (monitoring the temperature of a freezer) I occasionally get an invalid 85C/185F reading (happens around every handful or so of hours.) I originally believed it to be an issue with the cable I made up, so I made another assembly with another sensor and have the exact same issue. here's the code below:

Code: Select all

def go():
	import time
	import machine
	import urequests
	import network
	import onewire, ds18x20
	sta_if = network.WLAN(network.STA_IF)

	
	dat = machine.Pin(12)
	ds = ds18x20.DS18X20(onewire.OneWire(dat))
	roms = ds.scan()

	time.sleep(2)

	

	def send_data():
		url = 'http:/[web server address]/rsensor_ds18b20_e.php'
		headerd = {'Content-Type': 'application/x-www-form-urlencoded'}
		jsons = "data=" + str(ds18b20temp_f)
		if sta_if.isconnected() == True:	
			try:
				r = urequests.post(url, data=jsons, headers= headerd)
				r.close()
			except OSError:
				pass
	while True:
		ds.convert_temp()
		time.sleep(15)
		ds18b20temp_c=ds.read_temp(roms[0])
		ds18b20temp_f=ds18b20temp_c * 9.0/5.0 +32
		send_data()
	

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Getting 85C/185F readings with DS18B20 sensor at lower temperatures

Post by davef » Thu Jun 16, 2022 10:28 pm

It is a common problem, although it is one I haven't had.

Maybe try to catch the error:

Code: Select all

     #  read 1-wire room temperature
        try:
            ds1.convert_temp()
        except onewire.OneWireError as error:
            try:
                with open('errors.txt', 'a') as outfile:
                    outfile.write('room temp ' + str(error) + '\n')
            except OSError:
                pass

        utime.sleep_ms(1000) #  min of 750ms for 1wire conversion
Also, the normal wait time after the conversion is 750ms, you are waiting 15 seconds.

rpi_nerd
Posts: 35
Joined: Sat Jul 29, 2017 2:05 pm

Re: Getting 85C/185F readings with DS18B20 sensor at lower temperatures

Post by rpi_nerd » Fri Jun 17, 2022 1:10 am

Will try and see if that helps, thanks. The reason for the extra delay time is that I wanted the frequency of the updates to be approximately every 15 seconds vs 750ms.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Getting 85C/185F readings with DS18B20 sensor at lower temperatures

Post by davef » Fri Jun 17, 2022 2:40 am

I just wondered what happens if you wait too long? Where did you buy your DS18b20s?

Good luck!

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Getting 85C/185F readings with DS18B20 sensor at lower temperatures

Post by Roberthh » Fri Jun 17, 2022 6:02 am

85C is the 'error' value of the sensor.

JumpZero
Posts: 54
Joined: Mon Oct 30, 2017 5:54 am
Location: Arcachon - France

Re: Getting 85C/185F readings with DS18B20 sensor at lower temperatures

Post by JumpZero » Fri Jun 17, 2022 12:26 pm

It's been over 10 years that I use DS18B20 mainly with OWFS but also Lua-NodeMcu and MicroPython, on different hardwares: ESP8266, ESP32 and raspberry pi's.
And I still receive a random invalid 85°C (an error code actually).
For sure a clean wiring (follow Maxim recommendations ) will clear most of these errors.
I can have 1 or 2 (may be a little more sometimes) daily with a reading every 5 minutes.
So I just filter by software and reject these.

Post Reply