View Full Version : PS/2 Keyboard input

01-17-2007, 08:01 AM
Okay, I already had one question answered here involving serial data and the telephone. Now I have another (probably silly) question about PS/2 Keyboard input to a BS2. I have already attempted and failed with opening up a keyboard, cutting the wires, and connecting them to the basic stamp (with a generic wiring diagram). What I got was a series of strange ASCII characters when the data was debugged. Is there any way that I can connect a keyboard and program the Basic Stamp to take the "scancodes" as proper ASCII Characters? My point is to try to·keep the costs down·(like not buying Propeller Chips). Thanks.

PJ Allen
01-17-2007, 08:14 AM
PAK-VIa, $29.95· http://www.awce.com/pak6.htm

Parallax Propeller Proto Board, $19.95· http://www.parallax.com/detail.asp?product_id=32212

Wait a little, save a lot?· You decide.

Mike Green
01-17-2007, 08:15 AM
SmartHome sells a PS/2 adapter made by MultiLabs for $15-20 that does all the work for you (www.smarthome.com/78552.html (http://www.smarthome.com/78552.html)). It wasn't clear from your posting whether you've been able to actually communicate with the keyboard since the keyboard is actually the master in the situation. The keyboard reports scan codes which correspond to the physical keys and there are separate scan codes for pressing and releasing the keys. Your program has to do all the translating between scan codes and ASCII characters including the tracking of the shift, control, alt, caps lock, etc. keys.
That's a lot of work for a Stamp that may have to do other things as well. Hence the external adapter.

PJ Allen has a great suggestion in that the software for the Propeller already exists to do the keyboard decoding and transmitting and receiving serial data. All you need is the "glue" Spin program and a Propeller Protoboard. Admittedly, the Multilabs adapter is now cheaper, but the Propeller can also handle a mouse and generate VGA video (or TV video).

Post Edited (Mike Green) : 1/17/2007 1:19:52 AM GMT

01-17-2007, 09:26 AM
The Keyboards clock frequency ranges 20 to 30 Khz. The fastest usefull ·loop that I've been able to get from a BS2 is approximately 1khz (that's a for next loop with a toggle command).· In other words the BS2 is over 20 times too slow to read a PS/2 keyboard.· Get one of those chips Mike and PJ suggested. The price seems right.

Have Fun


01-21-2007, 11:21 AM
I was wondering if this would work....

If I used a serial to parallel shift register and a counter circuit, would it work if I were to allow the keyboard to shift in the serial data, then when the 11 bits are in, the counter goes high to let the stamp know to read the parallel bits?

1. keyboard shifts in serial data to register (while counter keeps track of bits coming in)
2. when 11 bits have been shifted in, digital counter goes high (while the stamp is in a loop waiting for the high)
3. stamp reads all the bits from the parallel outputs of the register, then goes back into a loop waiting for the next high

Would that work?


02-02-2007, 11:45 AM
OK ktekx you got me thinking. So I build this really simple circuit and it reads the keyboard just fine.
It doesn't need a counter because it uses the inverted start bit for flow control.

I posted it on the completed projects forum:


Have Fun