1
\$\begingroup\$

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.

\$\endgroup\$
11
  • \$\begingroup\$ There are DPDT relays too. The relay coil (electromagnet) draws more current than a processor pin can provide and may be the wrong voltage too so you will have to use a transistor as an intermediary between the pin and the relay coil. I don't know how sensitive USB is though to just sticking random conductors mid-cable. There are also analog switches instead of relays, but I have the same signal integrity issues. \$\endgroup\$
    – DKNguyen
    Feb 7, 2020 at 21:02
  • \$\begingroup\$ Hate to be the person who doesn't give a circuit, but have you considered buying one that is already done...? Sabrent sells a USB switch for less than 20$. You'd just need to figure out how to remote control it though. amazon.ca/Sabrent-Computers-Peripherals-Indicators-USB-SW20/dp/… \$\endgroup\$
    – Natsu Kage
    Feb 7, 2020 at 21:15
  • \$\begingroup\$ @NatsuKage Actually it didn't occur to me. Probably because I'm into experimenting with electronics lately and just wanted to build something :) . Interesting idea, I think I would rather like to build my own thing for learning purposes though, if it would be possible. But time/price wise it seems to be indeed a better option to just upgrade the existing solution. Thanks! \$\endgroup\$ Feb 7, 2020 at 21:52
  • \$\begingroup\$ @DKNguyen Can these relays keep their state? Or would I need an additional microcontroller for that? I'm also interested if they could be used with USB. Maybe someone with some experience will answer. \$\endgroup\$ Feb 7, 2020 at 21:52
  • \$\begingroup\$ If you lose power, the relays will enter a default state. They are just mechanical contacts held by a spring that is overcome by an electromagnet after all. You need latching relays if you want to mantain a state without power. \$\endgroup\$
    – DKNguyen
    Feb 7, 2020 at 21:57

1 Answer 1

5
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ That's an amazingly informative insight, thank you, it will probably save many people a lot of time. \$\endgroup\$ Feb 8, 2020 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.