robert-hh / Onewire_DS18X20

Classes for driving the DS18x20 sensor with the onewire protocol for Pycom MicroPython
11 stars 6 forks source link

Avoid scan single #20

Open MauroDiamantino opened 1 year ago

MauroDiamantino commented 1 year ago

It was added the option to avoid roms scan in ds18x20_single.py

robert-hh commented 1 year ago

Thank you for the PR. What is the benefit expect from the PR? The device scan is only performed once when instantiating the DS18X20 object. The access to a single device is not substantially faster, only you do not have to handle the list of device numbers.

MauroDiamantino commented 1 year ago

You're welcome. You're right, this PR is not intended to improve speed, but to improve noise robustness. I installed a DS18B20 sensor in high voltage transformer and I used a ESP32 board to get measurements. At the beginning, the intense electrical noise made the ESP32 board to periodically reboot because it wasn't able to scan roms. Avoiding the scan the ESP32 was able to directly enter in the measurementes captures loop, where some measurements are affected by noise but there is no problem because the board just retries the reading.

robert-hh commented 1 year ago

made the ESP32 board to periodically reboot because it wasn't able to scan roms

That is hard to understand. Scan is like Read and Write a transaction on the DS18X20 bus. It may fail or cause a exception, bat that should not cause the ESP32 to reboot.

MauroDiamantino commented 1 year ago

Sorry, I didn't explain myself very well. The electrical noise wasn't doing the ESP32 to reboot, the problem was that the __init__() function sometimes failed because of the roms scanning failed affected by the noise. You can just retry DS18B20Single object initialization, but that's not tipical implementation (even examples try initialization just once). So, following the priniple "the simpler, the more robust" I think it is better to avoid rom scan (which is uneeded) to avoid exception in the initialization.

robert-hh commented 11 months ago

I'm not inclined to merge that PR. It increases the code without adding substantial functionality. And code size matters, especially at boards with a small heap like the ESP8266 or SAMD21.