Hack a PS/2 Keyboard Onto Your Pi Zero

Hacking for the Raspberry Pi Zero is a tricky proposition. Whatever you do, you’re working with a nominal five dollar board, so your hacks can’t be too highfalutin. For instance, a decent PS/2 to USB adapter will cost you as much as the Zero did, if not more. But if you just need to drive your Pi Zero from your old Model M (we hear you!) you’ve got to do it on the cheap.

So when prolific Pi hacker [mincepi] set out to build a PS/2 adapter, some corners were cut. PS/2 is a clocked data protocol, but the good news is that the clock doesn’t start and stop all the time as in I2C or SPI. This means that if you poll the data line at just the right frequency, at least in principle you’ll be able to ignore the clock.


So that’s what [mincepi] did. As you can see in the schematic and the banner image, there’s nothing to it. Two resistors provide the pullup voltage for the clock and data lines. And here’s a gem: a green LED with a drop voltage of about 2 V converts the 5 V data line down to something that the Pi Zero’s 3.3 V won’t get fried with. Cute, and very much in keeping with the spirit of the hack. You might be tempted to scrounge up a 3.3 V zener diode from somewhere just to be on the safe side, but remember, it’s a five dollar computer you’re protecting.

The last piece is a custom kernel module for the Pi that polls the PS/2 data line at just the right frequency. If you’re not a Linux person and “compiling a kernel module” sounds scary, [mincepi] has even put together a nice guide for the Raspbian distribution that he’s using. It should work with minor tweaks for any other distro.

We said [mincepi] is a prolific Pi hacker and here’s the proof: we’ve covered his quick-and-dirty VGA output hack and a scheme to get analog sound input into the Pi Zero just in the last couple of weeks. Hack on!

31 thoughts on “Hack a PS/2 Keyboard Onto Your Pi Zero

    1. A $5 computer thats like trying to walk on water. ( yes you can do it but not easy. )
      and no were near the $5 dollar mark. like said above.

      Cant wait till they become like sparrows.

  1. So while this might work for OP’s particular PS/2 keyboard, it might not work for other keyboards that use a different PS/2 clock frequencies. Also note that the LED drop is dependent on the actual current and might be influenced by ambient light.

    tl;dr it is a hack, but it might not work for you.

  2. Some pretty clever tricks on this one’s site… Drive an ASCII-LCD from any computer via USB by mounting the Pi as a flash-drive with a single text-file… edit the file, update the screen. Audio-input using only two diodes, a resistor, and two GPIOs… sheesh!

  3. “but the good news is that the clock doesn’t start and stop all the time as in I2C or SPI”
    What do you means byt that?

    PS/2 clock line stay high when the keyboard is idle and start clocking with the first bit and stop after the stop bit.
    If the clock is ignored the data line signal alone is like RS-232 format. The first bit is a low voltage START bit, followed by 8 data bits (least significant first) then the parity bit (odd) and finaly the stop bit.

    The problem is that the data rate is not strictly defined by the specification, although for all keyboards I have tried it was around 12.5Kbit/sec

    So the good news is that if you know the bitrate you can receive the keyboard data using an UART that support parity bit.

    1. http://www.computer-engineering.org/ps2protocol/
      >The clock frequency must be in the range 10 – 16.7 kHz.

      Not sure if there were a formal specs on the range. Most of the PS/2 devices probably uses bit-banging to generate the PS/2 signals as it is an odd ball bi-directional protocol. The device is the clock master so you are dealing with all kinds of uC implementations out there. Normally that’s not an issues as the PC side uses the clock. UART by its nature is *asynchronous* and can typically handle 2-3% of deviation of clock rates, so there is the likely hood of finding a keyboard that won’t work or have errors. You’ll need a scope/logic analyzer to measure the timing.

      For the 3.3V subject, if the keyboard does follow the open collector, you are probably seeing 2K worth of pullup, so the onchip ESD protection diode would be able to handle that 1mA (give or take). It is an I/O device with a long cable and a can pick up lots of ESD, so a zener or small signal ESD device or even a small capacitor would help here. Human (and clothings or cat) rubbing plastic can generating a lot of ESD.

  4. All keyboards I have tried with MCU work well at 3.3 volt so one could spare the LED and play safe by powering the keyboard with 3.3 volt. And no special driver would be needed if the data line is connnected to UART input and the tty configured for 12500 BAUD odd parity RAW mode. A module may be needed to convert scancode to ASCII, I’m not a Linux expert but maybe this could be done by sendig the raw data to already existing keyboard driver.
    One can check the exact keyboard frequency with an oscilloscope.

  5. who cares ? All these pi-zero articles and hype are useless if it’s a computer nobody can get a hold of. I can’t believe how badly the Pi folks messed this one up re: supply-vs-demand.

    1. That could also be intentional of not cutting in their existing models or simply trying to gauge the success on a cost reduction model before cranking up the production. Their 100K production batches could easily be $300K – $400K worth of boards sitting in a warehouse eating up cash flow and gathering dust.

  6. Could you please stop this “just a five dollar board” nonsense? There is NO retailer in Europe or North America that regularly sells the Pi Zero for “just five” dollars (or euros). The cheapest price I’ve seen is 12 euros + shipping, average prices are around 15 euros + shipping. Still cheap, but NOT FIVE DOLLARS… (not talking about the hassle of actually finding a retailer that has some on stock)

    1. $5.00 at micro center Westmont IL. they sell out fast in like two days…
      They been out for like two weeks now, glad I picked up one when there was a bin full.
      Note they have a one per customer limit on the little board, when in stock…


    2. Official distributors in Europe are Pimoroni and The Pi Hut. They each receive stock every two weeks, and give heads-ups on twitter. Not exactly “regularly”, but pretty close.

      Shipping is also very reasonable to the US.

    1. It’s early days. They announced it too early, as usual, to get lots of demand. You just have to be aware of this, and go do something else while you’re waiting for them to get supplies sorted. Don’t let it bother you, man! It’s the high-tech market, this kind of shit happens all the time.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s