Electronic – How to construct a switch that would switch between two USB outputs, controlled electrically

controldpdtusbusb device

Basically I have a Smart TV, Raspberry Pi connected to it and wireless mouse and keyboard, using a single dongle for connection. What I would like to achieve is to being able to remotely switch where dongle is connected, to be able to operate both devices alternately.

In my research I found a concept of DPDT switch that seems to be exactly what I need, for 4 USB pins, but that switch would have to be remotely controlled. The remote part is out of the scope of this question, I just need something that I could send a signal to from my RPi through one of its pins to change output target of dongle.

I could find pretty much only manual DPDT switches, and I need something that I could control electrically. Would be difficult to build it? Could someone help me with a schematic? I'm willing to try.

Best Answer

I have worked with a USB switch, and it's not as simple as it first seems. My first job at a new company was to debug why some of their USB switches were failing. The switch involved a 4 pole changeover, as you're describing. The symptom was that the PC froze about one in 10 switch events, on some of the switches. The switches appeared electrically identical, as did the switching events. The breakthrough came when we switched from XP to win7, and the failure ratio changed, was it a detailed timing interaction with the drivers?

USB is designed for human connection and disconnection, which means slow, and the software drivers tend to have been written making this assumption. The connectors are designed with long and short pins so that power goes on first and off last.

Rather than whipping all four pins from one device to another, something the driver will not have been designed or tested for, you are much more likely to get success if you use discrete 2-pole relays to perform a simulation of the human disconnect-connect sequence. In four separate steps, break data then break power to the old device, wait for a few seconds, then make power then make data on the new device.

In retrospect, what was surprising about the 4 pole switch was that it worked as often as it did. It worked well enough to lull everyone into a false sense of security.