<- to Hubbe's corner
how to build an matrix HDMI KVM

(relatively cheaply)

Written by Fredrik Hubinette


Background

So, I bought a very nice new house. The new house has a media closet where my TiVo, PS3 and other video equipment lives. I have 3 TVs in different rooms and they are all hooked up to a matrix switch in the media closet so that each can choose what device to hook up to. Sounds simple, right?

The problems started when I realized that I have 5 devices with HDMI outputs. A 4x4 matrix switch can be had for $200 from monoprice.com. An 8x8 matrix costs thousands. To make matters worse, two of my HDMI devices are computers that need keyboards and mice. Apparently an 8x8 matrix HDMI KVM is not something you can buy, for any price. Depressing.

So, even before we had moved in, I started plotting for a way to hook up a HDMI matrix switch to a computer and then have that computer also route keyboard and mouse events to to the right device. But how do you inject those events into the device? (At this point, it might help if you picture me as Wile E Coyote, trying to hatch a way to catch that darn bird...)

My first thought was to look for some sort of console server, It seemed obvious to me that someone would have made a small device that talks VNC over ethernet at one end and plugs into VGA & USB on the other end. Preferably it should be cheap too so that you can plug it in to 100 of servers in a server room. Unfortunately, such a device seems to be hard to find. Back to the drawing board.

As I was reading about this I found out that there is a standard for talking USB over ethernet. Awesome, right? Perhaps I could just buy an 2-piece usb-over-ip extender and do some routing/firewall magic to connect things together? Seems simple, right? And perhaps it is. I don't know, because I couldn't find a 2-piece usb-over-ip extender. All the hardware out there seems to be a single remote usb HOST port. What I needed was a remote CLIENT port. (fall off a cliff, back to the drawing board...)

After some serious head-scratching, pacing and a few calls to ACME tech support I finally came up with a solution that could work. The idea was to take an Arduino and hook up one or more PS/2-to-usb converters to it. The host computer could talk serial protocol to the Arduino, which would talk PS/2 to the PS/2 controller which would talk USB to the client computer. It's a bit roundabout, but the PS/2 protocol is pretty simple and the components are very cheap.

PS/2 might be simple, but it turns our that there is quite a few ways to screw it up. I ended up buying a cheap oscilloscope that I found on craigslist, which helped, but even then I couldn't get it to work properly. After realizing how slow the arduino libraries are, I built my own pin abstraction library and used a second arduino as a logic analyzer, and eventually I got it right.

During the long long LONG process of getting the "simple" PS/2 protocol working, I had another Evil Genius Plan (tm) for how to hook up all the USB keyboards and mice to the right device; A BOX OF RELAYS. It's so simple, how could I not think of that? USB is hot-swappable after all. You just need one 4-pole relay for every combination of input and output and an arduino to drive it all. Seems simple, but it turns out that relays are kind of pricy, and if you want 3 inputs and 5 outputs, it starts to add up. I called up ACME and ordered a few relays for testing, but I still haven't built this solution.

Anyways, back to the arduino-ps/2-converter. (if this was a cartoon, this is the point where I light the fuse on the rocket) I finally got the PS/2 protocol figured out, and I hacked up some software on a linux computer that routed events from /dev/input/* to the right PS/2 port. And it WORKED! Awsome! Except, everything had a 0.1 second delay. Not so awsome for gaming.... Turns out that most (or all?) PS/2-to-usb adapters suck. I tried buying a few different PS/2 adapters, and ranged from bad to awful. (Rocket explodes, back to the drawing board)

At this point I came across a little device called a teensy. A teensy is very similar to an arduino, except it talks native USB. It can pretend to be a keyboard, a mouse, a giant road-runner-hunting robot or any other USB device you could think of. Since the teensy doesn't use it's serial port to talk to the USB, it can communicate over serial and USB at the same time. This makes the teensy perfect for implementing a virtual keyboard/mouse which gets it's events from the serial port.

The solution

The teensy turns out to work perfectly. (insert mental picture of Wily E Coyote eating bird here) I ended up just buying two teensys, one would serve as a USB-to-serial converter and one as a virtual mouse/keyboard combo. The delay is not noticable, and there is already a lot of code out there that can be used as a starting point for this stuff.

But wait you say, aren't I forgetting something? How do you plug in 5 HDMI devices into a 4x4 HDMI matrix switch? Or did I just spend the money to get an 8x8 HDMI switch? The answer is that I just bought another 4x4 HDMI switch. Both are controlled through a serial port. This is what it looks like now:

TODO:

  • diagram of hdmi matrix setup
  • picture of teensy stuff
  • picture of arduino stuff
  • post source codes
  • document irman setup

    LINKS: