Author Topic: One USB device on two PC's? - HELP NEEDED  (Read 2962 times)

0 Members and 1 Guest are viewing this topic.

Offline XephlonTopic starter

  • Newbie
  • Posts: 3
  • Country: england
One USB device on two PC's? - HELP NEEDED
« on: October 31, 2019, 09:04:48 pm »
Hey there,

Recently I have encountered an issue with a personal project where I need to connect a keyboard to two PC's. I am tempted to fabricate a Female to 2 Male USB Y-splitter, however I am not very confident with electronics and I am worried that either the two 5V outputs from the PC's will fry my keyboard, or the data signal from the keyboard will decay when being split and will not input correct values. I have found keyboard switches to switch between two PC's, however I want simultaneous inputs. Sorry if this is a rather irrelevant topic for this forum, however I hope you guys can give some advice and tips about the 5V outputs and the data signals.

Many thanks to all who read & respond,
Josh
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11905
  • Country: us
    • Personal site
Re: One USB device on two PC's? - HELP NEEDED
« Reply #1 on: October 31, 2019, 09:25:28 pm »
It is impossible to share the same USB device between the two computers. USB stack is stateful, there is an actual enumeration process that is going on, you can't have the same device be enumerated on two hosts.

This will not make any sense electrically too.
« Last Edit: October 31, 2019, 09:52:57 pm by ataradov »
Alex
 

Offline 0culus

  • Super Contributor
  • ***
  • Posts: 3032
  • Country: us
  • Electronics, RF, and TEA Hobbyist
Re: One USB device on two PC's? - HELP NEEDED
« Reply #2 on: October 31, 2019, 09:27:16 pm »
You need a KVM switch, a/k/a Keyboard, Video, Mouse switch. One enables you to share a monitor, keyboard, and a mouse between at least 2 computers. You do have to switch it back and forth, but it's still way more convenient than having duplicate peripherals on the bench.
 

Offline boffin

  • Supporter
  • ****
  • Posts: 1027
  • Country: ca
Re: One USB device on two PC's? - HELP NEEDED
« Reply #3 on: October 31, 2019, 09:32:11 pm »
Hey there,

Recently I have encountered an issue with a personal project where I need to connect a keyboard to two PC's. I am tempted to fabricate a Female to 2 Male USB Y-splitter, however I am not very confident with electronics and I am worried that either the two 5V outputs from the PC's will fry my keyboard, or the data signal from the keyboard will decay when being split and will not input correct values. I have found keyboard switches to switch between two PC's, however I want simultaneous inputs. Sorry if this is a rather irrelevant topic for this forum, however I hope you guys can give some advice and tips about the 5V outputs and the data signals.

Many thanks to all who read & respond,

You can buy little switches like that.  I have one connected to my (shared) printer/scanner so it's connected to either my or my wife's computer.
 

Offline 0culus

  • Super Contributor
  • ***
  • Posts: 3032
  • Country: us
  • Electronics, RF, and TEA Hobbyist
Re: One USB device on two PC's? - HELP NEEDED
« Reply #4 on: October 31, 2019, 09:36:26 pm »
The bottom line is that ataradov is right; I don't know of any way to do simultaneous inputs to two computers.
 

Offline XephlonTopic starter

  • Newbie
  • Posts: 3
  • Country: england
Re: One USB device on two PC's? - HELP NEEDED
« Reply #5 on: October 31, 2019, 10:26:03 pm »
Okay. Its annoying that I cant have them run simultaneously, but ill find a solution.
Cheers!
 

Offline jhpadjustable

  • Frequent Contributor
  • **
  • Posts: 295
  • Country: us
  • Salt 'n' pepper beard
Re: One USB device on two PC's? - HELP NEEDED
« Reply #6 on: October 31, 2019, 11:12:17 pm »
Sounds a bit like a keylogger with an extra USB device interface. That could get complicated in hardware, especially in the event the two PCs try to command different HID configurations. Maybe it would be easier to do it in one host PC's software, by capturing keypresses on the host PC and forwarding them to the other host PC by whatever protocol happens to be useful. (Something along the lines of USB/IP or some other flavor of event injector, perhaps?)
"There are more things in heaven and earth, Arduino, than are dreamt of in your philosophy."
 

Offline wraper

  • Supporter
  • ****
  • Posts: 17952
  • Country: lv
Re: One USB device on two PC's? - HELP NEEDED
« Reply #7 on: October 31, 2019, 11:19:23 pm »
You can use software solution https://symless.com/synergy
 
