timofurrer / w1thermsensor

A Python package and CLI tool to work with w1 temperature sensors like DS1822, DS18S20 & DS18B20 on the Raspberry Pi, Beagle Bone and other devices.
MIT License
493 stars 113 forks source link

Changing resolution DS18B20 doesn't change speed #73

Closed PieterHeri closed 4 years ago

PieterHeri commented 4 years ago

Hi,

For a master's project I need to read two DS18B20 sensors for 30 seconds as much as possible. The 12 bit resolution takes ~750ms, so with two sensors it takes 1.5 sec for a measurement. To be quicker I changed the resolution to 11 bit ($ sudo w1thermsensor resolution --hwid 0114556f64aa --type DS18B20 11).

The accuracy of the sensor went down, but the speed of the readings doesn't improve. I can see on the specifications of the DS18B20 that the speed of a 11 bit reading should be ~375 ms instead of ~750 ms.

Why doesn't the sensor speed go down? Do you have a tip to get the sensor readings quicker? I am using w1thermsensor 0.3.2 and to get a reading I just try 'sudo w1thermsensor all' in the terminal.

Thanks in advance

bsimmo commented 4 years ago

I can't say why as I don't know.

But you also need to look at some sort of threading and asking for the two readings one after the other and then reading the response. You'll get both results in a second or less.

Much harder to code though, I had some code but no idea where I out it.

On Thu, 5 Mar 2020, 1:25 pm PieterHerings, notifications@github.com wrote:

Hi,

For a master's project I need to read two DS18B20 sensors for 30 seconds as much as possible. The 12 bit resolution takes ~750ms, so with two sensors it takes 1.5 sec for a measurement. To be quicker I changed the resolution to 11 bit. The accuracy of the sensor went down, but the speed of the readings doesn't improve. I can see on the specifications of the DS18B20 that the speed of a 11 bit reading should be ~375 ms instead of ~750 ms.

Why doesn't the sensor speed go up? Do you have a tip to get the sensor readings quicker? I am using w1thermsensor 0.3.2 and to get a reading I just try 'sudo w1thermsensor all' in the terminal.

Thanks in advance

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/timofurrer/w1thermsensor/issues/73?email_source=notifications&email_token=ACYAXN53GP2HMMKU5PZBRB3RF6R3FA5CNFSM4LCJ3NT2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ISY43EA, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYAXN6CE37JEKIDCOEGVOTRF6R3FANCNFSM4LCJ3NTQ .

timofurrer commented 4 years ago

w1thermsensor 2.0 (current master) provide an AsyncW1ThermSensor class which supports the async / await interface to read temperature. I've added some examples here: https://github.com/timofurrer/w1thermsensor/tree/master/examples

You could also just use whatever release you have right now and read the temperatures from two different threads (keep in mind that Python has a GIL)

Generally, w1thermsensor has little overhead to read temperatures - also keep in mind that Python is rather slow and therefore probably not suited for real-time applications - thus, the speed is mostly dominated by the time it takes to read the sensor files from the kernel modules.