Something that was important to me when creating this linux music player was that it had to be as close to appliance-like as possible. That is, I want to be able to control it easily. That is, I want it to be just another stereo component. Imagine sitting on your La-Z-Boy enjoying your music coming out of your linux music player. The wife says, “Time to go.” Better stop the music. Ok, pull out iPhone, unlock it, find the iOS app (in my case MPoD), open it, then tap stop. Now imagine it was the 80s, and you were sitting on your La-Z-Boy listening to your music out of your CD player (what’s a CD?). The wife tells you it’s time to go. Pick up the remote, hit stop. In this post, I will try to replicate this experience.
And it will only cost you $5! All you need is a USB IR receiver, remote control, and lirc.
This combo is made for Windows Media Center Edition, but you can make it work with linux pretty nicely with a few limitations. The ir receiver is marked as IR603N and the remote is an RC118N. They seem pretty solid for $5. Last but not least it shipped from the US! So I didn’t have to wait the 10-15 business days that it normally takes to receives items like this from China.
When you plug this ir receiver into your computer, it may work out of the box…kind of. Mint 17 uses a kernel that recognizes these MCE ir receivers as a human interface device like a keyboard. If you press the up button, it will be like you pressed the up key on your keyboard. I actually hate that it does this, so we’ll disable it. What I want the remote to do is send a signal that the ir receiver recognizes which then kicks off a script. I want it to work despite any program Cinnamon shows active or inactive.
Install necessary packages.
sudo apt-get install mpc lirc
mpc — is a command line client for mpd. mpd is the music player I use for my liva project.
lirc — is what allows us control our computer with an ir remote.
At the end of the install this screen will pop up.
You might be tempted to pick one of the MCE remote configurations. Don’t. It won’t be much different from what’s already supported in the kernel. Instead choose
Linux input layer (/dev/input/eventX)
Press enter, then choose none when asking for the transceiver. This ir receiver is just a receiver.
Since we chose the Linux input layer option as the receiver, we are then asked which input device we should pick. Go for the Formosa IR603. Also, copy the location of the IR603 because we will use it later. Then press enter. Your ir receiver should now be activated.
If you ever want to go back to this configuration screen just do this:
sudo dpkg-reconfigure lirc
lircd.conf — recording the buttons on your remote.
First we need to back up our old configuration file.
sudo cp /etc/lirc/lircd.conf /etc/lirc/lircd-og.conf
Next we want to list the names of the key labels we can use in the next, next step. Memorize the list. All of them.
Make sure lircd (lirc daemon) is not running.
sudo killall lircd
Now let’s record the buttons on your remote. Just follow the directions given by the program.
sudo irrecord -f --driver=devinput --device=/dev/input/by-id/usb-Formosa21_IR603_HID_MCE-event-kbd /etc/lirc/lircd.conf
After you’re done. You can test your remote by using this command:
As reference, this is the lircd.conf file I’ve created:
# Please make this file available to others # by sending it to <email@example.com> # # this config file was automatically generated # using lirc-0.9.0(devinput) on Mon Jul 14 12:19:24 2014 # # contributed by # # brand: lircd.conf # model no. of remote control: # devices being controlled by this remote: # begin remote name lircd.conf bits 56 eps 30 aeps 100 one 0 0 zero 0 0 pre_data_bits 8 pre_data 0x0 gap 35953 toggle_bit_mask 0x0 begin codes KEY_POWER 0x04000400010082 0x01008E00000001 KEY_PREVIOUSSONG 0x040004000C00B6 0x0100A500000001 KEY_NEXTSONG 0x040004000C00B5 0x0100A300000001 KEY_REWIND 0x040004000C00B4 0x0100A800000001 KEY_FASTFORWARD 0x040004000C00B3 0x0100D000000001 KEY_PLAY 0x040004000C00B0 0x0100CF00000001 KEY_PAUSE 0x040004000C00B1 0x01007700000001 KEY_BACK 0x040004000C0224 0x01009E00000001 KEY_PROPS 0x040004000C0209 0x01008200000001 KEY_STOPCD 0x040004000C00B7 0x0100A600000001 KEY_PROGRAM 0x040004000C008D 0x01016A00000001 KEY_VOLUMEUP 0x040004000C00E9 0x01007300000001 KEY_VOLUMEDOWN 0x040004000C00EA 0x01007200000001 KEY_CHANNELUP 0x040004000C009C 0x01019200000001 KEY_CHANNELDOWN 0x040004000C009D 0x01019300000001 KEY_UP 0x04000400070052 0x01006700000001 KEY_DOWN 0x04000400070051 0x01006C00000001 KEY_RIGHT 0x0400040007004F 0x01006A00000001 KEY_LEFT 0x04000400070050 0x01006900000001 KEY_OK 0x04000400070028 0x01001C00000001 KEY_MUTE 0x040004000C00E2 0x01007100000001 KEY_RECORD 0x040004000C00B2 0x0100A700000001 KEY_1 0x0400040007001E 0x01000200000001 KEY_2 0x0400040007001F 0x01000300000001 KEY_3 0x04000400070020 0x01000400000001 KEY_4 0x04000400070021 0x01000500000001 KEY_5 0x04000400070022 0x01000600000001 KEY_6 0x04000400070023 0x01000700000001 KEY_7 0x04000400070024 0x01000800000001 KEY_8 0x04000400070025 0x01000900000001 KEY_9 0x04000400070026 0x01000A00000001 KEY_NUMERIC_STAR 0x040004000700E1 0x01002A00000001 KEY_NUMERIC_POUND 0x040004000700E1 0x01002A00000001 KEY_CLEAR 0x04000400070029 0x01000100000001 KEY_ENTER 0x04000400070028 0x01001C00000001 end codes end remote
Press some buttons on your remote, you will see the button presses displayed on the screen.
lircrc — configuring the remote script launcher
This file allows you to configure your remote buttons to do specific things like running a command. For example you can have the power key send
sudo shutdown -h now which will shutdown your computer. In my lircrc file, I’ve configured the remote to send commands to control mpd. You can do this using mpc which we installed earlier. For instance,
mpc stop stops mpd.
mpc toggle will play or pause the music based on what state you’re in. More information is available at the lirc site.
Below is an example of my configuration.
begin prog = irexec button = KEY_LEFT config = /usr/bin/mpc prev repeat = 0 end begin prog = irexec button = KEY_RIGHT config = /usr/bin/mpc next repeat = 0 end begin prog = irexec button = KEY_OK config = /usr/bin/mpc toggle repeat = 0 end begin prog = irexec button = KEY_PREVIOUSSONG config = /usr/bin/mpc prev repeat = 0 end begin prog = irexec button = KEY_NEXTSONG config = /usr/bin/mpc next repeat = 0 end begin prog = irexec button = KEY_REWIND config = /usr/bin/mpc prev repeat = 0 end begin prog = irexec button = KEY_FASTFORWARD config = /usr/bin/mpc next repeat = 0 end begin prog = irexec button = KEY_PLAY config = /usr/bin/mpc play repeat = 0 end begin prog = irexec button = KEY_PAUSE config = /usr/bin/mpc pause repeat = 0 end begin prog = irexec button = KEY_BACK config = mpc random repeat = 0 end begin prog = irexec button = KEY_RECORD config = /usr/bin/mpc repeat on & /usr/bin/mpc single off config = /usr/bin/mpc repeat on & /usr/bin/mpc single on config = /usr/bin/mpc repeat off & /usr/bin/mpc single off repeat = 0 end begin prog = irexec button = KEY_STOPCD config = /usr/bin/mpc stop repeat = 0 end
I’ve run into one limitation with this particular IR receiver. I’m unable to record all IR signals, that is, not just the one the included MCE remote sends (there are even a few on the MCE that can’t be recorded). I know the receiver can sense the signals because when I press a button in front of the receiver, the led on the receiver flashes. This could be related to how I configured lircd though.
Integrating with current stereo system
To integrate all this with my current stereo system, I had to get it to work with my universal remote. I didn’t want to have to use a separate remote to control just control the linux music player. My Sony RMVLZ620 universal remote did not have any presets for MCE remotes, but lucky for me, the remote does include a learning feature which had no problem learning the MCE signals.