Fastest OneWire (ds18b20) update rate on Raspberry Pi

I have several (up to 40) DS18B20 sensors that I'd like to read with a rPi. Currently, I have an Arduino reading them every 5 seconds by issuing a global temperature conversion command, waiting about 800ms, then reading them all. I have a Zero W that I've been using to prototype this same functionality with both the contrib-ds18b20-sensor library and reading the onewire files with the "file in" node directly. Both appear to take about 900 ms for each sensor. I see there's also contrib-owfs library but I have not setup the owfs server yet to test it.

Does anyone have extensive OneWire/Raspberry Pi experience with reading large sensor groups? Does owfs have advanced configuration options for using parasite power mode, writing/reading the high/low alarm setpoints and higher update rates etc?

I think the first question is why? What benefit is a 5s refresh rate for temperature readings giving you?

In any case, it looks like it is a slow sensor. Seems to have a minimum 750ms response time. In addition, since the sensor is encased, I can't see that it would respond very quickly anyway since there is, I would think, a significant thermal mass that needs changing.

1 Like

What Julian said, plus:

Last time I used a Pi for reading DS18B20 sensors, the w1-gpio kernel module had a limitation of about 10 devices, I think. :thinking: I moved to using ESP8266/ESP32 devices for all my low-level stuff, readings are fairly fast and stable.

And, the conversion time is highly dependent on the sensor's resolution, configurable from 9 to 12 bits. I am using 10 bits mostly now, so you get steps of 0.25 degrees Celsius. 9 bits (0.5 degree steps) would be even faster, if that is sufficient.

1 Like

If you really need to read this many devices on one bus, I would consider using a real 1-wire bus master. These are available as USB dongles that can be connected to your Pi and integrated into owfs.
My colleague is using that solution for his house.

Plus, you have the benefit of using 5V instead of 3.3V.

2 Likes

What Julian and Mathias said plus I would do the alarms in Node-red.

These temps are used for a couple process controls. 5 sec update rate isn't necessary but my 15 min graphs have a resolution of 15 secs. I could lower their precision for a quicker conversion time.

Thanks for heads up on the potential 10 sensor limit, that'll be a deal breaker.

I'd like to stay with 5V for the sensors as my experience is that they are a lot more interference resistant and reliable with 5V, especially with so many sensors.

I'm not actually doing alarms on the sensors, I'm using the high/low setpoints for organizing/ID'ing them. High alarm is my group number, low alarm is the sensor number. This is how commercial grain bin systems do it.

Each DS18B20 has a unique serial number!

From the Datasheet:
"Each DS18B20 has a unique 64-bit serial code, which
allows multiple DS18B20s to function on the same 1-Wire
bus."

1 Like

I supose the other question is how resilient does this need to be? Because if the temperature readings are critical (e.g. something will be spoiled or the whole thing will blow up :frowning:) then I wouldn't want to rely on a single Pi I wouldn't think. Better would be separate ESP8266's, probably 2 of them for each measurement and sending out to MQTT with a backup MQTT and backup WiFi network.

Then using 1 or 2 Pi's to do the central control.

1 Like

I am aware of that, and I may restructure to accommodate that for my own applications but it's easier to remember 1:5 then a random serial number. Plus, if its going to be compatible with other commercially available sensor ropes, I have to go with the high/low method.

@m_elias

I too have a ton of DS18B20's and was floored by how long it took to get data back down the line using contrib-ds18b20-sensor
So I started diggin how is polling the sensors on a 1 wire can geting so congested

If you look at the contrib-ds18b20-sensor code ds18b20 github. You will notice that its polling information from all the sensors then checking an array for the matching ID you entered into the node.

So if you have 10 sensors its polling 10 times! 10 sensors Its not using the match rom commands found in the 1-wire documentation. DS18B20.pdf

My solution was to poll once and sort the data myself. I've had 14 sensors talking fine!

Here is my flow I'm using for one 100 yard lane of the company freezer ( oh there are more lanes :blush: )

[{"id":"6a6c83b8.bb185c","type":"inject","z":"e1935875.a74068","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":120,"y":80,"wires":[["13ef1dd3.a2cf62"]]},{"id":"604ddc78.fab204","type":"comment","z":"e1935875.a74068","name":"TESTING: Output all temp sensors connected into an array. To figure out sensor ID's","info":"","x":310,"y":40,"wires":[]},{"id":"13ef1dd3.a2cf62","type":"rpi-ds18b20","z":"e1935875.a74068","topic":"","array":false,"name":"","x":310,"y":80,"wires":[["1f01bf2a.2f3b71"]]},{"id":"1f01bf2a.2f3b71","type":"debug","z":"e1935875.a74068","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":510,"y":80,"wires":[]},{"id":"d2bb6889.0e9c88","type":"comment","z":"e1935875.a74068","name":"Body: Tempature Probes","info":"diagram of map link here ","x":130,"y":140,"wires":[]},{"id":"78b46331.d9ff7c","type":"comment","z":"e1935875.a74068","name":"Freezer_400_East_U","info":"","x":240,"y":240,"wires":[]},{"id":"796619bd.d06898","type":"comment","z":"e1935875.a74068","name":"edit when changing sensor","info":"","x":750,"y":180,"wires":[]},{"id":"b656262f.9f4ee8","type":"comment","z":"e1935875.a74068","name":"TmpSen-Checks ----->","info":"","x":1200,"y":260,"wires":[]},{"id":"1a32f115.43a18f","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_East_U","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":240,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"a9f385f1.3e9de8","type":"debug","z":"e1935875.a74068","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1170,"y":600,"wires":[]},{"id":"69e008c7.5e0bd8","type":"link out","z":"e1935875.a74068","name":"TmpSen-RX OUT","links":["7b1ba438.5b19ec","7410bd02.e9f9b4"],"x":1075,"y":260,"wires":[]},{"id":"4a0ae719.de3f58","type":"inject","z":"e1935875.a74068","name":"30sec","topic":"","payload":"","payloadType":"date","repeat":"30","crontab":"","once":true,"onceDelay":"","x":120,"y":180,"wires":[["a780bcc.d212b4"]]},{"id":"1abb841e.5a146c","type":"switch","z":"e1935875.a74068","name":"If = FFB001A31704","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FFB001A31704","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":240,"wires":[["1a32f115.43a18f"],["b619ce5b.8681a"]]},{"id":"a780bcc.d212b4","type":"rpi-ds18b20","z":"e1935875.a74068","topic":"","array":false,"name":"","x":310,"y":180,"wires":[["1abb841e.5a146c"]]},{"id":"4a878a7f.f420b4","type":"comment","z":"e1935875.a74068","name":"Freezer_400_East_L","info":"","x":240,"y":280,"wires":[]},{"id":"b619ce5b.8681a","type":"switch","z":"e1935875.a74068","name":"If = FFAA33401802","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FFAA33401802","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":280,"wires":[["d0e0c004.6fd2a"],["3e0ebc54.8d7ee4"]]},{"id":"d0e0c004.6fd2a","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_East_L","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":280,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"98d18d4e.df1cd","type":"comment","z":"e1935875.a74068","name":"Freezer_400_Center_U","info":"","x":240,"y":320,"wires":[]},{"id":"3e0ebc54.8d7ee4","type":"switch","z":"e1935875.a74068","name":"If = FFAA0F411801","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FFAA0F411801","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":320,"wires":[["12701796.dd9258"],["8dc831b7.4b3a5"]]},{"id":"12701796.dd9258","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_Center_U","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":320,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"54ce9ea5.13a41","type":"comment","z":"e1935875.a74068","name":"Freezer_400_West_U","info":"","x":240,"y":360,"wires":[]},{"id":"8dc831b7.4b3a5","type":"switch","z":"e1935875.a74068","name":"If = FF8710411801","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FF8710411801","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":360,"wires":[["9c0c8a20.b71128"],["c9cc70a.b54399"]]},{"id":"9c0c8a20.b71128","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_West_U","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":360,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"f8eb4ab0.77f5e8","type":"comment","z":"e1935875.a74068","name":"Freezer_400_West_L","info":"","x":240,"y":400,"wires":[]},{"id":"c9cc70a.b54399","type":"switch","z":"e1935875.a74068","name":"If = FF790B411801","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FF790B411801","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":400,"wires":[["9c20d488.d080b8"],["a738605e.324f3"]]},{"id":"9c20d488.d080b8","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_West_L","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":400,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"a9b72790.2912e8","type":"comment","z":"e1935875.a74068","name":"Freezer_400_Evaporator_West_Coil","info":"","x":200,"y":440,"wires":[]},{"id":"a738605e.324f3","type":"switch","z":"e1935875.a74068","name":"If = FF2233401802","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FF2233401802","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":440,"wires":[["8ccbe599.592bb8"],["1f08a207.0316be"]]},{"id":"8ccbe599.592bb8","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_Evaporator_West_Coil","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":440,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"fdabded6.4baed","type":"comment","z":"e1935875.a74068","name":"Freezer_400_Evaporator_West_Intake","info":"","x":190,"y":480,"wires":[]},{"id":"7024c4f.2a0f93c","type":"comment","z":"e1935875.a74068","name":"Freezer_400_Evaporator_West_Exhaust","info":"","x":180,"y":520,"wires":[]},{"id":"f2757e0e.8448e","type":"comment","z":"e1935875.a74068","name":"Freezer_400_Evaporator_East_Coil","info":"","x":200,"y":560,"wires":[]},{"id":"adf5687a.72fbe8","type":"comment","z":"e1935875.a74068","name":"Freezer_400_Evaporator_East_Intake","info":"","x":190,"y":600,"wires":[]},{"id":"1f08a207.0316be","type":"switch","z":"e1935875.a74068","name":"If = FF370F411801","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FF370F411801","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":480,"wires":[["7dd0da09.27a764"],["83e81070.5a8b6"]]},{"id":"7dd0da09.27a764","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_Evaporator_West_Intake","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":480,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"83e81070.5a8b6","type":"switch","z":"e1935875.a74068","name":"If = FF2BB7331801","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FF2BB7331801","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":520,"wires":[["28e8b5f8.d64a0a"],["1cba9c60.871ca4"]]},{"id":"28e8b5f8.d64a0a","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_Evaporator_West_Exhaust","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":520,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"1cba9c60.871ca4","type":"switch","z":"e1935875.a74068","name":"If = FF1304C11705","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FF1304C11705","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":560,"wires":[["6a9640cc.45f73"],["31d65f4.6ccd1a"]]},{"id":"6a9640cc.45f73","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_Evaporator_East_Coil","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":560,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"31d65f4.6ccd1a","type":"switch","z":"e1935875.a74068","name":"If = AAB7CA131302","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"AAB7CA131302","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":480,"y":600,"wires":[["87c3c26e.0d41f"],["3c110f1.3dd4cf"]]},{"id":"87c3c26e.0d41f","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_Evaporator_East_Intake","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":600,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]},{"id":"72ba34ec.a7fe5c","type":"comment","z":"e1935875.a74068","name":"Freezer_400_Evaporator_East_Exhaust","info":"","x":190,"y":640,"wires":[]},{"id":"3c110f1.3dd4cf","type":"switch","z":"e1935875.a74068","name":"If = FF13A3B31701","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"FF13A3B31701","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":640,"wires":[["95291a0f.00d098"],[]]},{"id":"95291a0f.00d098","type":"change","z":"e1935875.a74068","name":"format topic to mqtt header","rules":[{"t":"set","p":"topic","pt":"msg","to":"Sun/SunValley/TempSensor/Freezer_400_Evaporator_East_Exhaust","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":640,"wires":[["a9f385f1.3e9de8","69e008c7.5e0bd8"]]}]

Hope this gets you to 5 seconds. 15 is more realistic.

1 Like

Why so many sensors for all the lanes in the giant 40ft tall freezer?

Well we contract out storage in the freezer for customers

Customers were having product go bad early every summer. They were blaming our cold storage.
I kept saying its your drivers leaving the back of the dang truck open when they were delivering the product to stops on the route in July.

Solution.... 90 days of data every 30 seconds. 6 months every minute, and 1 year every 5min stored to database.

Customers given access to data upon request or real time for a nominal fee. Pictures with time stamp on security camera of their product proving it only took 5 min to get it from the freezer to their truck and vis-vera.

Oh and im using a Raspberry PI for each freezer. I find them very reliable in the freezer :slight_smile:

uptime

4 Likes

I was already processing the data myself too, using the file in node to read the w1-gpio kernel files directly but it wasn't reading all 8 test sensors reliably. I probably need to tinker with the pullup R but I think I'll just try the firmata approach next with a Pi and 5V Arduino.

oh, having different resistance on the line for each sensor helps with decreasing collision. I found using expensive 100% copper high speed cat5 cable SUCKS! I'm using the coper clad crap and getting 50 yards no problem. using 4.7kohm resistors on almost all of the runs. 10kohms for short runs under 10ft

Edit: not for you but for others.
as you increase distance of the wire it adds resistance. so you have to factor it in when using a resistor. You can use cable length as a resistor of sorts fyi and to control timing of the message.

Could you post a link, I'm looking for cable for a short (20 yards) project.

@ghayne

Shielded for noisey areas - https://www.amazon.com/gp/product/B073HJH23M/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

Un-Shielded for low noies area - https://www.amazon.com/gp/product/B073HK7FKT/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

Note: It is brittle stuff. Don't yank it out of the box or bend it back and forth a bunch of times.
Cold will add to this effect.

I would warm the box up and put it in a heated blanket when pulling it in the freezer.

1 Like

Thanks @meeki007, I am in the UK but that gives me a great starting point. In days gone by I used to hand crimp plugs onto cables like this!

@ghayne

also I used punch down connectors to make wiring easy

double unit when I was daisy chaining them along the line.

tempsensor_punchdown_2

DON'T MIX UP your cables with Ethernet ! I use blue for my network and white for all sensors with a label on the end of every end to tell people not to plug this into a network.

Automation_Plug_1

I am not looking to connect DS18B20's, I want to put DS2413 remote GPIO's on the cable to attach motion detectors, but the cable recommendations help a lot.

A bit OT but I just have to say, I really like 1-wire. So reliable, so stable, set & forget...just works, been running since years now
In my home automation I use this little thing since years, see below. It sits high up on our chimney and measures the ambient light. I use various averaged readings in my algorithms in NR to control

  • awnings & shutters
  • calculating +/- offsets relative sunset/sunrise for indoor lighting, all our facade and outdoor lighting around the house

I know, I could also have used a z-wave motion sensor with built-in light sensor, but hey, who want's to climb the roof just to change batteries now and then?

1 Like

Maybe something for another thread in the Hardware topic but how did you run power/data?

In fact, let me create a new thread because while I'm thinking about it, I have a question.

New topic here: Q: Bundle sensors with an ESP8266 or separate them?