The following users thanked this post: ogden, TomS_

Offline jackthomson41

  • Regular Contributor
  • *
  • Posts: 53
  • Country: us
Re: One USB device on two PC's? - HELP NEEDED
« Reply #8 on: November 01, 2019, 12:46:20 am »
USB is a slave and your computer is host. You can't connect single slave to multiple host but can do the reverse. simple logic of Embedded Systems components.
« Last Edit: March 04, 2021, 12:38:23 am by jackthomson41 »
 

Offline andycsmith

  • Contributor
  • Posts: 16
  • Country: gb
Re: One USB device on two PC's? - HELP NEEDED
« Reply #9 on: November 01, 2019, 11:35:15 am »
The question is why do you need one keyboard plugged into two PC's, you want the same characters to appear at the same time on both PC's.

Are you trying to test some software or replicate actions in multiple environments, if so there is software that will allow you to script this and play back as if you are physically typing on the keyboard.
 
The following users thanked this post: tooki

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9964
  • Country: us
Re: One USB device on two PC's? - HELP NEEDED
« Reply #10 on: November 01, 2019, 03:56:37 pm »
Okay. Its annoying that I cant have them run simultaneously, but ill find a solution.
Cheers!

In general, I don't think it is possible either.  HOWEVER...  Since it is a keyboard and therefore receives very little information back from the PC...

If you ran the keyboard to some kind of microprocessor with 3 USB ports, I don't see why code couldn't be written that would do all of the arbitration.  It's easy, generally, to become a USB HID device and if we're starting with a HID device (keyboard) then it should be straightforward.  One needs to figure out which PC sends what to the device but having the device send to multiple PCs should be easy.

Since it is a keyboard, it should be easy to get at it in userspace under Linux.

I don't know anything about writing Linux drivers but the Raspberry Pi was 4 USB ports.  I'm not even sure that a driver is required.  It seems more like an application with 1 keyboard input and two keyboard outputs.  It could be pretty straightforward...

« Last Edit: November 01, 2019, 04:01:00 pm by rstofer »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9964
  • Country: us
Re: One USB device on two PC's? - HELP NEEDED
« Reply #11 on: November 01, 2019, 04:58:40 pm »
We would want Linux to create two USB HID output devices and listen to one input HID device.  The listen part is probably pretty easy, it's a keyboard.  Creating the two HID devices might take some research like:

https://developer.ridgerun.com/wiki/index.php?title=Linux_USB_gadget_(g_hid)

Google around for 'make linux look like HID device' or something similar.

I don't pretend to know how to do it but I'm getting more certain it is possible every minute.
 

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 7012
  • Country: ro
Re: One USB device on two PC's? - HELP NEEDED
« Reply #12 on: November 01, 2019, 05:12:29 pm »
Recently I have encountered an issue with a personal project where I need to connect a keyboard to two PC's.
...
I have found keyboard switches to switch between two PC's, however I want simultaneous inputs.

At first look that seems like a spying device (e.g. to steal what is typed at somebody else's computer, like passwords, credit cards numbers, emails and so on), and that would be illegal.

Care to explain why such a device is needed for your personal project?

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13218
Re: One USB device on two PC's? - HELP NEEDED
« Reply #13 on: November 01, 2019, 05:25:04 pm »
I don't know anything about writing Linux drivers but the Raspberry Pi was 4 USB ports.  I'm not even sure that a driver is required.  It seems more like an application with 1 keyboard input and two keyboard outputs.  It could be pretty straightforward...
You are on the right track, but it would need two USB device ports and one USB host port.  The Pi 4 has four host ports and one OTG port which can be used as a device port, so could concentrate up to four keyboards to one PC, not the other way round.  As MCUs with multiple device or OTG ports are rarer than hen's teeth,  either you need multiple MCUs with a comms bus between them, each handling one port, or possibly a FPGA that can support multiple USB 'engines'.

 

Offline GeorgeOfTheJungle

  • Super Contributor
  • ***
  • !
  • Posts: 2699
  • Country: tr
Re: One USB device on two PC's? - HELP NEEDED
« Reply #14 on: November 01, 2019, 06:00:31 pm »
You can do that easily with one rpi and two arduino leonardos. https://www.arduino.cc/en/Main/Arduino_BoardLeonardo . Connect the keyboard to the rpi, the leonardos to the PCs, and forward via the serial port (or ports) the characters to the leonardos.
The further a society drifts from truth, the more it will hate those who speak it.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9964
  • Country: us
Re: One USB device on two PC's? - HELP NEEDED
« Reply #15 on: November 01, 2019, 06:08:00 pm »
It's dead simple to use something like RawHID in a Teensy to create a HID device.  I did that some years back when I wanted to add knobs and dials to Microsoft Flight Simulator.

https://www.pjrc.com/teensy/rawhid.html

So, easiest case, a couple of Teensy's should do the output side.

There is a USB Host Shield available for Arduino which will work with the Teensy so, maybe a third Teensy to work as the host and accept input from a keyboard and disperse it to the other Teensy's.

https://www.pjrc.com/teensy/td_libs_USBHostShield.html

I can't find the Host Shield mentioned in the above link but I can find others at Adafruit or Sparkfun.  That may require some changes in the library code but I have no idea how difficult that would be.  Probably not very...

Yes, this can definitely be done.  My solution, with 3 Teensy's and a USB Host Shield is obscene in BOM.  No doubt there is an easier way to do it but it's not really my project.


I am pretty convinced it can be done.
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 7454
  • Country: pl
Re: One USB device on two PC's? - HELP NEEDED
« Reply #16 on: November 01, 2019, 09:11:38 pm »
Try a PS/2 keyboard connected to two USB-PS/2 dongles.
It may have some chance of working, depending on how the dongles handle unexpected bytes produced by the other dongle when it initializes the keyboard.
 
The following users thanked this post: I wanted a rude username

Offline Bicurico

  • Super Contributor
  • ***
  • Posts: 1816
  • Country: pt
    • VMA's Satellite Blog
Re: One USB device on two PC's? - HELP NEEDED
« Reply #17 on: November 01, 2019, 10:30:47 pm »
@magic: that was my thought, too.

Older wireless keyboards and mice had the problem that you could not operate several of them in viccinity.

Just get two sets of old wireless keyboards and plug the two dongles into your computers, using then only one keyboard. That should work...

Regards,
Vitor

Offline soldar

  • Super Contributor
  • ***
  • Posts: 3595
  • Country: es
Re: One USB device on two PC's? - HELP NEEDED
« Reply #18 on: November 01, 2019, 11:09:39 pm »
With the old AT PS2 keyboards this was very easy to do because besides the +Vcc and GND there were just two wires, data and clock.
All my posts are made with 100% recycled electrons and bare traces of grey matter.
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 7198
  • Country: fi
    • My home page and email address
Re: One USB device on two PC's? - HELP NEEDED
« Reply #19 on: November 02, 2019, 03:39:54 pm »
If the PC's run Linux, you only need two trivial daemons forwarding the keypresses from one to the other.
The basic code is trivial; it only becomes harder if you want to secure the connection (using OpenSSL or similar).
If you want, I can show you the basic daemon C code.  This easily scales to more than two machines, and more than two keyboards, as well.


If you want a hardware solution, use N+1 microcontrollers with a native USB interface, with N devices, and one host.
(You can do with N microcontrollers, if one of the ones with a native USB client interface also has an USB host interface.)

On N-1 USB connections to the PCs, use an USB isolator, to avoid ground loops.  The cheap eBay ones work well for max. 12Mbit/s USB, which is perfectly fine for keyboards and mice and many USB audio devices.  If this is used strictly with laptops on battery power, you can omit the isolators.

I would probably use N Pro Micros (same ATmega32u4 as in Leonardos, but much smaller board; the 5V/16MHz model, not 3.3V/8MHz), one USB host shield, and N ADuM4160/3160-based USB isolators, because I know these work well together (except I haven't used any of the USB host shields).  On fleabay, pro micros and the USB host shield cost about 4€ apiece, and the USB isolators about 8€ apiece.  For N=2, this comes to about 25€ or so.

If you can use a PS/2 keyboard, then you don't need to use the USB host shield. You can use the PS2Keyboard library with Pro Micros, because they use the same ATmega32u4 microcontroller as Teensy 2.0.

The idea is that the microcontrollers have a shared ground, and exchange key press information using UART, SPI, or I2C.  For a pair of microcontrollers, the UART makes the most sense.
 

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 854
  • Country: gb
Re: One USB device on two PC's? - HELP NEEDED
« Reply #20 on: November 02, 2019, 07:29:45 pm »
You can use software solution https://symless.com/synergy

Another recommendation for Synergy. I use it between two Macs to share a keyboard and mouse (and clipboard!), but you can use it between any combination of supported OSes.  :-+
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf