-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
OneWire timing issue #4116
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
Comments
I used the same combination (Wemos d1 Mini and DS18B20's) with that sample script without any problems. Over days, I have not seen any suspicious value. So I have one question: did you install the 4.7 kOhm resistor between the data line and Vcc of the DS18B20 sensor? Or maybe you have an defective sensor, or the connecting wire is too long, creating a larger capacitive burden. Side note: Questions like this are better discussed at the forum: http://forum.micropython.org/ |
Yeah, I tried with and without the 4.7kOhm resistor, tried powering from both 3.3V and 5V. Maybe I have some wrong DS18b20 (tried two, but from same shop - maybe some clones or whatever). My point is that MicroPython doesn't adhere to the datasheet (that says 15-60us), I think it means at least 60us to be sure. Here are a couple more 1-wire implementations: There seem to be quite big consensus on 70us. Is there any reason why MicroPython uses 40us? |
Looking at my devices here, the slave responds within 30 µs and pulls the line down for 120µs. Since the maximum response time of the slave is 60µs, it is indeed more safe to wait a little bit longer, like 70-80 µs. |
There is a bug in in the library. However in the sourcecode of micropython the delay is set to 40us. |
OK, here are the details: |
Thanks for the report about this, and for tracking down the issue. The fix to change the delay from 40us to 70us was done in 4904663 I tested it on a PYBv1.0, esp8266 and esp32, and it works for me with the new timings. |
I'm trying to use MicroPython on Wemos D1 mini (esp8266) to read temperature from DS18b20 sensor.
Reading values from this sensor is very unreliable for me. I get the temperature like once in 20 attempts to read the temperature. Other reads thrown an
OneWireError
exception duringOneWire.reset(True)
method or no device was found. This is the code I used (from the MicroPython docs):I tried flashing Arduino to the same board with same sensor and it worked flawlessly.
I compared source codes for both 1-wire libraries and discovered one difference:
The second sleep in the reset function is 40us for MicroPython, but 70us for Arduino.
Sources:
Arduino: https://github.com/PaulStoffregen/OneWire/blob/master/OneWire.cpp#L187
MicroPython: https://github.com/micropython/micropython/blob/master/extmod/modonewire.c#L37
So I tried following monkeypatch to use the timings from Arduino:
With this, I get the correct readings every time. There's also different number for the 3rd sleep, but that doesn't seem to matter.
I found that master should wait 15-60us after reset before reading slave presence signal:
https://datasheets.maximintegrated.com/en/ds/DS18B20-PAR.pdf (page 13) and then it has 60-240us to read the presence (I hope I interpreted the datasheet correctly).
TLDR: I think the second sleep time should be changed from 40us to 70us.
The text was updated successfully, but these errors were encountered: