ELM622 by ELM Electronics
is a preprogrammed PIC which converts commands from a Sony infrared
remote control into a serial data stream.
An IR receiver using a ELM622 requires no kernel modifications.
This project shows how to build a Linux IR receiver based on the ELM622
and how to use the receiver to control an X application such as xmms.
The software presented in this article converts the IR codes from the ELM622 into X-Window keycodes and sends the keycodes to any X application you specify. The IR codes could as easily be converted into a string of keycodes for more complex commands from a single IR remote keypress. The X IR Remote Control (xirrc) could be used as a second, specialized keyboard.
A complete description of how IR remotes work is beyond the scope
of this article. A detailed reference on the Sony IR format can be
The output of the ELM622 is an asynchronous serial character for every keypress on the remote. The serial data is sent at 9600 baud with 8,N,1 framing. A very nice data sheet is available in PDF format. The ELM622 has eight pins including power, ground, IR data in, and serial data out. There is also an input for CTS, an output for RTS, a reset output, and an output to drive an LED to indicate received data. The following block diagram of the ELM622 is taken from the data sheet.
The schematic for the receiver is shown below.
The schematic was created using gSchem and the schematic file is available
as xirrc.sch. A gSchem symbol for the ELM622 is
available as ELM622-1.sym.
The circuit can be broken into three major functions, a five
volt power supply, a TTL to RS-232 converter, and the IR receiver
The five volt supply consists of diode D2, capacitor C1, and the Zener diode D1. Diode D1 is a 1N4733 5.1 volt Zener available from Radio Shack as Catalog Number 276-565. C1 is a 25 volt 0.1 micro-farad capacitor. Diodes D2, D3, and D4 are all 1N4002 or equivalent.
The TTL to RS-232 converter is the op-amp, resistors R1 and R2, and the +/- 10 volt power supply formed by diodes D3 and D4. Note that we use the Tx data from the computer as the negative supply. The resistors bias the non-inverting input to about 2.2 volts. As the inverting input swings above or below 2.2 volts the output swings between about -9 volts and +9 volts. This swing is more than enough to be recognized as an RS-232 signal.
The IR receiver module has the infrared photodiode, a 38 kHz bandpass filter, automatic gain control (AGC), and a demodulator. The IR receiver used in this project is the Siemens SFH506 (which seems to be out of production). The more popular 38 KHz IR receiver from Radio Shack should work equally well.
Any construction technique can be used since the circuit operates at fairly low frequencies. The unit pictured was built using wire-wrap. You may want to build the power supply parts of the circuit first and test it without the other parts installed.
A Program to Control X Applications
The program presented here is a C program
which reads the serial characters from the ELM622, converts
the IR characters into X keycodes, and sends the keycodes to
a specified X application. You can modify the program to send
a string of characters, not just one.
Part of this program is based on GTKeyboard so this software falls under the GPL.
X-Windows is event driven and has a subroutine, XSendEvent(), which allows one program to send an event, (like a key press) to another program. The xirrc program operates by reading characters from the serial port, converting them to the apropriate keycode, and calling XSendEvent() to send the keycode to the target application. When the program is started it opens the serial port to the ELM622 receiver and then prompts the user to pick a target window (X app) to receive the keycodes.
Before using the program you will need to map the serial characters from the IR receiver to the keyboard keycodes which control your X application. The ELM622 converts some IR commands into ASCII characters and does not convert others. The easiest thing to do is the get a Sony remote or program a universal remote for Sony, and press each button on the remote and record the output from the IR receiver. For example, here is the mapping of a Sony remote to the keyboard commands which control xmms.
|Sony IR codes to xmms keys|
|Sony Code||Sony Command||ELM622 Code||xmms Command||xmms key|