PS/2 to USB keyboard converter

What?

A home made Atmel ATMega based adapter to allow me to use a nice old PS/2 keyboard with anything which has a USB port, and can source sufficient power to run it. The old keyboard I measured used ~1W of power. That's easy for a laptop or desktop to supply. But phones and tablets will struggle. A phone's power use is typically in the 3-5W to start with. Adding 1W more will noticeably shorten the battery life, should the phone allow the device to begin with (the phone OS might, quite resonably, refuse to power a device which uses 200+ mA).

Why?

For decades I have been using several old PS/2 keyboards, IBM Model Ms and a Northgate Ultra.

In 2014 I could no longer purchase a new computer with a PS/2 port. I tried two commercial keyboard adapters and neither worked consistently. They both missed keystrokes, which, it turns out, is especially annoying when the missed stroke was a key release, since the key keeps repeating until it is pressed and released successfully.

I'm an {embedded,os,app,gui} software engineer by trade, and thought this shouldn't be so hard. So I set out to make a decent adapter.

How?

I looked around and found that Atmel made single-chip, 5V tolerant, 8-bit SoC versions of their venerable ATmega chip with a high speed USB controller built into the hardware. So I purchased one on a development board from Adafruit, specifically the Adafruit ATmega32u4 breakout board. Using the LUFA USB software, and developing the PS/2 part by hand (existing PS/2 libraries for ATmega turned out to be flawed, exhibiting the same behavior as the commercial adapters!) I created a PS/2 to USB keyboard adapter which functions properly and completely reliably.

HOWTO

  1. Purchase or make yourself a board based on the ATmega32u4 or a similar CPU.
  2. Install the AVR compiler and tools suite.
    apt-get install gcc-avr avrdude
  3. Fetch and build the firmware. You'll need to
    1. fetch and install the LUFA USB library
    2. fetch the firmware I wrote.
      git clone https://github.com/nsd20463/ps2_kbd_to_usb_adapter.git
    3. Edit the top level Makefile in my firmware to set the variable LUFA_PATH to indicate where you unpacked the LUFA library source
    4. Edit the USB device descriptor strings
        usb_manufacturer_str = USB_STRING_DESCRIPTOR(L"Northgate Computer Systems");
        usb_product_str      = USB_STRING_DESCRIPTOR(L"OmniKey Ultra");
        usb_serial_str       = USB_STRING_DESCRIPTOR(L"0621683");
      in descriptors.c to match (or not, your choice) your keyboard.
    5. Optionaly, measure the current consumed by your PS/2 keyboard and edit
        .MaxPowerConsumption = USB_CONFIG_POWER_MA(200),
      in descriptors.c to match. However I've found that USB hosts are pretty tolerant, so this is very much optional.
    6. Build everything.
      make
      The final firmware is in adapter.bin (same in .hex)
    7. Plug the Adafruit ATmega32u4 breakout board into a USB port, reset it using the RESET button, and while bootloaded is waiting (when the LED is pulsing), install the firmware.
      make flash
  4. Connect the PS/2 keyboard to the ATmega32u4. You can do this by building the ATmega32u4 into the keyboard (there's usually a lot of empty space in an old keyboard), or by wiring a female 6-pin mini DIN PS/2 socket to the ATmega32u4, and plugging the keyboard's PS/2 cable into that.

    The pinouts the firmware expects of the ATmega32u4 are:

    port D2 DATA
    port D5 CLK

    and of course 5V power and ground.

    The pinouts of a PS/2 mini-DIN connector are:

    pin 1 DATA
    pin 3 GND
    pin 4 +5V
    pin 5 CLK

    Looking into the [male] end of the PS/2 cable from the keyboard, or identically, into the soldering/back side of the female PS/2 socket, the pins are numbered:

                      ^
             CLK--  5 | 6
            GND--  3     4  --+5V
                   > 1 2 <
    
                   /
                DATA
        

    and the other two pins (2 and 6) are unused.

    Myself I chose to built my adapters using a DIN socket so I could use them with multiple keyboards. However building the electronics into the keyboard does make everything mechanically stronger, and part of me thinks I should have taken the plunge and altered my keyboards directly.

Pics

Note that I chose to put pin 1 (DATA) right through pad D2, and pin 3 (GND) is soldered to the otherwise unused D1 pad for mechanical strength.

 

 

 

-- 
Nov 2014, Nicolas Dade <ndade@nsd.dyndns.org>