Jump to content

Logging from DS18B20s


TerryE

Recommended Posts

I am just making up my remote sensors  for the new house and breadboarded up a 5 ds18b20 one-wire configuration.  Just before I wnet off to the hospital, I dropped all waterproof sensors into a glassof hand-hot water and left  them to cool.  There was one bad outrider so I did an X plot of all five against the average temperature measured by the other four and got this response:

58d424b3503a0_ErrroCurvesforDS18B20s.png.c7490e240e434784fe650e97c4fcb5f1.png

I haven't given the curves here but they also show quite difference lag characteristics in responding to higher rates of change.  

What this tells me is that I need to batch check and calibrate my sensors before using live.  They cost pin money in bulk form China, so this is probably well worth while if you want accurate readings or matched sensors.

 

PS. I know that used the Averege, but what the hell.

PPS.  Another 10 on their way so I should be able to get a properly matched set out of these :)

 

  • Like 1
Link to comment
Share on other sites

I am just setting up 9 sensors for calibration.  Found that when I connect up 6 they are reliable, add a seventh one it goes flaky, add the eighth one and the whole lot crashes.

May have to change the 47k resistor to something else (a 10k).

 

All I do to calibrate them is to pick one sensor as a 'true' one and then plot the others against it.  Then do some curve fitting in Excel, note down the equation and use that.

The lag can be an issue, longer sampling times usually sorts that.  They are not precision temperature sensors, but good enough for most things in a house.

 

Terry

Has T4 got a loose live wire? they can work using parasitic power, but when I tried I got a similar result, but the other way around.

Edited by SteamyTea
Link to comment
Share on other sites

My experience is that the Chinese DS18B20 sensors have a relatively high percentage of duds, with temperature offset being the quick and dirty way to spot them.  All the genuine Maxim DS18B20s that I've bought from an accredited supplier (RS Components or Farnell UK) have been far better matched, with no duds at all.  Looking at the device marking, there are noticeable differences between genuine Maxim devices and the Chinese ones, and like a lot of Chinese semiconductors, I suspect they are fakes.

 

The genuine Maxim devices are more expensive, but frankly that extra cost is trivial when you consider the time it takes to connect up and position the sensors in a house.

Link to comment
Share on other sites

37 minutes ago, JSHarris said:

All the genuine Maxim DS18B20s that I've bought from an accredited supplier (RS Components or Farnell UK) have been far better matched, with no duds at all. 

I've now got 15 cheap Chinese ones. I'll buy some from Darnell and compare them in my test rig.

 

I've been buying the waterproof ones - partly because the probe packaging with lead is far more robust. The cooling cup of water is a good way to check.

  • Like 1
Link to comment
Share on other sites

I'd be interested to see what you find.  I only started testing these when I had odd readings from two sensors that were both sat on the bench.  I then clamped half a dozen sensors, flat side down, to a block of aluminium and calibrated them against an NPL calibrated glass lab thermometer that was stuck in a drilling in the aluminium block, with the drilling filled with heat sink compound.  What I found was that there were often temperature offsets of between +/- 0.5 deg C to a worst case of + 1.3 deg C, at around 20 deg C.  In general, only around half to two thirds of the Chinese DS18B20s were inside the Maxim spec of +/- 0.5 deg C.  I didn't check linearity, as I decided to just give up on the Chinese sensors and use genuine Maxim devices. 

 

The only downside with doing this was that I needed to make housings for the Maxim devices, not hard, as I found they are a nice snug fit inside a bit of 6mm OD brass tube from B&Q.  With 1mm OD heatshrink on the junction with the connecting cable I found it was pretty easy to run some quick set epoxy over the DS18B20 and insert it into a short length of brass tube, sealing around the cable entry with adhesive lined heatshrink sleeving.  An extra blob of epoxy in the end of the tube sealed that and made a robust sensor.

 

With regard to the pull up resistor, I found that reducing the value this gave better results on long cables.  I'd very occasionally get a single duff reading, maybe once every week or two (and the sensors are read ten times an hour) from the sensor with the longest cable run.  Reducing the pull up from 4k7 to 3k3 seems to have fixed this.

Link to comment
Share on other sites

Got the soldering iron out at the moment.

All seems fine now.  May be different when I split them all up on different length cables, but that is for later.

 

So a quick coding question.

 

In Python, when you open up to read the sensors with:

 

Sensor 4
    tfile = open("/sys/bus/w1/devices/28-0316b2f96eff/w1_slave")
# Read all of the text in the file.
    text = tfile.read()
# Close the file now that the text has been read.
    tfile.close()

 

After I have processed the data with:

 

# Split the text with new lines (\n) and select the second line.
    secondline = text.split("\n")[1]
# Split the line into words, referring to the spaces, and select the 10th word (counting from 0).
    temperaturedata = secondline.split(" ")[9]
# The first two characters are "t=", so get rid of those and convert the temperature from a string to a number.
    temperature = float(temperaturedata[2:])
# Put the decimal point in the right place and display it.
    temperature = temperature / 1000

 

Can I move onto the next sensor without renaming the the tfile to say tfile1. 

What I have to do with the final temperature = temperature /1000 or I just keep printing out the same data.

 

Not hard to rename them all with a simple number, just that I am lazy and wondering if it is necessary.  Also reduces the chance of errors.

Edited by SteamyTea
Link to comment
Share on other sites

3 hours ago, SteamyTea said:

Has T4 got a loose live wire? they can work using parasitic power, but when I tried I got a similar result, but the other way around.

 

The OW protocol uses pull down float high scheme with the clock defined by the master and in the case of receives then there is a ping-pong beat where the slave replies on the.pongs.  The transfer is CRCed so any loose connections result in CRC failures and I am not getting any of those. 

 

The pull low results in clashes being logically anded and the search protocol uses this plus requesting both the address bits and the not bit to work out common 0s 1s and clash bits to enumerate the devices. Really elegant.

 

I usually use an esp8266 module called the Wemos D1 or pro variant which cost about £3 each from China on a 4 week delivery or £7 direct from the UK. It just plugs into the USB and you program it like an Arduino, so no extra kit is required.  I also use the firmware that I help develop: NodeMCU Lua. The big advantage of this is that you only blow the firmware once (except if you are a firmware developer like me).  All of the Lua runs out of the on-module file system, so you can update individual modules as needed.

 

I usually do my hardware in three phases: breadboard, prototype and "production". The last two l do using a through hole soldered board to mount hardware modules, connectors and any components.  The difference is that the prototype is often just spot hot glued to a mounting board whereas the production model goes in a DIN rail or project box with decent glands etc..

 

The family supports parasitic power but I don't bother as you need special parts that support it.

Link to comment
Share on other sites

I go from P/Type to P/Type 1, P/Type 2, P/Type 3...

Then stuff it in a box.

 

Got my 9 sensors up and running now, shall leave them on a bit and see what they get up to.

Then I can get out my 'calibration' sensor and add that to them.  Then find a way to dunk them is a bucket of water without them shorting.

 

24/03/2017 11:22:33,27.75,27.75,27.187,27.187,27.125,27.187,27.187,28.062,27.375
24/03/2017 11:22:47,27.375,27.375,26.75,26.937,26.625,26.812,26.75,27.75,27.0
24/03/2017 11:23:00,27.0,27.0,26.375,26.625,26.25,26.5,26.375,27.437,26.687
24/03/2017 11:23:14,26.687,26.687,26.125,26.375,25.937,26.187,26.062,27.125,26.375
24/03/2017 11:23:27,26.375,26.375,25.875,26.062,25.75,25.937,25.75,26.812,26.062
24/03/2017 11:23:41,26.125,26.125,25.625,25.812,25.5,25.687,25.562,26.5,25.812
24/03/2017 11:23:56,25.812,25.812,25.312,25.5,25.187,25.375,25.25,26.187,25.5
24/03/2017 11:24:10,25.562,25.562,25.125,25.312,25.0,25.187,25.0,25.937,25.25
24/03/2017 11:24:23,25.312,25.312,24.875,25.062,24.812,24.937,24.812,25.687,25.062
24/03/2017 11:24:38,25.125,25.125,24.687,24.875,24.625,24.75,24.687,25.437,24.812
24/03/2017 11:24:51,24.875,24.875,24.5,24.687,24.437,24.5,24.5,25.25,24.625
24/03/2017 11:25:05,24.687,24.687,24.312,24.562,24.25,24.312,24.312,25.0,24.437
24/03/2017 11:25:19,24.5,24.5,24.187,24.375,24.125,24.187,24.187,24.812,24.312
24/03/2017 11:25:33,24.312,24.375,24.062,24.25,24.0,24.062,24.062,24.687,24.187
24/03/2017 11:25:46,24.187,24.187,23.937,24.062,23.937,23.937,23.937,24.687,24.0
24/03/2017 11:26:00,24.062,24.062,23.812,24.0,23.937,23.812,23.812,24.375,23.875
24/03/2017 11:26:13,23.937,23.937,23.687,23.875,23.687,23.687,23.75,24.25,23.75
24/03/2017 11:26:27,23.812,23.812,23.625,23.75,23.625,23.625,23.625,24.125,23.687
24/03/2017 11:26:40,23.75,23.75,23.562,23.687,23.562,23.5,23.562,24.0,23.562
24/03/2017 11:26:54,23.625,23.687,23.437,23.562,23.5,23.437,23.5,23.937,23.5
24/03/2017 11:27:07,23.562,23.562,23.375,23.5,23.437,23.375,23.437,23.812,23.437
24/03/2017 11:27:20,23.5,23.5,23.312,23.437,23.375,23.25,23.375,23.75,23.312
24/03/2017 11:27:34,23.437,23.437,23.312,23.375,23.312,23.25,23.312,23.687,23.25
24/03/2017 11:27:47,23.375,23.375,23.25,23.312,23.312,23.187,23.25,23.625,23.25
24/03/2017 11:28:01,23.312,23.312,23.187,23.25,23.25,23.125,23.187,23.562,23.187
24/03/2017 11:28:14,23.312,23.312,23.187,23.187,23.187,23.062,23.187,23.5,23.125
24/03/2017 11:28:28,23.25,23.25,23.125,23.187,23.187,23.062,23.125,23.437,23.062
24/03/2017 11:28:41,23.187,23.187,23.062,23.125,23.125,23.0,23.125,23.375,23.0

 

