[Project Idea] USB-only KVM type switch box, UPS PSU, mechanical relays or what - Page 1
Forum section: electronics / projects

author: faekjarz
author_rank: Regular Contributor
timestamp: December 01, 2017, 01:44:01 am
content: Hi!I'm thinking about a KVM type USB switch box, but without the V (as in Video) ...USB-only. Basically not even limited to Keyboards and Mice (HID input), how about USB-Storage, UAS or UVC, but a KVM type switching scenario is what i have in mind. Implementing such a little box should be fairly straight forward, even for a novice like me, with limited Arduino / AVR experience. It's just wiring and switches, right?Here's my Plan A:Mimic the physical connection sequence of a USB plug, which has staggered PWR and DATA pins (the longer outer PWR pins connect first, when plugged in). I'd basically have to recreate the unplug-and-plug-into-other-port sequence, without actually touching any plugs or cables - the whole point is to only press channel select buttons (yes plural, inmyproject i want one select button per channel). And i want at least 3 channels.Sequence draft A:fn onCHselectEvent()if CHselectedequals CHactivenoop("do nothing"); // no need to change state, because you selected the same channel, duhelseopen_data(CHactive); // pull the plug, data pins are short, sever 1stsleep(0.25s); // mimic staggered USB plug pinsopen_power(CHactive); // still pulling plug, long power pins sever lastsleep(0.25s) // just for good measureclose_power(CHselected); // connect long pins firstsleep(0.25s) // mimic staggered USB plug pinsclose_data(CHselected); // connect short pins lastQuestions:My quarter of a second sleep() may be a bit too generous, but i guess .05 would be too fast. (I'm sure there's an actual value in the USB spec, but tl;dr) …Comments?Should i switch GND too? I mean, i could save one relay (switching component) per channel, but putting all the GNDs onto the same conductor would basically connect GNDserverwith GNDworkstationwith GNDlaptopwith GNDhackedIOTbotnetZombie...and so on …all via somewhat thin wires. I'd better isolate those too, right?Relays are nice and fairly easy to use; juice on one end causes closed circuit on the other end, done …those are fairly cheap too, <5€$ delivered, for ~12 (3 channels) 5V clackers from AliExpress.UPS type Control Circuit Power Supply Lego Bricks:Since there are only USBdevices(leaf nodes, in bus topology nomenclature) connected to theinputchannel (as in KVM nomenclature), i need to source the power supply tothe switching control circuitry, as well as the devices, from any of the output channels. My idea is similar to a seamless UPS (Uninterruptible Power Supply) type fail-over circuit. I'd rather fancy a somewhat "active" approach, with a sufficiently dimensioned capacitor to overcome short power outages, while failing over, in case the active (from the UPS point of view, not necessarily the CHactive) channel host shuts down or reboots / resets. Up to 5 seconds backup power would be nice, in order to keep the current MCU runtime state (not rebooting, due to power loss / hard reset). And yes, there should be a BACKUP_POWER_ONLY emergency kind of flag somewhere, in order to immediately open / sever power rails to all input side devices (which could be a very "thirsty" 2.5 inch bus-powered HDD) …just keep the control logic running for a few secondsI'm sure there are 5V "Lego Brick" type (ready-made) circuits, are there? Comments?Weird machines:I remember that one talk at one of the CCCs (Chaos Communication Congress), a few years ago, about weird machines, overly complicated, hardly debugable, machines; the gist was "Don't create weird machines!" …so, i think i should compartmentalise and constrain my UPS PSU idea. I really want to keep the MCU and its state running, as long as possible, while there's power supplied via any of the "outputs". But i don't want to supply power to any of the "input" devices, via a non-active channel. In short, when the selected channel (CHactive) is powered off, the input device(s) should be in the same state too. And if there's power supplied from another channel, the MCU keeps running, until the last power supplying host is powered off.the Train Of Thought steams on, and on:…if there's no power on any of the output channels, than there'd be absolutely no need to …urgh, nevermind, that's rather obvious ;-)…but what if the CHactivesetting is being stored in some kind of non-volatile memory, and...restored...on boot...? …do AVRs / ATtiny / ATmega have integrated nv-mem? Alternatives?…mechanical relays and a big cap are the obvious choice for a novice like me …comments?Oh, by the way, i want CHactiveindicator LEDsPhew, this project might require a lot of MCU pins …unless someone persuades me to invest effort into familiarising myself with shift registers

author: james_s
author_rank: Super Contributor
timestamp: December 01, 2017, 01:54:03 am
content: I would probably use analog switch ICs, but you can already buy USB switchboxes, we used to have some of them around at work.

author: faekjarz
author_rank: Regular Contributor
timestamp: December 01, 2017, 02:32:58 am
content: Quote from: james_s on December 01, 2017, 01:54:03 amOhai James! Could you please post some links? What USB switch boxes might your work place have used?

author: james_s
author_rank: Super Contributor
timestamp: December 01, 2017, 10:10:14 pm
content: I don't remember what brand they were, we don't have them anymore but they were simple passive switch boxes, mechanical buttons. They were similar to these:https://www.amazon.com/ECore-Cables-Manual-Button-Switch/dp/B01M3293Z8/ref=sr_1_19?s=electronics&ie=UTF8&qid=1512166176&sr=1-19&keywords=usb+switch+box

author: faekjarz
author_rank: Regular Contributor
timestamp: December 02, 2017, 12:54:25 pm
content: Quote from: james_s on December 01, 2017, 10:10:14 pmWOW, I didn't expect that such a switcher could be that bare bones, with mechanical switches!I guess that price kills my DIY approach too, haha.

author: james_s
author_rank: Super Contributor
timestamp: December 05, 2017, 08:42:03 pm
content: There are some disadvantages to a passive switch though, each time you switch is like unplugging the device and plugging it into something else so it will re-enumerate each time. When you use a KVM it typically provides an abstraction layer of sorts so the devices on either end have no idea that the switch has taken place although I think that only works with HIDs like keyboards and mice.