BrewSteve
Posts: 5
Joined: Sat Jun 01, 2019 8:20 am

DS18B20 resolution

Sat Jun 01, 2019 8:57 am

Hi
I have 6 DS18b20 sensors connected to my Pi3 sitting in an insulated box in my lounge. It is set up to provide a reasonable calibration environment (short of a stirred waterbath). Temperatures change slowly and I am sampling at 10 minute intervals. Results are good, with most sensors tracking OK, and one offset. There are two with bigger jumps in the temperature change:
Image

Dont think that image has loaded!

It appears that 2 probes have a resolution of 0.25 C and the others 0.062 C. The 2 outlier probes are from the same batch as 4 others (my purchase batch that is). My reading is that the drivers control the resolution so this should be the same for all probes. My code is here

Code: Select all

#Multiple sensors
#With the get_available_sensors class-method you can get the ids of all available sensors.
#https://timofurrer.github.io/w1thermsensor/
#http://raspberrywebserver.com/cgiscripting/rpi-temperature-logger/building-an-sqlite-temperature-logger.html

from w1thermsensor import W1ThermSensor
import datetime
import time
import sqlite3

# store the temperature in the database


def log_temperature(myTimeStamp,sensid,temperature):

    conn=sqlite3.connect('DataLogger')
    curs=conn.cursor()
    curs.execute("INSERT INTO SensorData values((?), (?), (?))", (myTimeStamp,str(sensid),temperature))
    #curs.execute("INSERT INTO SensorData values("myTimeStamp","sensid","temperature");)

    # commit the changes
    conn.commit()

    #conn.close()

while True:
	myTimeStamp = datetime.datetime.now()
	print("sensor log loop running")

	for sensor in W1ThermSensor.get_available_sensors():
		#print("Sensor %s has temperature %.2f" % (sensor.id, sensor.get_temperature()))
		temperature=sensor.get_temperature()
		sensid=sensor.id

Any suggestions as to why 2 probes should have a different resolution? I did consider that the physical construction of the encapsulated probe (air pockets) might slow the response but the data points to a resolution issue, it is too clean to be caused by a construction issue.

RattusRattus
Posts: 44
Joined: Sat Sep 29, 2018 11:27 am

Re: DS18B20 resolution

Sat Jun 01, 2019 4:52 pm

Hi there

I use these sensors in quantity. I use them in LARGE chains ( >50 sensors per bus) as a result I DO NOT use the libraries because a single GPIO line is unable to drive a large bus (instead I use multiple GPIO lines to drive pull-up, pull down, strong pull-up and strong pull-down FETs and some automatic impedance matching foo for long chain lengths). So I am only able to offer general comments;


#1 There are a lot of FAKE DS18B20 (and DS18B20+) devices out there, be sure of your supply chain

#2 The resolution of each device can be selected from 9 Bits to 12 Bits using R0 and R1 in the Thermometer Resolution Configuration register (byte 4 of scratch-pad)... is it possible that you have different resolutions selected?

#3 Are you doing simultaneous conversions or one conversion per sensor read? simultaneous conversions will mean that you will not be able to run parasitic power, and likely mean that your sensors at the end of your chain are browning out... (indeed you may be suffering brown out towards the end of the string even if you are only doing conversions one sensor at a time). Are the sensors with the largest swing the ones towards the end of your chain?

/Rattus

User avatar
omegaman477
Posts: 148
Joined: Tue Feb 28, 2017 1:13 pm
Location: Sydney, Australia

Re: DS18B20 resolution

Sat Jun 01, 2019 11:45 pm

0.25ºC resolution suggests you are not reading the full 12 bits.
..the only thing worse than a stupid question is a question not asked.

BrewSteve
Posts: 5
Joined: Sat Jun 01, 2019 8:20 am

Re: DS18B20 resolution

Wed Jun 05, 2019 3:58 am

Thanks for the responses.

I've tried changing the resolution using the CLI tool at https://github.com/timofurrer/w1thermsensor without success. The other tools work fine (listing sensors, reading temperature etc) but not changing precision. I've tried a couple of different sensors without luck.

The commands and error message are:

Code: Select all

[email protected]:~ $ sudo apt-get install python3-w1thermsensor
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-w1thermsensor is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 358 not upgraded.
[email protected]:~ $ sudo w1thermsensor get 1 --precision 10
/bin/sh: 1: cannot create /sys/bus/w1/devices/28-041663592dff/w1_slave: Permission denied
Traceback (most recent call last):
  File "/usr/bin/w1thermsensor", line 9, in <module>
    load_entry_point('w1thermsensor==1.0.3', 'console_scripts', 'w1thermsensor')()
  File "/usr/lib/python3/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/w1thermsensor/cli.py", line 145, in get
    sensor.set_precision(precision, persist=False)
  File "/usr/lib/python3/dist-packages/w1thermsensor/core.py", line 280, in set_precision
    raise W1ThermSensorError("Failed to change resolution to {0} bit".format(precision))
w1thermsensor.errors.W1ThermSensorError: Failed to change resolution to 10 bit
[email protected]:~ $ 

I've tried explicitly listing sensors as well, and get similar results.
Running as super user (as here) is still giving a Permission denied message.

Any suggestions?

pcmanbob
Posts: 6400
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: DS18B20 resolution

Wed Jun 05, 2019 8:48 am

What results do you get if you use this code

Code: Select all

#!/usr/bin/python
import os
import time

 
sensorids = ["28-041701672bff", "28-04170170feff", "28-0116035524ee", "28-021603a172ee", "28-0116035524ee", "28-021603a172ee"]
sensorname = ["1", "2", "3", "4", "5", "6"]
device_file = ""
 
def read_temp_raw():
    
    
    f = open(device_file, "r")
    lines = f.readlines()
    f.close()
    return lines
 
def read_temp():
    lines = read_temp_raw()
    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
        
        return temp_c
	
while True:
    print "Start "
    for sensor in range(len(sensorids)):
        device_file = "/sys/bus/w1/devices/"+ sensorids[sensor] +"/w1_slave"
        temperature = (read_temp())
        print "Sensor",sensorname[sensor],
        print temperature
        time.sleep(0.1)
    print " "
    time.sleep(1)
    
you will need to change the sensor names to match your actual sensors.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

BrewSteve
Posts: 5
Joined: Sat Jun 01, 2019 8:20 am

Re: DS18B20 resolution

Sun Jun 09, 2019 1:32 am

Thanks

This code runs fine and produces output:
Start
Sensor 1 16.437
Sensor 2 16.437
Sensor 3 16.25
Sensor 4 16.5
Sensor 5 16.187
Sensor 6 16.437

Start
Sensor 1 16.437
Sensor 2 16.437
Sensor 3 16.25
Sensor 4 16.75
Sensor 5 16.187
Sensor 6 16.437

pcmanbob
Posts: 6400
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: DS18B20 resolution

Sun Jun 09, 2019 7:15 am

I would say 2 of the sensors you have are of low quality or rejects ,

seems to be a problem with the water proof ones, just had 2 on one of my projects that have been working faultlessly for 6 months fail.

They go off line randomly and need to be powered down before they will work again.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

RattusRattus
Posts: 44
Joined: Sat Sep 29, 2018 11:27 am

Re: DS18B20 resolution

Sun Jun 16, 2019 9:51 pm

pcmanbob wrote:
Sun Jun 09, 2019 7:15 am
They go off line randomly and need to be powered down before they will work again.
Sounds very much like the Fake parts I came across, see my earlier post in this thread.
I have only had this problem buying parts from not traceable supply chains. once I started buying parts from the likes of Digikey / Element14 etc I stopped seeing this kind of problem....

/Rattus :)

danjperron
Posts: 3371
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18B20 resolution

Sun Jun 16, 2019 10:26 pm

You could use my user mode method.


The application configDS18B20 could set your bit resolution.


Use another pin than GPIO4 to set the resolution.

https://github.com/danjperron/BitBangingDS18B20

pcmanbob
Posts: 6400
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: DS18B20 resolution

Mon Jun 17, 2019 9:27 am

Following the failure of my waterproof sensors I decided to strip them down and replace the DS18B20 with some I have from a better supplier, once thing I did notice on stripping down the second on is that the soldered connections looked greenie/brown and broke away very easily so may be that was the cause of the problems.

once I had a new sensor attached to the wires and new heat sink compound in the tube with the sensor installed and new heat shrink tube applied I started testing.

now I had tested the DS18B20 before installation and it was providing results with 3 decimal places for 95% of the time , but once installed in the waterproof head that changed it now produces readings with only 2 decimal places 99% of the time with just the occasional 3 decimal place reading.

So it looks like the added mass of the tube and heat sink compound causes the sensor to heat more slowly and in larger steps resulting in the readings only being to 2 decimal places.

you live and learn.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

danjperron
Posts: 3371
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18B20 resolution

Mon Jun 17, 2019 1:00 pm

Accuracy of the DS18B20 is 0.5 Celsius. Half of a full degree!!!


It is normal to get more resolution than accuracy otherwise you couldn't get a good accuracy!

At 12 bits you are at 0.0625 Celsius which is a little more than 1 decimal resolution. So why are you looking at 3 decimals when the resolution, not the precision, is just a little bit better than 1 decimal?

pcmanbob
Posts: 6400
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: DS18B20 resolution

Mon Jun 17, 2019 2:03 pm

danjperron wrote:
Mon Jun 17, 2019 1:00 pm
Accuracy of the DS18B20 is 0.5 Celsius. Half of a full degree!!!


It is normal to get more resolution than accuracy otherwise you couldn't get a good accuracy!

At 12 bits you are at 0.0625 Celsius which is a little more than 1 decimal resolution. So why are you looking at 3 decimals when the resolution, not the precision, is just a little bit better than 1 decimal?
Because the original question on this thread was why some waterproof sensors were producing readings of XX.XX but other sensors were producing readings of XX.XXX
BrewSteve wrote:
Sat Jun 01, 2019 8:57 am

