Hello, I have an ESP32 microcontroller that has UART (TX and RX pins). I have them currently connected to a CP2102 (very common USB to UART converter chip). I then have a micro USB connected to the CP2102. This works great for flashing firmware, serial dubigging, etc.
I also have a Raspberry PI, which also has UART(TX and RX pins), that I would like connected to the same RX and TX pins of the ESP32 (has to be the same pins in this case - I cannot set up multiple separate UARTs in this project). Since I cannot have them both connected at the same time, I would like to be able to switch between the two.
Instead of using jumpers / dip-switches to switch between the two.... is there a way I can use the VBUS signal on the USB to trigger the switch? For example if a USB is plugged in, +5 volts will now be present on the VBUS pin, could this somehow be connected up to some transistors/mosfets, which disconnects UART from the raspberry PI, and connects UART with the USB port. If USB port is disconnected, then UART is disconnected from USB port, and is re-enabled for the raspberry pi.
This seems doeable, but I am a little confused on how to configure the transistors/mosfets to accomplish this. Any help or advice is greatly appreciated, thanks!
Here is a sketch of what I am trying to do:

I also have a Raspberry PI, which also has UART(TX and RX pins), that I would like connected to the same RX and TX pins of the ESP32 (has to be the same pins in this case - I cannot set up multiple separate UARTs in this project). Since I cannot have them both connected at the same time, I would like to be able to switch between the two.
Instead of using jumpers / dip-switches to switch between the two.... is there a way I can use the VBUS signal on the USB to trigger the switch? For example if a USB is plugged in, +5 volts will now be present on the VBUS pin, could this somehow be connected up to some transistors/mosfets, which disconnects UART from the raspberry PI, and connects UART with the USB port. If USB port is disconnected, then UART is disconnected from USB port, and is re-enabled for the raspberry pi.
This seems doeable, but I am a little confused on how to configure the transistors/mosfets to accomplish this. Any help or advice is greatly appreciated, thanks!
Here is a sketch of what I am trying to do:

Last edited: