MCP23017 switch between high impendance and gnd

I am fiddling with a remote control. My hardware is ESP32 board and MCP23017 expander.
The required functionality is to switch pin from high impendance to ground for preset amount of time. How can I achieve this? The open_drain option doesn’t seem to be implemented.

Might be not possible. What’s the application? Diode could be used?

Or a resistor driving the base of a transistor

1 Like

There is a wall mounted remote control. When a physical button is pressed, a pad is connected to gnd, otherwise the pad is left floating
I am trying to control that remote with ESP32. I don’t want to apply any voltage on that pads, since it might damage the actual remote.

Driver with NPN resistor would be an option, but I wonder whether this can be achieved with sole coding.

Yes if you use esp32 gpio pin instead od mcp.
Otherwise diode, transistor, mosfet…
I personally prefer optocoupler.

So what’s the operating voltage of that remote?

I don’t have enough gpio pins, hence the mcp23017.

Remote is running on 3V.

3V battery has fully charged voltage ~3.3V, so I wouldn’t hesitate to connect it directly to esp32 or MCP at 3.3V.

If that’s not in your comfort zone, add optocoupler there.
Original remote button circuit:

Esp driven button circuit:

Or put just Schottky diode in series…

I’ve never needed the MCP port expander outputs to be Hi-Z, but if you switch the pin to input, the output will be Hi-Z. When you need to drive it, switch it to output.

How you do that dynamically in esphome?

But this is the option for MCP23017:

mode (Optional, string or mapping): Configures the pin to behave in different modes like input or output. The default value depends on the context. Accepts either a shorthand string or a mapping where each feature can be individually enabled/disabled:

  • input (Optional, boolean): If true, configure the pin as an input.
  • output (Optional, boolean): If true, configure the pin as an output.
  • pullup (Optional, boolean): Activate internal pullup resistors on the pin.
  • pulldown (Optional, boolean): Activate internal pulldown resistors on the pin.
  • open_drain (Optional, boolean): Set the pin to open-drain (as opposed to push-pull). The active pin state will then result in a high-impedance state.

EDIT: well, datasheet says output’s are push-pull, so perhaps it’s not possible “by design”. Try and see, but if it’s not i’d just add, say, uln2003 (or uln2803) to outputs. ULN has open-collector outputs.
I always add uln to my MCP’s - for higher current, if nothing else.

I totally disassembled and analyzed the remote. You are right, there is a pull-up on every button. I guess there would be no problem if I simply switch the pin between high and low state.

Technically schottky or optocoupler approach is correct and still dead simple.
I’m lazy, so I probably would go straight without.
But when the battery goes low in charge, let’s say down to 2.7V, applying 3.3V to remote MCU gpio pin might violate the specs…

Edit: but you didn’t confirm how that remote is actually powered and what’s the voltage, so if you want any good suggestions, please post more info.

It would be powered with 3.3V from PCB with the ESP32. (Not the 3.3V pin on ESP board, but an external regulator) Batteries will be eliminated.

Ok then.
Just be aware that if your “external regulator” ever fails, undesired current path there will be. If the whole setup (including esp) is powered from same regulator, there’s no problem.