logo elektroda
logo elektroda
X
logo elektroda

[Solved] How to drive the two inputs (GPIO23 and GPIO22) on the ESP32 with an external signal?

krawietz 3903 9
Best answers LABEL_AI_GENERATED

Why does my PC817 optocoupler module not reliably switch ESP32 GPIO23/GPIO22 low from an external float signal, and why do both inputs sometimes change together?

The PC817 output is not being driven hard enough in your setup, so the phototransistor does not saturate and the GPIO never reaches a solid low level; measure the collector voltage and you’ll likely see that the “low” state is not low enough [#20080146] With your module and 10 kΩ pull-ups, 3.7 V from the battery is not sufficient, and the circuit only works when 5 V is applied to the optocoupler input [#20082012][#20082017] The module’s extra 3 kΩ series resistors on V1/V2 were also called out as something that can spoil the output stage, so removing/shorting them was suggested [#20081311] In short: the issue is insufficient LED drive/current through the optocoupler, not the ESP32 GPIOs themselves [#20080146][#20082012]
AI summary based on the discussion. May contain errors.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • Optocoupler wiring causes both ESP32 inputs to trigger

    #1 20080064
    krawietz
    Level 16  
    Posts: 273
    Help: 10
    Rate: 45
    I need to drive an external signal to two inputs on the ESP32 (specifically, I assumed the use of GPIO23 and GPIO22), and as these are two floats drowned in tanks of water, I found that I would use galvanic separation using a two-channel module with PC817 optoisolators. Generally on the 'short' it seemingly works. For testing purposes, I apply voltage (3.7V) from the 18650 battery to the input of the optoisolator module (the target is to have 5V through these floats - they act as a jumper depending on the position) and the output connected directly to the GPIO on the ESP32 and of course to ESP ground. Generally works.... until I put it together on a prototype board, wired, added connectors etc.... Then it turned out that one GPIO works correctly (we power up the optocoupler - the state changes) oh the other one triggers both.... That is, applying power to the second optocoupler causes both GPIOs to change state.... The same happens without the optocoupler if I short-circuit the GPIO directly to ground (briefly if I short-circuit only the pins on the ESP itself this does not happen). I added 10k pull-up resistors between GPIO and 3.3V and GPIOs shorted to ground work fine, the state only changes when the GPIO data is shorted to ground. The problem is that they have stopped responding if we feed a signal through the optocoupler. Applying power to the optocoupler input changes absolutely nothing about the state of the GPIO input. What have I done wrong?

    Tailor
  • ADVERTISEMENT
  • Helpful post

    Phototransistor may not pull GPIO fully low

    #2 20080146
    Anonymous
    Level 1  
  • #3 20080235
    mpier
    Level 29  
    Posts: 818
    Help: 153
    Rate: 141
    Hello,
    One problem is the lack of any schematic.
    krawietz wrote:
    The same thing happens without an optocoupler if I short the GPIO directly to ground (briefly if I short only the pins on the ESP itself this does not happen).

    This sentence is also a problem at first glance.

    Greetings.
  • ADVERTISEMENT
  • Prototype board leakage causing strange resistance readings

    #4 20080663
    krawietz
    Level 16  
    Posts: 273
    Help: 10
    Rate: 45
    Target diagram below. I will actually check the power supply, as the target is supposed to be 5V.
    How to drive the two inputs (GPIO23 and GPIO22) on the ESP32 with an external signal? .
    Of course the yellow jumpers removed so that the input side ground is separate from the ESP ground.

    I also have 24V AC available in the circuit, supposedly some documentation for the module says that 3.3 - 24V can be applied to the input - there is a 3k resistor in series and a signalling LED. There is also a 3k resistor in series between outputs V1 and V2 and the collector.
    Another thing is that the possibility of using 24V AC would simplify the whole circuit and eliminate an additional power supply.

    Krawietz

    Added after 10 [minutes]:

    mpier wrote:
    krawietz wrote:
    The same thing happens without the optocoupler if I short the GPIO directly to ground (briefly if I short only the pins on the ESP itself this doesn't happen).
    The same thing happens without the optocoupler if I short the GPIO directly to ground (briefly if I short only the pins on the ESP itself this doesn't happen).
    This sentence is also a problem at first glance.


    This worries me a bit...
    I assembled the whole thing on a prototype board .... of this type...
    How to drive the two inputs (GPIO23 and GPIO22) on the ESP32 with an external signal? .
    Goldpin sockets soldered into the board so that the ESP can possibly be removed....
    Plus connectors for wiring about this type:
    How to drive the two inputs (GPIO23 and GPIO22) on the ESP32 with an external signal? .
    All intricately connected with single-wire cables....

    And this is where it gets interesting... The ohmmeter e.g. on adjacent pins whether goldpin socket or those for cables sometimes shows some strange resistance.... several kilo ohms... several hundred... The fields themselves in the contact board do not show such miracles.... neither do the cable connectors... And after soldering some strange stories.... All in all, I don't know if these Chinese boards soak up residual flux from the tin and make a resistor or if my ohmmeter is going crazy....

    Krawietz
  • #5 20080699
    Anonymous
    Level 1  
  • PC817 is a poor fit for industrial input isolation

    #6 20081104
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #7 20081122
    Anonymous
    Level 1  
  • #8 20081311
    starob
    Level 29  
    Posts: 1088
    Help: 128
    Rate: 137
    krawietz wrote:
    There is also a 3k resistor in series between the V1 and V2 outputs and the collector.


    Solder them out and short the pins, they spoil the whole job. The 10k pullup (+ internal pullup of the proc?) can cause the output voltage to be too high. Have you measured the voltages on the GPIO ? - this could be a clue.
  • ADVERTISEMENT
  • 3.7 V battery too low for optoisolator drive

    #9 20082012
    krawietz
    Level 16  
    Posts: 273
    Help: 10
    Rate: 45
    starob wrote:
    krawietz wrote:
    There is also a 3k resistor in series between the outputs of V1 and V2 and the collector.


    Solder them out and short the pins, they spoil the whole job. The 10k pullup (+ internal pullup of the proc?) can cause the output voltage to be too high. Have you measured the voltages on the GPIO ? - this could be a clue.
    .

    Voltages ok, 3.1V on GPIO....
    However, a 3.7V battery is not enough for the optoisolator to work properly in this configuration.
    When 5V is applied, everything works correctly.

    Krawietz
  • 3.7 V battery too low for optoisolator input

    #10 20082017
    krawietz
    Level 16  
    Posts: 273
    Help: 10
    Rate: 45
    starob wrote:
    krawietz wrote:
    Between the outputs of V1 and V2 and the collector is also a 3k resistor in series.


    Solder them out and short the pins, they spoil the whole job. The 10k pullup (+ internal pullup of the proc?) can cause the output voltage to be too high. Have you measured the voltages on the GPIO ? - this could be a clue.


    Voltages ok, 3.1V on GPIO....
    However, a 3.7V battery is not enough for the optoisolator to work properly in this configuration.

    When 5V is applied to the optoisolator input from the power supply, the circuit works correctly.

    Krawietz
  • Topic summary

    LABEL_AI_GENERATED
    The discussion revolves around driving GPIO23 and GPIO22 on the ESP32 using an external signal through galvanic isolation with a PC817 optoisolator. The user encountered issues where one GPIO functioned correctly while the other triggered both GPIOs simultaneously. Suggestions included measuring the voltage on the phototransistor's collector, checking the power supply voltage, and considering the use of a low-pass filter or alternative optocouplers for better performance. The user confirmed that a 3.7V battery was insufficient for the optoisolator, and proper operation was achieved with a 5V supply.
    AI summary based on the discussion. May contain errors.
    ADVERTISEMENT