And just noticed that the second sensor is on the same address as the first. Bugger

Edited by SteamyTea
Link to comment
Share on other sites

4 minutes ago, SteamyTea said:

Then find a way to dunk them is a bucket of water without them shorting.

 

That's a good reason to use the encapsulated parts but even if you don't, haven't you missed all of @Nickfromwales extolling of SikaFlex?  You can just encapsulate the cable end, soldered joins and tails in a polysilicate or even hot glue and this will pretty effectively waterproof the part alternatively put them in a poly bag.  cover this in thermal scrinkwrap sleeve if you are a perfectionist.

 

You don't need a bucket; the centre of a glass will do (to avoid boundary cooling effects) and this is better since it will quickly cool so your sensors will cover the same range together.  Beware of rapidly changing temperatures since the individual devices can have varying internal temperature lags, but this isn't an issue in practice if your normal rate of change in less than 1° per hour.   

Link to comment
Share on other sites

I know ways to make them waterproof enough.

I find a small bucket or large pickle jar quite good as the rate of cooling is slower, can then sample at a slower rate and get a more accurate result.

But, as you say, in the real world it is not that important.

Link to comment
Share on other sites

7 hours ago, PeterW said:

@TerryE can it also log DHT22...??

 

The simple answer is yes, and Wemos even do a standard DHT Pro shield: .  I hadn't thought of doing this, but a good option might be to put DHT22s in all of the extract ducts.  The DHT22 uses the OW bus at an electrical level but the bus protocol at a S/W level is different.  Specifically only one device is supported per OW bus but the Wemos board export 7 I/O pins that can be used to drive  separate devices.

 

I terms of my little setup, here is my prototype stage for the logger (total price well under £10 or £15 including half a dozen Chinese DS18B20s): 

58d53a4aa182b_TemperatureloggerPrototype.thumb.jpg.c2fc4b7f0c77a5d98118836dbe43481c.jpg

 

Most of the smarts are on the Wemos Module so the circuit board only contains the wiring to support 8 DS18B20 headers.  You just plug your USB into your PC and the DS18B20s into the headers and you are up and running.  The power here comes from the USB 5V.

 

There is standard Arduino extension to support this board, but the NodeMCU Lua package typically uses a IDE called ESPlorer, but I use a simplified approach which works for me.  In dev mode every time the chip loads a new module it checks back to the mother ship over wifi and if the version is newer than the existing copy then it automatically replaces the file before loading it.  This means that I don't use ESPplorer for editing or downloading source. I just do all the editing on my laptop and reset the chip if I want to download the latest copy.

Link to comment
Share on other sites

@PeterW, It's a standard USB virtual comm port, so any *nix / OS/X / Windows machine will do.  I just plug in to my Ubuntu Laptop when developing.

 

If you are using them for "mission critical" control in production and don't want to rely on the Wifi being up, then a good technique is to plug the device into your HA RPi3 using USB and use a simple serial protocol over the virtual comm port.  USB supports up to 5m cables so this will allow you to collect data remotely up to 5m away.   Further than that and you will need to depend on the WiFi being up.   For non-critical logging (e.g. room temps) then you just use Wifi.

 

Also a company called ITEAD do a range of mains pluggable switches / sensors, etc. based on this chip (its Sonoff range) so you can just buy these and replace the firmware if you want; that's what my son-in-law does in their house.  

Link to comment
Share on other sites

I am happy to source my stuff from China because most comes from there any way, and there's little point in paying a 2-3 x mark up to some supplier unless they add value.  Supply obsolescence is a real issue wherever you get your components from, so one thing I will be doing is to buy a 10-20 year spares holding as part of commissioning.  E.g. if I am using Wemos modules, then buy 100% extra as spares.

Link to comment
Share on other sites

As I had a couple of hours free yesterday and my 9 DS18B20s had been running a couple of days, I thought I would look at how precise the readings where.

I cannot really check accuracy as I do not have a calibrated thermometer to check them against.

 

So what I did was to create a range of temperatures that are imaginary true ones.  Then look at the spread of readings in each bin range.

This is pretty easy in a spreadsheet, just list a range of temperatures (I rounded down to 1 decimal point the lowest temperature then incremented up by 0.1°C).

Then I looked at means between the the bin below and the bin above i.e. Temp bin below < DS18B20 reading > Temp bin above.

This makes for a very quick visual comparison in a spreadsheet as the DS18B20 mean should be pretty close to the "imaginary" temperature.

 

Some numbers are going to follow now.

If I take the minimum temperatures recorded by all sensors first.

14.6°C (Imaginary), 14.72, 14.71, 14.69, 14.70, 14.75, 14.71, 14.75, 14.75, 14.70

 

Then the maxium

24.4°C (Imaginary), 24.50, 24.51, 24.50, 24.51, 24.51, 24.47, 24.47, 24.47, 24.52

 

Then the highest overall count (this gets really nerdy).

 

Sensor 1, Count 528, Imaginary Temp 18.3, Mean Temp 18.30

Sensor 2, Count 517, Imaginary Temp 18.2, Mean Temp 18.20

Sensor 3, Count 480, Imaginary Temp 18.2, Mean Temp 18.19

Sensor 4, Count 526, Imaginary Temp 18.2, Mean Temp 18.19

Sensor 5, Count 542, Imaginary Temp 18.2, Mean Temp 18.19

Sensor 6, Count 559, Imaginary Temp 18.0, Mean Temp 18.01

Sensor 7, Count 579, Imaginary Temp 18.4, Mean Temp 18.37

Sensor 8, Count 579, Imaginary Temp 18.4, Mean Temp 18.37

Sensor 9, Count 638, Imaginary Temp 18.0, Mean Temp 18.01

 

So it seems that these cheap DS18B20s are pretty precise in the temperature range I have so far tested, not more than 0.15°C out, which is neither her nor there for what we are using them for.

I have also not had any errors in the 11,166 readings I have taken over the last couple of days.  I am sampling every 13.59 seconds overall.

 

I also had a look at the standard error of the mean, but that is really so low that it is not worth mentioning, but I will anyway 0.03°C max.

 

Now to really go overboard with the stats, I also looked at the median and modal values.

The biggest difference from the imaginary temperature was 0.1°C on the modal values (as expected as there are not many readings, but not counted them.)

The main thing here is that all the values are very close together, between -0.09 and 0.10°C over a range of 10.2° shows that the logged temperatures are pretty well normally distributed.  This is a good thing when testing, as more accurate assumption can be drawn.

 

Not sure what conclusion can be drawn from this, apart from the precision of these very cheap sensors is plenty good enough for me.

Edited by SteamyTea
Got my <> the wrong way around in the write up. And then to re-add some numbers, cutting and pasting from Excel does nto always work
  • Like 1
Link to comment
Share on other sites

@SteamyTea, try logging over a temperature glide. If you haven't got the waterproof ones then put them in a metal box on the window cill and let them slowly warm in the sunshine. Or in a poly bag in water starting hotter or colder than room temperature.  Then you can do the same sort of analysis as my first post. You don't need an absolute reference, just use an average, maybe excluding any obvious outriders.

 

I've decided to source mine cheaply but use this sort of callibration technique to select matched sets. I don't need absolute accuracy, but I do need reasonably matched sets - say to 0.1° over the operating range.

Link to comment
Share on other sites

That data pretty much mirrors my experience, ST,  that if you get "good" sensors then they tend to be consistently "good", but I did receive quite a lot of duff sensors, that quickly showed as being duff by having an excessive temperature offset (greater than +/- 0.5 deg C).  I think I used two or three different suppliers from ebay, initially, and I didn't keep a record of which devices came from each supplier.  It may well be that all my duff ones came from a single rogue supplier, as that would tally with the percentage of duff ones I had.  I can say that the genuine Maxim ones look markedly different from the ones I bought on ebay, with clearer part markings that are in a different font.

 

I'm pretty sure that DS18B20s are being manufactured in quantity by one or more Chinese counterfeiting outfits, simply because I've seen exactly the same thing with power MOSFETs, and the volume of the market for DS18B20s is very large.  Like all things, some of the fakes may well be as good as the genuine chips, it's just a bit of a lottery knowing who are the reliable sellers.  When I had problems with fake IRFB4110 MOSFETs, I found that the easily tested specs were fine, although the on resistance was at the upper end of the spec.  The part markings were definitely fake, as they showed the parts as having been made at an IR fab plant that had never produced this range of devices.  I built a brushless motor controller with them and immediately had big explosions, with the FETs letting out loads of magic smoke.  It turned out that the fakes had no where near the dV/dT capability of the genuine devices, so failed dramatically when switching a few tens of amps at around 80 V in a uS or two.  When rebuilt with genuine IR devices (which were about four times more expensive) the controller worked fine (still does, several years later).

 

FWIW, there are a lot of fake SSRs around, too.  I got caught when I bought what were marked as Crydom SSRs, but when they arrived they felt very light when compared to another Crydom that was the same model.  I decided to sacrifice one and ripped it apart, only to find that it wasn't potted internally, had inadequate isolation between the LV side and the ELV side and also had very poor thermal coupling between the internal triac and the metal back plate.  Clearly this were fakes being sold by a Chinese seller on ebay, described and marked as if they were a well-known and trusted brand name.  In the end I bought a job lot of new and genuine Crydom SSRs from a UK seller, that were guaranteed to be genuine devices, and they've been fine.  Given the safety risks associated with stuff that's switching 230 VAC and supposedly has an isolated ELV DC control signal, I'd urge a bit of caution when buying these things.

Link to comment
Share on other sites

As I mentioned earlier, B&Q sell brass tube that's 6mm OD and about 5mm ID and a DS18B20 is a nice snug fit inside.  The tube is best cut with a pipe cutter, as it has a very thin wall.  I can't remember the price, but a 1m length is enough to make sleeves for around 40 sensors.  The brass makes for a reasonably good thermal path between the sensor and the outside world, not that this matters too much for the sort of slow temperature changes in a house.

  • Like 1
Link to comment
Share on other sites

I've plugged 8 of my my batch of waterproof DS118B20s into my prototype rig and did a quick temperature ramp on them, by filling a glass dish with hand-hot and dropping them in, then stirring and dribbling in cold water to gradually cool the solution down (note that I've labelled each DS18B20 with its PW address): 

Net-batchDS18B20s.jpg.36962be17fa98009c7fd62d63cc6180a.jpg

 

The error range was a lot less this batch: ±0.3%, but it wasn't at all clear to me how much of this was due to inhomogeneities in the liquid temperature and the positioning of the cans relative to the cooler glass surfaces, etc.  So I had a brood and decided to bundle the probes with an elastic band around the sleeve part to the cans were still separated by water and then stood them in a metal egg cup in the centre of a glass again holding water at an initial ~40°C and left them to cool overnight logging the temperatures every 10 mins.  I then pulled the data into a spreadsheet, so here is also the error vs. average XY plots for all 8 thermo's:

 

What I'll do before heading off to bed is to leave 8 of the devices in a hot glass of water and let this cool naturally overnight and then repeat tomorrow.  This should give me two reasonably homogeneous and steady glides to calibrate the thermometers

Test-setup.thumb.jpg.f672375caa3a274f89b6084762560184.jpg  58dbde618dfc7_Tdelts-T.png.c8aadc65af9417f8021ee15d9c6e40b9.png

 

What is clear here is that the thermometers give stable and self-consistent readings over the temperature range that I am using these for.  They are consistent to within ¼°C of the average over this range, and once corrected by a linear regression derived from this calibration data, then they will be accurate within the least significant bit of their sampling resolution.   As I said, I am less concerned about absolute accuracy so long as the thermometers are mutually consistent.

 

IMO, there is little point in paying a 200% plus premium for Maxim parts from a main UK distributor or doing any waterproofing given that these 10 Pcs 1M DS18B20 Temperature Temp Sensor Thermal Thermometer Waterproof Control cost £1.30 ea.

 

I will do the second batch tonight.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...