Quicker reading from multiple DS18X20 sensors

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
Post Reply
scudderfish
Posts: 24
Joined: Sun Oct 04, 2015 9:06 am

Quicker reading from multiple DS18X20 sensors

Post by scudderfish » Sun Nov 08, 2015 5:38 pm

I've hacked about on the previous 18X20 driver so that it works quicker if you have more than one sensor. If you only have one, this will be no better. Basically, instead of enumerating over each sensor telling it to read, and waiting for an answer, I tell all sensors to start a conversion, wait for the last one and then read them all.
Here's a test run, the first block of temps is read all sensors the old way three times, the second block is the new way. The number after is the time in ms to complete all three sets of reads.

Code: Select all

MicroPython v1.5-94-gae58035 on 2015-11-07; WiPy with CC3200
Type "help()" for more information.
>>> import FDS1820
>>> FDS1820.tst()
devices: [bytearray(b'(\xff\x13Ns\x15\x03u'), bytearray(b'(\xff\xaa`s\x15\x03\xac'), bytearray(b'(\xff\x00\xcbr\x15\x02\xea')]
temperatures: [1981, 1975, 1993]
temperatures: [1981, 1975, 1993]
temperatures: [1981, 1975, 1993]
6094
temperatures: [1981, 1975, 1993]
temperatures: [1981, 1975, 1993]
temperatures: [1981, 1975, 1993]
2332
>>> FDS1820.tst()
devices: [bytearray(b'(\xff\xcfur\x15\x02#'), bytearray(b'(\xff\x13Ns\x15\x03u'), bytearray(b'(\xff\xaa`s\x15\x03\xac'), bytearray(b'(\xff\xf8\xa6r\x15\x02\x7f'), bytearray(b'(\xff\x00\xcbr\x15\x02\xea')]
temperatures: [2031, 1987, 1981, 2093, 2000]
temperatures: [2031, 1987, 1981, 2100, 2000]
temperatures: [2031, 1987, 1981, 2100, 2000]
10133
temperatures: [2031, 1987, 1981, 2100, 2000]
temperatures: [2031, 1993, 1981, 2100, 2000]
temperatures: [2031, 1993, 1981, 2100, 2006]
2619
So when I had three sensors, it took about 2 seconds per read set for the old code and 0.8 seconds for the new code. I then added two more sensors. It then becomes 3 seconds per set for the old code, but only 0.8 and a bit for the new code.

First commit of ugly code here https://github.com/scudderfish/SFL525R/ ... FDS1820.py

Regards,
David

scudderfish
Posts: 24
Joined: Sun Oct 04, 2015 9:06 am

Re: Quicker reading from multiple DS18X20 sensors

Post by scudderfish » Sun Nov 08, 2015 7:22 pm

Now in it's own repo so it doesn't get mixed up with my master project

https://github.com/scudderfish/FDS18X20

scudderfish
Posts: 24
Joined: Sun Oct 04, 2015 9:06 am

Re: Quicker reading from multiple DS18X20 sensors

Post by scudderfish » Sat Jan 30, 2016 3:47 pm

I've finally got my wipy installed in my car and on the first run of this code today I was logging 5 sensors to an SD card at about 3 sets of readings per second. I'm very pleased with that!

Regards,
David

Post Reply