Arduino PS2 to USB Keyboard

My April Fools joke hit a roadblock when I discovered that my coworker was using an old PS2 keyboard rather than a USB one. I had to work out a solution for that. A bit of googling turned up this on the Arduino site: PS2Keyboard. So basically I just needed to find a PS2 connector and to wire up an interrupt line and a data line and then the Arduino can read the PS2 key presses. I took the example library from PS2KeyboardExt2 since it was a bit more advanced than the PS2Keyboard library, and I modified it to map the PS2 key scancodes onto USB Keyboard HID Key Usage codes, and added a function to return a USB HID Keyboard Report.

It took a few hours to get the job done, tested with a USB to PS2 adaptor attached to my keyboard. Everything seems to be working except for NUMLOCK key changes but hopefully my coworker won't notice that.

Here's the PS2KeyboardUSB library files and the sketch:
Download file "PS2KeyboardUSB.h"
Download file "PS2KeyboardUSB.cpp"
Download file "kbd_april_fools.pde"

The project could be used to make a nice PS2 to USB keyboard adaptor.

I installed the project on my coworker's docking station Friday morning (April 1st) while he was distracted by an accomplice. We're all waiting to see if he notices it or just slowly goes mad.

Comments

Anthony Jones (unauthenticated)
Apr 5, 2011

It turns out that once the coworker noticed that the keyboard was playing up he found it quickly. He now has an Arduino sitting on his window sill at home.

Oladon (unauthenticated)
May 7, 2011

Anthony, could you post a picture or description of your wiring setup? I'm working on an Arduino + PS/2 keyboard project, and having a really hard time getting the data to /both/ the Arduino and keyboard. With the Arduino as a "tap" on the wires, neither receives the correct signals... with the Arduino acting as an intermediary, I don't know how to pass the signal along after the Arduino has seen it.

I think your project will help me, but I'm curious about how you did the interfacing.

Thanks for posting this!

darran
May 8, 2011

Hi Oladon, Anthony was the target of the april fools prank but he did eventually return my Arduino :-). Let me know your email address and I'll send you through some details (darran [at] hunt [dot] net [dot] nz).

Cheers,
Darran.

Pedrejo (unauthenticated)
Jul 25, 2011

Hi Darran,

Thanks so much for your work on this! I'm trying to use the PS2 -> USB code with an old CueCat barcode scanner and am not having much luck. Do you have any idea why the scanner works with the Arduino PS2 but not the HID firmware & April Fools code? Sorry, I don't really know enough to determine what the problem might be. Any ideas would be greatly appreciated.

Thanks, Pedrejo

darran
Jul 29, 2011

Hi Pedrejo,

without seeing your code I'm not sure why it's not working for you. Does the CueCat scanner behave like a PS2 keyboard? I'd probably start with just the PS2 code and some Serial.println's to see how the CueCat was behaving, and then work on translating that to Keyboard HID output.

Cheers,
Darran.

akshay (unauthenticated)
Mar 1, 2012

hi guys
i am trying to interface an old keyboard with aurdino uno with atmega controller having sd memory.the code given in PS2keyboard seems to be giving a lot of errors.
can suggest a suitable code and let me know if i need to extract any files into the library.i am a beginner so kindly explain in detail.

darran
Mar 11, 2012

hi akshay, that sounds like a good question for the arduino forum. The code from my blog works fine with the PS2 keyboard I have, so there must be a problem with the hardware or perhaps with your sketch. If you post the sketch to the forum on http://arduino.cc you should quickly get some help.

Chris (unauthenticated)
Jun 13, 2012

How did you handle the PS/2 to USB conversion? Was it new firmware for the 8U2? I didn't see anything in the code that looked like USB.

darran
Jul 9, 2012

Chris the PS/2 to USB conversion code is in kbd_april_fools.pde in this blog entry: http://hunt.net.nz/users/darran/weblog/329aa/Arduino_PS2_to_USB_Keyboard.html .