Join 3,556 readers in helping fund MetaFilter (Hide)


Help me do the old USB switcheroo
May 17, 2011 6:28 AM   Subscribe

I can't quite get to the bottom of a USB peripheral auto-switching circuit diagram.

Here's the scenario: I'd like to share a USB hard disk enclosure between two devices - a media player and a games console. Since only one device will be in use at a time, I need a USB switch of the sort people sometimes use to share printers - here's one for sale on Amazon UK.

But, since I'm a cheapskate, and since I have drawers full of electronic components - it's a fairly recent hobby - I'd like to build my own automatic USB switch. The plan is to use the +5V from the USB input of device B to activate a relay, switching the disk to that device. When the device is unplugged, the relay switches the disk back to device A.

I found a circuit - here it is - that appears to do what I want. After puzzling for a minute over the extra connections on the USB sockets I'm guessing that 5 and 6 are the spare ID pin found on mini-USB and the shielding on the cable, both to be connected to ground. Right?

What I don't understand, however, is why it's only the D+ and D- that are being switched. Shouldn't I be using a 3PDT relay and switching the +5V as well? What am I missing?
posted by le morte de bea arthur to Computers & Internet (13 answers total) 1 user marked this as a favorite
 
No need to switch the +5V, you keep both USBs supplied with voltage all the time, and just switch the data.
posted by orthogonality at 6:39 AM on May 17, 2011


Yeah I suppose in this case I'd hard wire K1's 5v to K3's, since the idea is that K1 is always there and K2 just plugs in every now and again. Since there's no difference between 5v from one or the other, why switch it (3 way switches are also much more expensive than 2)
posted by RustyBrooks at 8:11 AM on May 17, 2011


Since there's no difference between 5v from one or the other...

Don't be too sure about that. There could be a small difference, and hooking them together isn't a very good idea. Powering the child from one while talking to another could result in non-trivial current flow.

I agree with the OP: you really should switch the power as well as the signal.
posted by Chocolate Pickle at 10:49 AM on May 17, 2011


(Note: IANAEE.)
posted by Chocolate Pickle at 10:51 AM on May 17, 2011


Since there's no difference between 5v from one or the other...

I assume that both appliances are grounded, so it'll be close but the USB specification allows some deviation from +5v exactly. You don't want current flowing between the appliances. This is analogous to a ground loop and may cause reliability issues or equipment damage.
posted by atrazine at 12:25 PM on May 17, 2011


You do want to switch over the VBUS signal (+5V) as well. The VBUS sense input on the peripheral (hard drive enclosure) does use that to determine when the host is plugged in or unplugged. Most USB peripherals probably won't work if you don't have the pin 1 on K3 hooked up to anything like it is shown in the schematic. It should be connected to VBUS.
posted by thewildgreen at 1:57 PM on May 17, 2011


Thanks. Switching the VBUS signal seemed logical to me too, but I wasn't sure whether there was some special reason not to that I'd overlooked.

So now I need to find a 3PDT relay. Only problem is, I can't find one with a 5V coil; they all seem to be big clunky 12V or 24V power relays. Maybe that's why the circuit used a DPDT...

Would I get away with using two relays (a DPDT for the data, plus a SPDT for the +5V)? Or would the fact that the relays don't necessarily switch over in perfect sync be likely to cause problems?

[Sorry to peg this on to the original question, but in my defence it's part understanding how to get this circuit thing to work in practice].
posted by le morte de bea arthur at 11:37 PM on May 17, 2011


It is probably difficult to find a multi-pole relay with a 5V coil. Using two relays might work, but there is a small chance that the timing difference could affect the USB enumeration operation. You can try it out on a breadboard if you have all the components. If you run into issues, try switching the D+ / D- first, and then switching the VBUS a short time later.

P.S. If I were you, I'd buy that cheap little accessory that you had linked in your original question and be done with it. Pick your battles etc etc :)
posted by thewildgreen at 9:06 AM on May 18, 2011


Have you looked into "solid state relays"?

They're inherently single-pole, but maybe you can work around that by using twice as many.
posted by Chocolate Pickle at 4:05 PM on May 18, 2011


If you run into issues, try switching the D+ / D- first, and then switching the VBUS a short time later.

DON'T DO THAT. it's exactly wrong - you need to disconnect the signalling lines, disconnect the power circuit, reconnect the power circuit, and then reconnect the signalling lines. (well perhaps you can get away with doing them at the same time, but it's forbidden in the USB spec).

if you look at standard USB connectors, you'll see that VBUS and GND are longer than D+ and D-. since the power circuit is completed a small amount of time before the data circuit is, this allows the device controller to have powered up and be stable before it's attached to the data bus, which is required in order for the device to negotiate data rates and power requirements with the host controller.

it's also worth noting that USB devices specifically negotiate their power requirements with the host. your second computer may not appreciate having a device claim to need only a small current allowance, but actually draw enough juice to actuate a physical relay.
posted by russm at 1:38 AM on May 19, 2011


This is getting complicated.

Maybe I could use an electromechanical relay to switch the D+/D-, and a solid state relay for the power circuit. That way the power circuit is pretty much guaranteed to connect first, even if the disconnection order is wrong.

Oddly enough, there appear to be devices on the market that allow USB devices to be shared by simply switching the connection over via a 3pdt break-before-make rotary switch. Although since these devices are sold as 'printer sharing' switches, the requirements about order of breaking and making connections may not be as relevant.

I'm tempted to just wire a simple manual switch and see how it performs with the setup I have, and then maybe try something with a breadboard and relays later. Or perhaps do something more complicated in terms of making/breaking contacts by controlling the switching via a PIC or AVR.

Thanks for all the help everyone. I feel like I'm learning something, even if the problem isn't 100% solved.
posted by le morte de bea arthur at 2:09 AM on May 19, 2011


it wouldn't surprise me if, in practice, you can get away with connecting power and signalling at the same time (particularly if it's solid-state switching where contact bounce isn't a problem).

one other possibility that springs to mind - since a relay will mess with power negotiation, and the 3pdt relays you have are 12V, you could power the switch from 12V. give the box a 12V power brick that will actuate the relay, use a voltage divider to get 5V out of that and into the hard drive, ignore the 5V from the primary host, and just use the 5V from the secondary host to drive a solid state switch that then controls the 12V to the relay. the hosts won't care if the device claims to need 500mA but actually draws less than 100.
posted by russm at 2:40 AM on May 19, 2011


If you run into issues, try switching the D+ / D- first, and then switching the VBUS a short time later.

russm: DON'T DO THAT. it's exactly wrong ...

russm is right. I actually wanted to say it the other way around, but got messed up while writing it out. Even if you go with russm idea of driving the relays externally using a 12V power brick, I'd still recommend switching and connecting the VBUS signal from the host to the hard disk. This signal is essential for most USB peripherals to work even if the peripheral is self-powered (powered by wall power as opposed to USB powered).
posted by thewildgreen at 1:44 PM on May 20, 2011


« Older A vacation in Colorado: where ...   |  A friend recently got a job of... Newer »
This thread is closed to new comments.