Go Down

Topic: using the PS2 keyboard library with Arduino Leonardo (Read 2587 times) previous topic - next topic


I'm having difficulties getting the PJRC PS2 keyboard library (http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html) working reliably with the Arduino Leonardo. I'm relatively new to using the Arduino, but this library seems to be the recommended way to read PS2 keystrokes.

When I run the example sketch to echo keystrokes to the serial terminal, I get about 50% of the characters echoed correctly. The other half typically consists of random characters. In addition, I'd say only 30% of the keystrokes are actually detected at all. I tested many keys on the keyboard to see if there was a mechanical fault but this mis-identification and detection lag happened to all of them.

I get very different results using code from this blog which just implements the PS2 protocol in a barebones way: http://nocommercialpotential.posterous.com/interfacing-the-ps2-keyboard . All of the scan codes echoed from this program are consistent (and correct after I manually looked them up) and there is no lag in detection of keystrokes.

So I could implement my own lookup tables with the second example but I'm curious if I'm making a mistake with the PJRC lib. There are more features in that library that I would like to make use of. Thanks for any help.


but this library seems to be the recommended way to read PS2 keystrokes.

Recommended by whom? By Paul, on the Teensy? Well that makes sense, so get a Teensy.

The art of getting good answers lies in asking good questions.


It's the main hit when you search "PS2 keyboard library arduino."  It's the first thing in the playground: http://playground.arduino.cc/Main/PS2Keyboard  I know that's a public wiki but it clearly works for older Arduino boards..


I got the PJRC lib working but in a strange way.  In the example code I define the IRQpin to be pin 3.  However, when I actually wire up the device, I have to connect the keyboard's CLK pin to pin 2 on the Leonardo.  Not 3.  Despite the definition.  This lets the library work as expected.  Connecting to pin 3 results in the gibberish I noted above.

So that's confusing..  More notes and discussion here: http://electronics.stackexchange.com/questions/50911/using-the-ps2-keyboard-library-with-arduino-leonardo


I got this working with some slight tweaks to PS2Keyboard.h .  Specifically I had to define the interrupt pins for the Leonardo's ATMega32U4.  My fork is hosted here: https://github.com/yosemitebandit/PS2Keyboard.

Go Up