Sinking Current with ESP8266 [SOLVED]
Posted: Mon Jan 15, 2024 3:04 pm
Hi.
I am experimenting with an 2n7000 mosfet and a d1 mini pro (esp8266). My code toggles between the LED_BUILTIN and an external LED on pin D5 (alternating the LEDs). I am trying to drive the external LED with the 2N7000 using the circuit below.
(Note "muc" --> "mcu"
My understanding of this circuit is that:
[*] when the D5 is LOW, there will be a voltage across the gate and source which will turn ON the mosfet causing current to flow from the drain to the source -- turning the external LED OFF.
When the DE is HIGH, there will be no voltage across the gate an source which will turn OFF the mosfet causing the current to flow thru the external LED -- turning the external LED ON. [*]
If I set pin D5 to output (using pinMode(D5, OUTPUT)), the LED is continuously ON -- meaning that the mosfet never turns ON. This suggests to me that the D5 pin is not sinking current when LOW as an output.
Alternatively, if I set pinMode(D5, OUTPUT_OPEN_DRAIN), then the circuit behaves as I anticipated -- taggling LED_BUILTIN and the external LED.
My question: Did I misunderstand the behavior of a an output pin when LOW? I had expected D5 to to sink current (behave like an open-drain) when LOW as OUTPUT.
I am experimenting with an 2n7000 mosfet and a d1 mini pro (esp8266). My code toggles between the LED_BUILTIN and an external LED on pin D5 (alternating the LEDs). I am trying to drive the external LED with the 2N7000 using the circuit below.
(Note "muc" --> "mcu"
My understanding of this circuit is that:
[*] when the D5 is LOW, there will be a voltage across the gate and source which will turn ON the mosfet causing current to flow from the drain to the source -- turning the external LED OFF.
When the DE is HIGH, there will be no voltage across the gate an source which will turn OFF the mosfet causing the current to flow thru the external LED -- turning the external LED ON. [*]
If I set pin D5 to output (using pinMode(D5, OUTPUT)), the LED is continuously ON -- meaning that the mosfet never turns ON. This suggests to me that the D5 pin is not sinking current when LOW as an output.
Alternatively, if I set pinMode(D5, OUTPUT_OPEN_DRAIN), then the circuit behaves as I anticipated -- taggling LED_BUILTIN and the external LED.
My question: Did I misunderstand the behavior of a an output pin when LOW? I had expected D5 to to sink current (behave like an open-drain) when LOW as OUTPUT.