f2pi

A SIMPLE MODEL F KEYBOARD INTERFACE FOR THE PI

Love your old Model F keyboard and want to use it on your Pi? This project is for you!

THE HARDWARE

Thanks to a very generous soul, I became the proud owner of an IBM Model F keyboard. After admiring it's solid massiveness for a couple of weeks I sat down to figure out how to interface it to my Pi 3. It operates much like a PS/2 keyboard, so interfacing should be similar. Or so I thought....

The first problem was that the protocol isn't quite readable by a UART: It doesn't use one start bit, but one that's almost two bit times long. And the signal is inverted - the idle state is at logic zero. How could I make this work with a simple circuit?

The signal could be inverted by a simple one-transistor circuit. But what about that start bit? It's close enough to two bits that it could be properly read, but then the eighth data bit would be read in as the parity bit. With some clever software I could extract this bit value from a valid/invalid parity condition. But there was a problem: I wanted to use the Mini UART (Bluetooth uses the normal one) and it doesn't support parity bits. So, if the eighth data bit is logic one, it would act as a start bit for a new byte consisting of all zeroes. So, to determine the eighth bit value, I'd have to wait for a bit after receiving data to see if a new byte is coming. That's possible, but not very elegant.

While reviewing the published waveforms I had an epiphany - if the clock and data lines are and-ed together the start bit shortens to one bit time. Invert the resultant signal and it would be readable by the Mini UART. And I knew that I could do all this with a simple circuit made from two diodes, two resistors, and a transistor: parts that I had on hand. So I threw it together on a breadboard and took a look at it with my trusty 'scope. It looked good: the resistor values just needed adjusting for a clean signal. Here's the final circuit:

NOW ON TO THE SOFTWARE

I wrote up a kernel module based on my m2pi project. It's actually simpler than the original - there's no need for a translation table! It turns out that Linux uses native XT scancode values for it's internal key representations. I also needed to modify the baudrate testing program to work with the XT keyboard. After I set the proper baudrate, the kernel module worked perfectly!

VERSION TWO

The above circuit is simply an implementation of a NAND gate in diode-transistor logic. So I thought: how about using one of those nifty single-gate TTL ICs that TI makes? Here's what this new circuit looks like:

Pretty simple, right? I think two parts is pretty good. The gate comes in a SOT23 package, so I couldn't solder wires directly to the part like I usually do. But maybe I could etch a simple circuit board? I sat down with the data sheet and a piece of paper and designed it:

After etching the board it looked like this:

How's that for simple? It's a single sided board. The decoupling capacitor goes on the back, and has leads that wrap around to the front.

I wanted a low profile capacitor, so I made one from a surface mount device:

And installed it on the back:

And soldered on everything else:

Then covered it with heat shrink tubing to protect it:

MAKING ONE FOR YOURSELF

You can make it from a scrap circuit board. I used a circuit board salvaged from a broken hard drive. You just need an area with unbroken copper covered with solder mask on one side of the board, with no vias, about .157"x .310". It's nice if the board is .030" thick, but it will work with the more usual .060" thickness.

Cut your piece out and trim the edges to final dimensions. Then scribe lines in the mask as indicated on the drawing. You can use a needle or X-acto knife. Refer to the photo below for an example. If you have one, a vernier caliper makes this easy. The solder mask will act as an etch resist, and where you've scribed the copper will be etched away. Your horizontal lines can be pretty narrow since you'll over-etch the board, thus widening them. You'll have to also remove any mask that's over copper on the back side of the board: we don't want any copper on the back. You can scratch it off with a knife or use sandpaper.

Here's what mine looked like. My horizontal lines were thicker than necessary: just a narrow scratch is adequate, as long as it gets down to the copper:

Etch the board using your chemical of choice. (If you don't have any etchant, you can make ferric chloride made from Muriatic acid and scrap iron. Or use the vinegar+salt+peroxide etchant that you can find out how to make on the 'Net. You probably already have the chemicals! There are other options available if you do some research. Or, buy a bottle of ferric chloride etchant if you're feeling extravagant!) You want to over-etch the board so that any internal layers are no longer exposed at the edges: they might short against the capacitor leads. This also has the beneficial effect of widening the scribed lines. Etching should be stopped when all lines are etched and of a respectable width, and the back is completely etched. Rinse the board and dry it, then remove the solder mask. Either rub the board on fine sandpaper placed over a flat surface, or use a flat oil stone. Be careful to remove only a minimum of copper! NOTE: don't trim the edges of the board after etching: it will expose the internal layers, if any.

Now you're ready to assemble! You need to make a capacitor with a funny lead arrangement from a surface mount part and some bits of wire.

WRITE-UP NOT FINISHED: STAY TUNED...