Sunday, June 3, 2012

Configuring LIRC for HVR-1600 in Ubuntu 12.04




As promised, here is the recipe I followed to get LIRC working for my Hauppauge HVR1600 card on Ubuntu 12.04. This includes both the IR Receiver and the IR Blaster. This may work for other Hauppauge cards as well. The hard work was all done by others, for Ubuntu 10.04, this just serves as an updated reference for Ubuntu 12.04. As usual, this info is provided with NO warranty of any kind, so use at your own risk! It's assumed you have basic knowledge of Linux/LIRC/Scripts/etc.

The secret to the HVR1600 is the lirc_zilog kernel module. Once this kernel module is loaded and LIRC is configured, the HVR1600's IR capabilities should work.

Step One: Install LIRC

Step one is easy, just install standard LIRC! You can install it from the Ubuntu Software Center, or, install (or build) it from the command line if you are so inclined. The LIRC version that was installed for me was 0.9.0.

Step Two: Install lirc_zilog

(Note: you might already have lirc_zilog installed, see below).

This part is a bit tricky. The "proper" way to do it would be to install the lirc-modules-source package, apply the lirc_zilog patch, then reconfigure the package to build the kernel modules. The Ubuntu 10.04 recipe for this is here.

However, it does not yet appear that the lirc-modules-source package is available for Ubuntu 12.04. If it were, you would likely have to make some changes to the patch file to get it building under 12.04 (you might find some hints here).

As a shortcut, I found a complied version of lirc_zilog that appears to be 12.04 compatible here. There is a *.deb file for both i386 and 64-bit version (disclaimer: I can't vouch for the security of this site of the files). I find it strange that these files appear in this package but aren't actually in Ubuntu by default - but I'm sure there is an answer to that (if you know, feel free to share).

Download the version applicable to you and open the *.deb file with the Archive Manager (not the Ubuntu Software Center, which it opens with by default).

Find the lirc_zilog.ko file in the archive here: /lib/modules/3.2.0-24-generic/kernel/drivers/staging/media/lirc/

Extract it, and copy it to the following location in your system:
/lib/modules/3.2.0-24-generic/updates/dkms/lirc_zilog.ko

To load the module: sudo modprobe lirc_zilog

If all was successful, you shouldn't get any errors. At this point, you should be able to do lsmod | grep -i lirc_zilog and see:

lirc_dev               19204  1 lirc_zilog

Pro-Tip: To have lirc_zilog automatically inserted into the kernel on boot, add it to /etc/modules

Pro-Tip:  You might already have lirc_zilog installed. As an easy check, in a Terminal, go to /lib/modules and run find . -name "lirc_zilog*. If it finds lirc_zilog, already, you shouldn't have to copy one from another source. However, you'll still have to modprobe lirc_zilog to get it loaded and add it to /etc/modules to have it run boot.


Step Three: Install the HVR1600 IR Firmware files

I believe this can be found here, and a few other locations on the web.

This file needs to be copied here: /lib/firmware


Step Four: Configuration Files

You need to modify the following two files:

/etc/lirc/hardware.conf
/etc/lirc/lircd.conf


First, we modify hardware.conf to get lirc_zilog to be loaded. Add or modify the following lines (if necessary):

REMOTE_MODULES="lirc_dev lirc_zilog"
REMOTE_DEVICE="/dev/lirc0"
START_LIRCD="true"
LOAD_MODULES="true"

As for lircd.conf, again, a working one for my card was found here. I believe you can even put the relevant parts in its own file and use an include directive if you'd like.

Step Five: Take a deep breath

You're almost there! At this point, the following two things should work:

From a terminal, run "irw". Point your HVR1600 at the IR Receiver and press some buttons! If irw is working correctly, you should see some response, like:

$ irw
00000000000017a5 00 OK Hauppauge_350
0000000000001795 00 Down Hauppauge_350
0000000000001794 00 Up Hauppauge_350

This means your IR Receiver is working.

To test the IR Blaster, use the irsend command. At this point, it doesn't matter what code set you use, you just want to get the light to blink. For example:

$ irsend SEND_ONCE blaster 0_130_KEY_0

Note that the name "blaster" was the name chosen in "lircd.conf" from above....if you used another name insert it there.

Step Six: Final configuration

If the IR Blaster and Receiver are responsive, you're pretty much golden. All that remains is a bit of extra configuration.

To get the IR Receiver to do "cool" things (e.g. work MythTV and/or launch applications), you want to configure a ".lircrc" file. This should be in your Home directory.

Each command to be sent to a specific application has an entry that looks like this:

begin
prog = mythtv
button = LEFT
repeat = 3
config = Left
end

Each starts with "begin" and ends with "end".

button = The button on the remote which will cause the command
prog = The program to send the command too.
config = The command to send to the program
repeat = What to do when a key is repeated. 0 ignores repeats. A positive value (n) sends the command to the program every "nth" times.

Obviously, you need a lot of commands to get various buttons working. To get you started, here is a .lircrc file very similar to the one I use.

Pro-Tip: To get a remote button to start a program, instead of just being interpreted by one, set "prog" to irexec and "config" to the command line-method of starting the program. Remember that irexec must be running in the background for this to work, so you can set it up as an Ubuntu start-up application.

For the receiver, you need to figure out what code set the device you are sending commands to uses. One again, a script is already developed for this. This will send the Power command to the device. Once you see it respond, you've found the right code set. For example, in the command I have above, the code set being used was 0_130 code set.

You'll most often be using this to change the channel, but you can do other things as well. You can find some example change_channel scripts here. Don't forget that in order for MythTV change the channel, you need to configure the backend to post to the script.

At this point you should be in good shape, but you might require some additional modifications to get things "quite right" (geeks are never happy, are we?)

My only concern is that some point along the line, a Linux kernel change will cause lirc_zilog to stop working. But I'll cross that bridge when I come to it...either by getting it building from source or finding it compiled elsewhere. I hope you found this guide helpful.

References and special thanks!
http://wilsonet.com/?p=40
http://www.blushingpenguin.com/mark/blog/?p=24
http://www.bsntech.com/bsntech-blog-mainmenu-321/computers-mainmenu-281/1762-getting-your-hauppauge-hvr-1600-remote-control-to-work-in-ubuntu-1004-lucid.html
http://pkgs.org/download/linux-image-3.2.0-24-generic










9 comments:

  1. Nice review. You should check out the below blog as well.

    http://jimmzmatt.blogspot.in/2012/05/ubuntu-1204-precise-pangolin-at-glance.html

    ReplyDelete
  2. Thanks for the post. I was able to get it working following your guide but I had to make sure I had the latest kernel updates. The original kernel that ships with mythbuntu is 3.2.0-23-generic. Trying to apply the zilog module gave an invalid format error. The latest kernel 3.2.0-29-generic loads everything fine. Only thing I did differently was I used /etc/rc.local to load the module on boot.

    ReplyDelete
  3. Thanks for this post, Jay!

    I built a mythtv system in 2010 using Ubuntu 10.04, and it took me a couple of weeks to get my HVR-1600 IR to work. I needed to grab Jarod Wilson's Fedora source and patch it to build on Ubuntu. Recently, I rebuilt my system from scratch using MythBuntu 12.04.1. Using your recipe, my IR was up and running in a couple of minutes. MythBuntu 12.04.1 includes the lirc_zilog kernel module, there was no need to install it.

    ReplyDelete
  4. Glad to hear that David! All the best :)

    Jason

    ReplyDelete
  5. Hi Jason

    Thank you very much for posting this guide!
    Finally got IR blaster responding so I can set it up to control my Shaw Cable DCT700 box

    Before coming across your guide, I had hit the following roadblocks:

    1. I could find no documentation on lirc.org suggesting to use lirc_zilog module for a HVR-1600. I found a 2009 post on ubuntuforums suggesting it, but it said you had to compile and patch it yourself and the instructions were too old to run.

    I finally found the module already comes with my 3.2.0-39-generic kernel in the staging directory if you apt-get install kernel sources. All you have to do then is type sudo modprobe lirc_zilog and you have got it loaded.

    2. Next, I read the firmware link to haup-ir-blaster.bin on a few pages (including your instructions above), but I thought I had already installed it as I had already installed the 3 firmware files needed to view television mentioned on the mythTV page for the hvr-1600. I finally figured out you have to install this fourth firmware file for the IR functions.

    3. Although ubuntu distros (I use linux mint) come with hauppuage compatible lircd.conf file in /use/share/doc/lirc/remotes, I could not find anything about what values to put in hardware.conf to work with hvr-1600.


    I went on sourceforge homepage for LIRC hoping to find a support forum to get some help. On the homepage, there is a very amusing post by some poor fellow having a total meltdown over his frustration to get his tv card to work in linux. (I feel your pain brother!!!)

    I am surprised it survived moderation, so I will reprint it here before it gets disappeared :

    one of the "BEST" illustrations of what open source is: IT WILL MAKE SOMETHING SPECIALLY DESIGNED TO PISS YOU OFF SO YOU WILL REALLY CONSIDER BUYING COMMERCIAL SOFTWARE BE CAUSE OPEN SOURCE IS ^@&$ ! afaik this is the only solution for using remotes on linux ... BUT WHO THE HACK MADE YOU SO SMART ?!? and (if you don't accept the obvious reason i just typed above) ... WHY ?!? your STUPID program is SOOOOOO SMARTTTTTTT that it decided to suspend my system be cause i pressed "wrong" button on remote and as a result EVERYTHING CRASHED and why i'm pissed off, hmm, nothing much, except i have a raid on my system I HAD A VMWARE RUNNING ON MY SYSTEM so, i know what you gonna say, you gonna say that it is my fault (OFC, ALWAYS) it is my fault that i use the system with all potential, excuse me ! KILL YOURSELF YOU IDIOT !!!!! (…less)


    I was getting very close to this fellows blood pressure level until I found your post.

    I would like to post a link to your blog instuctions and to quote them on forums.linuxmint.com so they are more visible. Let me know if you have any objections.

    Thanks again

    Dixon

    ReplyDelete
  6. Hi Dixon!

    Thanks very much for your post! It's always wonderful to know that some of my efforts have benefited another.

    Please feel free to link to my post anywhere that would be topic appropriate.

    There is also a link to my guide on the following resource:
    http://linuxtv.org/wiki/index.php/Hauppauge_WinTV-HVR-1600

    The folks on the forums might be interested to read it as well, along with the original (though now-locked) guide:
    http://www.mythtv.org/wiki/Hauppauge_HVR-1600

    All the best! Have a great day!

    ReplyDelete
  7. Good Day Jay,

    Thanks for taking the time to put this together. I used your instructions a couple months ago, and was able to successfully get the HVR1600 blaster working with my DISH Network 311 receiver. For some reason, my blaster quit working and I cant get it going again. I have even tried a fresh install and following your guide, however still hitting a roadblock. The lirc_zilog module is loaded, i am able to see Hauppauge_350 commands come through the IRW command, and IRSEND SEND_ONCE blaster 0_130_KEY_POWER (or any other command) is making the IR blaster LED flash, however, I am unable to find a code set that will make the DISH receiver respond. I have tried the codeset "SEND_POWER" script (just as I did the first time) and none of the codes are working. Originally the 0_130 set was all I needed. Any other ideas as to what could be wrong? I am at the limit of my linux troubleshooting abilities... Thanks again!

    -dan

    ReplyDelete
  8. Hi Dan,

    Thanks for your reply!

    One issue I have with my blaster is that it only works in very close range. It must be pretty much directly in front of the IR receiver on the box. I take a flash light and run it over the receiver to make sure I find the correct point, then attach it directly in front with some clear double sided tape, or scotch tape. Since the blaster lead is translucent, this shouldn't interfere with the operation of the ordinary remote.

    Also, I know you said the LED is flashing, but there could still be a hardware problem. One tip is to take an ordinary digital camera (with a screen), and point the IR blaster at the sensor. When you send the IR Blaster command, you should see it light up on the digital camera (IR isn't visible to human eyes, but you can see it with the camera). You can also try this with any ordinary remote to make sure to make sure it works.

    That's all I can think of for now. It does seem like a hardware issue is more likely, but perhaps double check the receiver itself for any settings which might be interfering.

    Here is a page that might give you some more help:
    http://www.mythtv.org/wiki/DISHNetworkLIRCConfiguration

    Best of luck!

    ReplyDelete
  9. Thank you so much for posting this. I just reinstalled my mythbox with Mythbuntu 14-something and my Hauppauge 1600 did not work out of the box. I followed your instructions and it worked. I did have to reboot between step 3 and 4 (for the firmware, I think). Now my remote works. Thanks again!

    ReplyDelete