usb data lines and switching - Page 1
Forum section: electronics / general

author: lilshawn
author_rank: Regular Contributor
timestamp: August 25, 2021, 06:03:15 pm
content: i'm going to be designing a device to switch usb devices on and off a computer system. (the computer will not be running at the time) they are extremely low current devices and don't require any kind of sustained transfer speeds or anything like that ... but they cannot all be just plugged in without interfering with each other. so the plan is to switch the device i need at the time "on" leaving the others "off".so I have one USB-B port with a cable going into the computer and multiple USB devices plugged into a "hub" of sorts. (a series of USB-A ports)my plan is to tie all the ground/D+/D- lines together, then use a ULN2003 to "switch" the USB5+ power "on" from the USB-B port to the appropriate USB-A port. essentially "powering" the individual USB device. keep the data line runs as short and even as possible to eliminate any kind of corruption or interference.is it okay to tie these data lines together in this fashion?(scabbed together schematic for reference)thanks for your help!

author: mariush
author_rank: Super Contributor
timestamp: August 25, 2021, 06:52:19 pm
content: The uln2003 is gonna have a significant voltage drop.I also wouldn't tie the D+ and D- wires together. Consider analog mux chips or mechanical relays.Mechanical relays would be easiest, as you'd have the lowest resistance, and they're cheap.. a 5v DPDT relay is 1$ and let's you switch the D+ and D- wires between 2 ports , so 3 relays would be enough for the data wires.Here's an example of a DPDT relay :https://www.digikey.com/en/products/detail/cit-relay-and-switch/J104D2C5VDC-20S/12503179See datasheet at page 2 for how the pins of relay are positioned.The ground wire can be kept always wired, for the voltage wire you'd have to use either relay or have it hardcoded on the selector switch.You could use a 4 position slide switch with 2 sets of contacts , a set could be used to route the voltage, the other could be used to turn on the specific relaysrelay 1 - default off = port A , relay 1 - on = port Brelay 2 - default off = port C , relay 2 - on = port DRelay 3 connects either relay 1 outputs or relay 2 outputs to computer portrelay 3 - default off = relay 1 , relay 3 - on = relay 2So :port A : relay 1 off, relay 2 off (don't care) , relay 3 offport B : relay 1 on , relay 2 off (don't care) , relay 3 offport C : relay 1 off (don't care) , relay 2 off , relay 3 onport D : relay 1 off (don't care) , relay 2 on , relay 3 onSo worst case scenario, you're gonna 2 relays energized, consuming maybe 30-50mA from 5v.The design isn't safe to switch between ports live, as there's a delay until a relay turns off and until the other relay turns on, so if you slide between positions it could be that data wires of two ports would be simultaneously connected.But, you can simply add a on/off switch to disconnect the whole box from 5v input, wait a second or so, change the slider position, turn back on ... and you don't have to reboot the computer.You'll need to add one diode to each relay for protection but that's easy, if you're a beginner you'll find tutorials on the internet about why that's needed..

author: lilshawn
author_rank: Regular Contributor
timestamp: August 25, 2021, 07:55:29 pm
content: thank you for your insight.you are correct, i have no plans to switch this live. it will be done before the computer is switched on, and powered off before it's changed.you think something like a MAX4899AE would work better in this instance?IE power all the usb devices and then switch out the D+ and D- lines with the 4899? devices consume about 50ma peak each, so powering all the devices is not an issue.

author: mariush
author_rank: Super Contributor
timestamp: August 25, 2021, 09:22:50 pm
content: Yeah, looks like it would work.That chip works with max 3.6v, so you'd probably want a 3.3v linear regulator powering it.I'd still keep the ports unpowered, and power only the active port - basically device has to be powered to communicate with the pc to initialize. If you plug device and gets powered and then you turn on the pc, the device may not work until it's reset again.