Preamble
Intro
This is a guide on building a homebrew (that means, not shop-bought) LIRC (Linux Infrared) receiver, and setting it up to work with your Ubuntu Feisty installation.
The device itself will use very few componants, and will connect via the line-in port of your sound card. LIRC can be installed from the Ubuntu repositories. You don't need to install the kernel source, do *any* compiling, or worry about what happens when a kernel update comes along! The whole process is easy; I did this when I was 15.
Background on LIRC
LIRC allows you to use a remote control to control some of your favourite apps. MythTV (a PVR system), VLC (A video player) and a lot of music players all have a LIRC interface. You can run any command-line command from LIRC (such as "audacious --play-pause") too, so it gives you a huge range of possibilities. I've got buttons to blank my screen, lock it, etc. Read: the sky is the limit.
All this is controlled through a remote control. You _could_ build one, but there isn't much point. A huge range of remote controls are supported.
Sources
http://people.inf.ethz.ch/mringwal/lirc/ - Used for schematic
http://lirc.org/html/audio-alsa.html - Information on the LIRC ALSA drivers
Various help from lots of people
Requirements/Materials
- Ubuntu, running feisty fawn (I previously compiling LIRC on Edgy, which also worked, but a repo install should work on any version of ubuntu with lirc in the repos. I tested in an x86 architecture, but again, it shouldn't matter)
- A full duplex sound card with a 3.5mm input port (for example, mic or line-in) that you don't mind using while you need to use LIRC
- A +5V power source (USB, Motherboard, shop-bought adapter, serial port... discussed later)
- A soldering iron, some solder.
- 3.5mm Audio jack/wire. You can use old headphones for this, or buy one from a shop.
Electrical componants:
- TSOP 1738 (The IR componant)
- 4k7 resistor
- 1k resistor
- 100nF capacitor
Step 1: Circuit wizardry
Here is a schematic of the circuit you'll build, courtesy of the first aforementioned guide:
First thing you need to worry about is a power supply. There are a few ways of going about this. You need 5V, and there are lots of things in the computer that supply it. Find a spare pin on the motherboard, or strip a serial / usb lead and fiddle around with a voltmeter. You'll soon find +5V. Or you can be lazy, like I did. I bought an adapter from a shop that can switch its voltage supply, etc. To save ruining a perfectly good adapter, I also bought something of an extension cable for this, which is cheaper and I don't mind dedicated its life to this specific project. Some photos:
The adapter I used
Connecting the adapter up to the extension: adapter wire on right
You need to get hold of the components above. If you go to a school, college, ask if you can get the resistors/capacitor. My school let me use them. if that doesn't work, chances are they won't notice they're gone . If stealing doesn't appeal to you, talk to anyone you know who might be willing to part with them. If all else fails, order some, but it will cost a bit more because you aren't buying in bulk. The IR chip will probably need to be ordered anyway.
I'm not going to go into how to solder, there are other guides for that sort of thing. Here's the jist of setting up the circuit:
- Set up your power supply. If you're using my method, cut the wire, plug it in, and figure out which wire is positive (using a meter)
- Solder stuff! Connect your power supply (but make sure it's off!) to the IR chip. Connect up ground too. You'll have one "leg" of the chip remaining, the output
- Solder the resistors together, and then to the IR chip. Solder the capacitor between them.
- Cut and strip your headphone wire (or whatever you are using). If it's stereo, you'll have two wires, each surrounded by more wire (which is ground). You only need one channel. Strip the inner wire (the coloured one) and connect this to the free leg of the capacitor. Finally, connect the other end of the resistors in series to the headphone ground (the outer, protective wire). Yay!
Step 2: Make a case
This is a little more imaginative. You can mount the circuit inside your computer, but I didn't bother. I actually got an old audio cassette case, cut holes in it, cellotaped everything down, and then cellotaped it to the top of my monitor:
It's not pretty, but I don't mind. It does the job and keeps the circuit safe.
Step 3: Check the circuit works
If you haven't already, connect everything up. Put the audio jack into the line-in of your sound card. Connect the power!
(side note: tapping one of the legs of the capacitor sends a very low base note. if you have the speakers for it, try it. it's pretty cool )
Now, open your sound settings. You can do this from the GNOME menu (Applications > Sound and Video > Volume Control) or from the command line:
Code:
$ gnome-volume-control
You can also use alsamixer for this if you prefer to use terminal.
Go to Edit > Preferences. Make sure the following are checked: Line-in, Line-in capture, capture.
Hit close on the preferences window. Under the "playback" tab, locate "Line-in". Raise the volume to full, and be sure it isn't muted (icon at the bottom). Now find a remote control, any! VCR, DVD, TV, Stereo, whatever. We're just testing here. Press some buttons. You'll hear some sci-fi-ish noises. YAY! That means your circuit is working.
Not hearing anything? Check your volume is on, your speakers on/connected, that line-in is unmuted, etc. Check your circuit has power with a meter, check the solder joints and that you've soldered stuff to the right pins of the IR chip.
Step 4: Getting LIRC to work
Code:
$ sudo apt-get install lirc lirc-x
Install any/all dependencies.You need the "universe" repo enabled to run the above. To enable it, check out the excellent wiki page: https://help.ubuntu.com/community/Repositories/Ubuntu
Now to do some configuring. You need a remote control that LIRC will work with. That's any remote control, however they all need configuring. That means converting the noises you heard earlier into button codes. Thankfully, people submit their files for this sort of thing:
http://lirc.sourceforge.net/remotes/
I went through my entire house looking for remotes. Eventually my dad pointed out that Philips had invented the RC-5 specification, so any Philips remotes would be a safe bet. Luckily it was. My Phillips VCR remote was supported, which is nice.
If you can find a supported remote:
Great! Download the file to your desktop. Then:
Code:
~/Desktop$ sudo mv filename /etc/lirc/lircd.conf
If you can't find a supported remote:
You may need to make the configuration file yourself. There are guides around for this, google it. I'll add links to this guide later.
-----
That's one half of the lirc configuration. The next step is to launch the lirc daemon (lircd). This runs as root.
Code:
$ sudo lircd --driver=audio_alsa -d hw@48000
A little explaination! The --driver=audio_alsa sets up LIRC to use the ALSA driver, which means it looks at sound input
-d hw@48000 is the device. hw is the sound card itself, so you can set this to hw1,0 if you are using your second sound card. the 48000 bit is the sample rate. Lower than this, and lircd doesn't pick up all your button presses.
Step 5: Test LIRC configuration
First, set up line-in as your capture device. With the gnome-volume-control window you left open, go to the "switches" tab. Check the "line-in capture" box. Move to the "recording" tab. Make sure the volume is on max and that it is unmuted. Finally, check that the line-in is still on full volume and still unmuted.
Open a terminal. Run:
Two things can happen here. Either the command will end straight away, or hang there. The former is bad, it means it couldn't connect to the LIRC session. Start lircd with -n as an argument to see what the trouble could be.
Otherwise, hit buttons! With any luck you should see their relevant codes showing up. For example, when I press 1, 2, 3 I get:
Code:
$ irw
0000000000001141 02 sys_05_command_01 PHILIPS_RC-5
0000000000001142 00 sys_05_command_02 PHILIPS_RC-5
0000000000001143 00 sys_05_command_03 PHILIPS_RC-5
That's good news, again. If your button-pressing yields nothing, you've got a problem. First, check that the circuit is still working (do this by unmuting line-in). If that works, check the config file you have is suitable for your remote control. Try killing lirc (sudo killall lircd) and starting it again (as above).
Step 6: LIRC application configuration
Next we need to turn the kind of thing returned by irw into useful commands. A few apps have lirc modules build into them, which is nice. Others, you can do command-line control. This configuration revolves around a configuration file in your home directory, called .lircrc
Open your favourite text editor and save as this file. Configuring this file is covered in the LIRC documentation: http://www.lirc.org/html/configure.html (scroll down to "The .lircrc file format"). Here's the just of it anyway:
Code:
begin
remote = PHILIPS_RC-5
prog = vlc
button = sys_05_command_34
config = key-next
repeat = 0
end
Above is a snippet of my configuration file. It uses data returned from irw. You can see the remote is set to PHILIPS_RC-5 (which is from irw) and the button is sys_05_command_34 (again, from irw). VLC provides a LIRC interface, so I can set "prog" to vlc. Note that this isn't a bash command, as only apps which have LIRC plugins/interfaces can be used here. The "config" is the big passed to VLC, in this case telling it to go the next item in the playlist. repeat is explained by the above documentation:
repeat tells the program what shall happen if a key is repeated. A value of zero tells the program to ignore repeated keys. Any other positive value 'n' tells the program to pass the config string every 'n'-th time to the according application, when a key is repeated. The default for repeat is zero.
Want to run commands? Here's another snippet.
Code:
begin
remote = PHILIPS_RC-5
prog = irexec
button = sys_05_command_31
config = gnome-screensaver-command -a
end
Here, irexec is the program. irexec accepts applications in the config. I've set config to gnome-screensaver-command -a, which blanks the screen for me.
--
The next step is getting this configuration in action. First, restart lircd.
Code:
$ sudo killall lircd
$ sudo lircd --driver=audio_alsa -d hw@48000
Finally, to put the configuration in action, start irexec
Start the apps you configured, have a play around!
Step 7: Finishing up
You probably don't want stupid beeping whenever you hit a button. Go back into Volume Manager and mute line-in (DON'T mute capture or switch the capture device).
Also, running all those commands is a hassle, so:
Enter:
Code:
#!/bin/bash
lircd --driver=audio_alsa -d hw@48000
Save this as "lirc" (without the quotes) in /etc/init.d/
Exit gedit, then:
Code:
$ cd /etc/init.d
$ sudo update-rc.d lirc defaults
$ sudo chmod +x lirc
That starts lircd on boot (as root). You can't put irexec in there because that needs to be run as your user. Add that to your GNOME startup (System > Preferences > Sessions).
You're all done! No compiling, nothing! I'd do this over buying a receiver any day!
Bookmarks