I have a homework to use D0(GPIO16) of nodeMcu as input on DS18b20 (onewire), but it does not work.
I tried using d1,d2,d3 instead and that worked fine. I have a resistor pullup to 3.3v.
Any ideas on how to make that work with D0? Do I need to make some specific setup?
io 16 is a pin of the internall RTC of the esp8266. so the access is slower.
GPIO16 (D0) is also shared with "LED_BUILTIN_AUX" so whatever that is may be interfering.
random nerd tutorials explains that GPIO16 is not interrupt cabable
So I took a look inside onewire.cpp:
a lot of calls to
nointerrupts();
and
interrupts();
so my guessing is: the onewirepin must be interruptcapable
as GPIO16 can't invoke interrupts this would require to write high reponsive code
that does nothing else than polling GPIO16.
depending on how precise the text of your homework is written
you could present the solution
"not possible due to non-interrupt-capability of GPIO16"
So maybe a timer-interrupt that is polling fast enough for the onewire-protocol could be a solution.
best regards Stefan
Assuming you are using the standard ESP8266 Onewire library from Paul Stoffregen, then the issue is not related to interrupts.
nointerrupts(); and interrupts(); are used around sections of code with critical timing, to stop other interrupt sources from interrupting the carefully timed sections of code.
The Onewire library uses direct register access to GPIO to make the timing more accurate. The problem with ESP8266 GPIO16 (D0), is that it uses a different set of registers from the other 16 GPIO (GPIO[15:0]). The library uses a couple of macros to convert the pin number to the direct register accesses and for pin 16, it gets it wrong.
Fortunately, someone has provided a fixed library. Unfortunately the fixed library has not had the testing required to allow Paul Stoffregen to integrate it into the official OneWire library.
So you can use it at your own risk. I am using it with DS18B20 on pin GPIO16 (D0) and have had no issues.
The pull request on github can be found here Updated ARDUINO_ARCH_ESP8266 pin definition to allow use of GPIO16 by gnalbandian · Pull Request #88 · PaulStoffregen/OneWire · GitHub
It only changes one file "util/OneWire_direct_gpio.h"
The hack is to edit the library on your local system by replacing this library file with the new version.
The issue would be if you every update the Onewire library, the fix would be blown away.
The better fix would be to make the updated Onewire library file, part of your project and not a library.
Have fun,
Ray
Thanx, Ray!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.