-
Notifications
You must be signed in to change notification settings - Fork 3.1k
DS18Bb20: broadcast CONVERT_T to parasite powered devices #3683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Ideally this should be reviewed by the original author @vsky279. |
|
(needs a rebase as well) |
|
Hi caiohamamura, I'm pretty sure I needed to implement this code to make it work for larger number of parasite powered devices few years ago. So I suggest to make the simplification optional. -- Add a config flag
local ds18b20 = {
use_fw_pullup = false, -- default: keep old behavior
...
}
conversion = (function (self)
local sens = self.sens
if self.use_fw_pullup then
-- simplified variant: trust firmware's strong pull-up
debugPrint("starting conversion: all sensors (fw pullup)")
ow_reset(pin)
ow_skip(pin)
ow_write(pin, CONVERT_T, MODE)
for i, _ in ipairs(sens) do status[i] = 1 end
tmr_create():alarm(750, tmr_ALARM_SINGLE, function() return readout(self) end)
else
-- old fallback code (your original handling of parasite vs powered)
debugPrint("starting conversion: per-sensor (manual parasite handling)")
return old_conversion(self)
end
end) |
|
Yes, on second thought it would be better if we delegate that decision to the user itself. As stated by the datasheet it can consume up to 1.5mA, so if we consider the esp 8266 datasheet that says it can provide up to 12mA, the maximum parasite powered at the same time would be exactly 8, but considering other possible sources of loss such as wire resistance+its length it would probably be safer to assume 7 sensors or even less. That said, it makes sense that your configuration using 8 sensors would not work. In that scenario the user should follow the recommendation from the datasheet and use a MOSFET for controlled by another gpio port to control the strong pull-up for feeding the sensors. Actually in Arduino Framework DallasTemperature library they assume the user will make that configuration when parasite power and the user is required to setup the pin number which is connected to the strong pull-up on initialization of the library. It would probably be better to document those contraints within the nodemcu documentation itself, because I myself struggled a little bit, maybe the library should give more control to the user and split sending the CONVERT_T command function and reading the temperatures, and that function needs to be very simple and quick so that the user can still use a gpio controlled pull up if needed, because as the datasheet states:
I don't even think in lua we can provide that 10µs at most delay, maybe that would require a C module or tweaking one wire to allow controlling a second pull-up pin. |
|
Thanks for the clarification. I see your point and it makes sense – especially the current limitation and the 10µs requirement from the datasheet. From my side, I’d prefer to keep the module simple and backward compatible. That’s why I proposed to add the If you believe the module should also expose a lower-level API (e.g. splitting CONVERT_T from the readout, or supporting an external MOSFET pin), please feel free to propose such modification – I’m not planning to implement it myself. |
Fixes #3682.
devbranch rather than for thereleasebranch.docs/*.This PR will remove the special handling for parasite powered devices, because
ow_writeis already able to correctly handle the strong pull-up required by the DS18B20 and will return to its usual state when issuing newowoperations.Testing
During testings I parasitic powered two different sensors with a 1m length cable each: pins 1 and 3 are GND and pin 2 directly connected to pin=7 (D7) of a NodeMCU.
I uploaded the ds18b20.lua and the following init.lua:
Opened the serial monitor and everything is working as expected, printing every ~750ms.