Closed osresearch closed 2 years ago
Why do you need open drain for a mosfet? When you switch the pin to INPUT, the mosfet gate will be floating.
I'm confused, why would you need open-drain for driving a MOSFET? I run lots of ESPhome lights using ESP32's and use the following:
output:
light:
This works perfectly as is with the correct MOSFETs (and/or MOSFET gate drivers). It allows for on/off, dimming, etc.. You should not be doing any lambda or pin mode switching?
Maybe I'm missing something, try my code. :)
I'm interfacing the ESP with an existing device: a big-switch shaped nightlight with a binary tilt sensor and several high power LEDs that are low-side switched via an open-collector MOSFET. The original design had the tilt sensor wired directly to the MOSFET and ground. In one orientation the sensor let' the pin float, which turns off the LEDs; in the other orientation it shorts the pin to ground and turns on the LEDs When the ESP drives the pin to 3.3v in the normal PWM mode, it causes the MOSFET to not turn off all the way so it doesn't dim.
But then why not connect the "switch" to a binary input (add a pull-high to 3.3v so you always have a defined state) and then use that as the digital signal to drive the MOSFET connected to the ESP32 board. So transforming the switch input to a logical on/off signal and then driving the MOSFET the regular way, no open-drain or floating ways used.
That would solve all problems I'd think?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Operating environment/Installation (Hass.io/Docker/pip/etc.):
esphome
1.16.2 installed viapip3
on ubuntu 20.04ESP (ESP32/ESP8266, Board/Sonoff):
esp32cam board
ESPHome version (latest production, beta, dev branch)
1.16.2
Affected component:
ledc
Description of problem:
The ledc component switches the pin mode to output, so a pin configured as
OUTPUT_OPEN_DRAIN
will not behave correctly. When used as a binary lamp, this works fine for turning on and off an external MOSFET:However, when it is switch to use the
ledc
output platform the pin is switched back toOUTPUT
and the dimming does not work correctly. The problem might be in the underlying call toledcAttachPin()
, as discussed here: https://esp32.com/viewtopic.php?t=15783I can add a
lambda
that switches it to open drain when turning the lamp on, and this works for dimming, but is unable to turn the lamp off. I thought perhaps adding an explicit switch back to input mode would work, but that leaves it in a flickering state.Problem-relevant YAML-configuration entries:
Logs (if applicable):
Additional information and things you've tried: