Quicker reading from multiple DS18X20 sensors
Posted: 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.
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
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
First commit of ugly code here https://github.com/scudderfish/SFL525R/ ... FDS1820.py
Regards,
David