It appears that 2 probes have a resolution of 0.25 C and the others 0.062 C. The 2 outlier probes are from the same batch as 4 others (my purchase batch that is). My reading is that the drivers control the resolution so this should be the same for all probes.

Any suggestions as to why 2 probes should have a different resolution? I did consider that the physical construction of the encapsulated probe (air pockets) might slow the response but the data points to a resolution issue, it is too clean to be caused by a construction issue.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

danjperron
Posts: 3371
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18B20 resolution

Mon Jun 17, 2019 2:23 pm

Because the original question on this thread was why some waterproof sensors were producing readings of XX.XX but other sensors were producing readings of XX.XXX
I'm sorry but xx.xx is not 0.25!

xx.xx imply resolution less than 0.01 but the post is about difference between 0.25 and 0.063 which shown a possible problem with bit resolution. If you have problem with a sensor with a resolution of 0.25 you can't check 2 decimals digits. The best you could check is 1 decimals and not at its fullest!

BrewSteve
Posts: 5
Joined: Sat Jun 01, 2019 8:20 am

Re: DS18B20 resolution

Tue Jun 18, 2019 7:44 am

I suspect that the issue I have, which appears to be the failure of my code or CLI commands to change the DS18B20 resolution, is due to sensors that are not performing as I expect; they are not capable of having the resolution changed.

I bought these on eBay. When I look at ebay listings there are some which explicitly state 'programmable resolution' and some which do not. I have ordered some 'programmable resolution' sensors and will report back when they arrive.

Thanks for all the helpful comments

danjperron
Posts: 3371
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18B20 resolution

Tue Jun 18, 2019 1:58 pm

I'm just curious!

What is the result of my application configDS18B20

Code: Select all

git clone https://github.com/danjperron/BitBangingDS18B20
 cd BitBangingDS18B20
gcc -o configDS18B20 configDS18B20.c
Connect only one sensor to a GPIO pin. Not the GPIO4 but any in IN/OUT mode.
Don't forget to power it up with 3.3V and add the 4k7 pullup resistor.

On this example i'm using GPIO21 pin(40).

it should report the bit resolution

Code: Select all

[email protected]:~/BitBangingDS18B20 $ ./configDS18B20 21
GPIO 21
BCM GPIO BASE= 3f000000
...85 01 FF FF 7F FF 0B 10 38
12 bits  Temperature:  24.31 +/- 0.062500 Celsius
DS18B20 Resolution (9,10,11 or 12) ?9
Try to set 9 bits  config=1F
[email protected]:~/BitBangingDS18B20 $ ./configDS18B20 21
GPIO 21
BCM GPIO BASE= 3f000000
...86 01 FF FF 1F FF 0A 10 A9
09 bits  Temperature:  24.38 +/- 0.500000 Celsius
DS18B20 Resolution (9,10,11 or 12) ?12
Try to set 12 bits  config=7F
[email protected]:~/BitBangingDS18B20 $ ./configDS18B20 21
GPIO 21
BCM GPIO BASE= 3f000000
...80 01 FF FF 7F FF 10 10 A1
12 bits  Temperature:  24.00 +/- 0.062500 Celsius
DS18B20 Resolution (9,10,11 or 12) ?^C
[email protected]:~/BitBangingDS18B20 $

BrewSteve
Posts: 5
Joined: Sat Jun 01, 2019 8:20 am

Re: DS18B20 resolution

Thu Jul 04, 2019 8:14 am

Thanks Danjperron

Your application and procedure worked just fine. i was able to view and adjust the resolution on by DS18b20 sensors. So my suspicion that there are programmable and non-programmable resolution sensors appears to be incorrect.

My issues in changing resolution using timofurrer's tools would appear to be due to access issues, or more fundamentally my poor linux skills.

My new shipment of DS18B20 probes arrived yesterday. These are not as good as the others. As pcman bob says
seems to be a problem with the water proof ones, just had 2 on one of my projects that have been working faultlessly for 6 months fail.

They go off line randomly and need to be powered down before they will work again
.

I am running the probes in parallel, connected back to a breadboard and sharing a single 3.3V supply, ground and resistor. The first batch were running for months. The new batch stopped logging after 20 mins but started again on a reboot of my Pi. A further failure took the whole string out but was resolved bu unplugging and replugging a probe (not best practice). Now running a mix of my older and new probes I have had one drop out but not take the whole string down.

So there are definitely quality differences out there, and a couple of failure outcomes, either a single probe going offline or some failure in 1 which stops stops the whole system from reading.

I might just write come code to cycle the power on the probes periodically, a kludge I know but I cant resist the price on these things. I want to put them in to my home brewery, when I worked in large brewery we used to budget $1k to wire up a temperature transmitter on a 4-20 mA loop. I cant afford that some screening of outliers and software kludges works for me.

Return to “Automation, sensing and robotics”