PS/2 Keyboard IR Receiver

Project overview

The keyboard A few years ago, someone gave me a small wireless infra-red keyboard, part no. RC-KB2, designed to be used with a Kenwood audio system. As soon as I saw it, I wanted to discover it's transmission format. Why? Because I would then be able to build a small receiver which would allow me to use this keyboard on a PC with a PS/2 port.

My receiver Two years later, I finally found (or took?) the time to do it. This page's purpose is to document the project. Maybe someone else would like to use a keboard like this one with their PC? In any case, the receiving part of the code could be rewritten for other keyboards or even regular infra-red remotes.



Pictures

Pictures of the Kenwood RC-KB2 keyboard:
Infra-red led

Infra-red led

The keyboard

The keyboard

The keyboard again.

The keyboard again.


Pictures I took during development:
Development setup

Development setup

Infra-red receive close-up. Part no: tsop1238

Infra-red receive close-up. Part no: tsop1238


Pictures of the receiver I built:
Inside the enclosure

Inside the enclosure

Done!

Done!




Technical Details

When the keyboard emits infra-red, it is not continuously. In fact, it modulates the infra-reds at a frequency between 35 and 38 Khz. I did not measure the exact frequency, but I assume it is in the 35-38 khz range because an infra-red receiver salvaged from a VHS Vcr receives the signal correctly at a pretty good distance.

After looking at the receiver's output with a digital oscilloscope, I understood how the data was transmitted. As my infra-red receiver had an active low output, a low level in the following diagrams indicates that an infrared wave was present.

When the keyboard is sending a key press event, it starts by generating the following signal which I called 'Attention':

             4.5ms
----+        +----
    |________|
      9.1ms       
Right after the attention signal, the keyboard sends the data bits. The time elapsed between active pulses (560us) varies depending on the bit value being transmitted (1 or 0). A long time (approx. 1640us) represents a 1 and a short time (approx. 560us) represents a 0.
-----+ +-+ +-----+ +-----+ +-+ +--...
     |_| |_|     |_|     |_| |_|
         0       1       1   0   ...
When a key is held down, the keyboard sends a short signal which I called 'repeat':
             2.2ms
----+         +--+ +----
    |_________|  |_|
     9.1ms        ^
                600us
The keyboard sends 32 data bits, in other words, 4 bytes. Here is the meaning of each byte:
ByteDescription
FirstPeripheral Identification. Constant value.
SecondKeycode high byte.
ThirdKeycode low byte.
FourthBitwise NOT of the keycode low byte. Adding the third and fourth bytes will always result in 255. Useful for error detection.
I compiled a list of the codes emitted by most keys on the keyboard. The [shift] keys cannot be paired with all keys. The [Room B] keys act as a kind of [shift] keys but they cannot be paired with the same keys. Unlabeled keys on the keyboard do not generate events.
keycodes_rc-kb2.txt


Keymap

The keyboard

The keyboard

This keyboard was designed for a specific purpose. Therefore, it is quite different from a regular PC keyboard. Many keys are missing: ctrl, alt, F1-F12, Home, End, Page up, Page down, Insert, Delete... Also, this keyboard has keys which are not normally present on a PC keyboard: Disc Sel, Sub out monit., User file name, Room B...

The biggest usability problem I faced with this keyboard is the fact that there are only a limited number of possible key combinations. And when a combination works, for instance shift + a, a different keycode is sent. This is very different from a PC keyboard which would transmit the following sequence instead: 'Shift key pressed, A key pressed'...

Here is an overview of the possible key combinations. See keycodes_rc-kb2.txt for the full list:
  • Shift keys may be combined with all letters keys, numbers keys and the following character keys: ;',./-+
  • Room B keys may be combined with a limited set of keys, typically application specific keys such as: Confirm, Repeat, Random, Display, +10, +100, les chiffres 0-9, set, disc skip down, disc skip up and the stop/play/prev/next/rew/ff keys.
With such limitations, how can we do a CTRL +C or an ALT + F4? What about SHIFT + Page-up? Simply impossible. In order to work around this, here is what I did:
  • After the CONT PLAY key has been pressed, the next key I send to the PC is preceeded by the CTRL pressed event and followed by a CTRL released event.
  • After the Sub Out Monit. key has been pressed, the next key I send to the PC is preceeded by the ALT pressed event and followed by a ALT released event.
  • It is possible to press CONT PLAY followed by Sub Out Monit. to obtain a CTRL + ALT + somekey event.

Here is a table which describes which keyboard keys generate which standard PC keyboard key events. Obvious keys, such as numbers, letters and ponctuation are omitted from this table. Of course, some keys are missing. But I dont plan to use this keyboard for programming or playing games so it should be fine. Anyway, if I ever need other keys, I'll be able to implement them.
Kenwood key PS/2 Key Comments
Power ESC
Confirm to +100 F1 to F9
Delete Backspace The delete key is located where the backspace key normally is.
Disc.Sel. Tab
P.mode \
Check insert
Clear Delete
Set Home
Mode End
Cursor L Left arrow Absolutely necessary!
Cursor R Right arrow
Charac. Srch. Down Down arrow
Charac. Srch. Up Up arrow
Disk Skip Down Page Down
Disk Skip Up Page Up
Room B + Disc skip Down Shift + Page down Useful for scrolling in xterms and the Linux console
Room B + Disc skip Up Shift + Page up
Cont Play Ctrl + ???? Magic key to send the next key between CTRL down and CTRL up events.
Sub Out Monit. Alt + ???? Matic key to send the next key between ALT down and ALT up events.




Schematic


Note: The whole circuit is powered from the PS/2 port.


Firmware

Here's the hex file which must be programmed into the Atmega8: ir2ps2.hex
Fuses bytes for this project: high byte = 0xc9, low byte = 0x9f

For details about how to program an AVR, visit my AVR programming page.

Source code:
The source code is available under the terms of the GPL license. Consult the COPYING file inside the tarball for more information.
ir2ps2-1.0.tar.gz




References

The PS/2 Keyboard Interface: http://www.computer-engineering.org/ps2keyboard/
Interfacing the AT keyboard: http://www.beyondlogic.org/keyboard/keybrd.htm
Petr Simandl - PC keyboard communication protocol: http://www.simandl.cz/stranky/elektro/keyboard/keyboard_a.htm



Disclaimer

I cannot be held responsible for any damages that could occur to you or your equipment while following the procedures present on this page. Also, I GIVE ABSOLUTELY NO WARRANTY on the correctness and usability of the informations on this page. Please note, however, that the procedures above have worked in my case without any damages or problems.

Now you cannot say that I did not warn you :)