← index #5696Issue #6634
Off-topic · high · value 2.758
QUERY · ISSUE

esp8266: open drain PWM?

openby osresearchopened 2020-02-25updated 2020-03-03
port-esp8266

When driving a high-side switching transistor with an external pull-up resistor the Pin.OPEN_DRAIN output works well (with negative logic, so grounding the output turns it on and letting it float turns it off). The PWM module however has a comment that it explicitly disables the open drain, which prevents the transistor from being able to fully turn off: https://github.com/micropython/micropython/blob/master/ports/esp8266/esppwm.c#L387

Is there a reason to do this rather than leaving the pin in the mode configured by the python code?

CANDIDATE · ISSUE

@larsks Thanks for taking the time to do bisect to track down the commit. I can see how that commit might have affected the DHT driver.

closedby ViniciusClementopened 2020-11-19updated 2025-10-15
proposed-close

@larsks Thanks for taking the time to do bisect to track down the commit. I can see how that commit might have affected the DHT driver.

Unfortunately I can't reproduce the problem. On an Adafruit Huzzah Feather the DHT code above works just fine for me, on pins 4, 5, 12, 13, 14, 15. First and subsequent measures all work.

I suspect it's an issue with pulling up the DHT's data line. Since it's an open drain pin it should be pulled up to high with a resistor, say 10k Ohm. You can do this with an external resistor, or try the internal one on the esp8266 via:

d = dht.DHT22(Pin(4, Pin.IN, Pin.PULL_UP))

The reason it might have worked before without a pull-up is because the esp8266 pin was glitching when set to open-drain-high and driving the line high for a brief moment, which would have put enough charge on the wire to make it act like it was pulled high. Now it doesn't do that so there needs to be a resistor pulling it up.

Originally posted by @dpgeorge in https://github.com/micropython/micropython/issues/4233#issuecomment-430459734

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied