eagspoo eagspoo - 6 months ago 38
Android Question

Disconnect USB using software controlled relays?

For debugging and testing an android device that connects to a custom USB peripheral, we'd like a software controlled way to unplug and replug the USB.

It looks like USB cables have 4 wires so I'm thinking if the specific device I need doesn't exist (I haven't found it) all I really need is a software controlled 4-channel switch so I can just cut the USB cable in half and plug the wires from each side into the switches, and open/close the switch using software.

Sane so far?

I looked around and found devices like this: https://www.amazon.com/SMAKN-Channel-Programmable-Computer-Control/dp/B01KWTL0BQ/.

Here is a diagram of how I imagine this would work:

example diagram

A couple things I'm not clear about:

  • Will this add too much load to the USB +/- signal wires so the timing is messed up and it won't work?

  • Is a relay really a "switch" in the sense I'm hoping for where it just closes an unbuffered circuit I can drive a signal on both directions as required to be inserted into the middle of a USB cable?

In short, should I buy this thing and go for it or is there some critical flaw in this approach?



This will work (as with all things: if done correctly!).

The relay on that board is a hardware relay; when closed, it is electrically indistinguishable from a normal piece of wire. It's rated for 12 V which is fine for this application.

One precaution is that the USB connector is designed so that the different contacts meet in a specific order (e.g. ground first because it is the outer case, then the interior pins are different length so the power pins meet before the data pins) - your controller software should mimic this to avoid causing any potential issues if either device is unprepared for a different connection order.