IR Blasters

IR blasters are needed when Mythbuntu must change channels through a set top box or digital transport adapter instead of just being able to record clear channels off of the antenna input. Usually, the set top box or digital transport adapter is required by a cable company so that they can control which channels you receive in a lineup or pack more services onto the wire using the most efficient technology. Whatever the reason, Mythbuntu must have some way of controlling the STB or DTA to cause it to change when it needs to record a particular program.

Many of the IR receivers also support IR blasters (transmitters). So to do some of the encoder cards. These are the steps to setting up an IR blaster for use by MythTV.

The first step is to make sure that you have a copy of LIRC that supports the IR receiver/transmitter that you will be using. You can take a look at the Remote Controls section (above) for notes on how to build LIRC for a number of remote control receivers but, essentially, this process begins by checking to see if LIRC already has support for the receiver/transmitter built in. You can check whether it does with the following command:

     lircd --driver=?

This will give a list of drivers that are built into the lircd that is installed on the system. If you see the one you need (e.g. "tira" for the Tira-2, "irman" for the Ira, or "iguanaIR" for the Iguana Works product), you are probably in business and you can skip ahead to the irrecord step, below. Otherwise, if you don't see the required driver in the list, or you know for sure that IR blasting with your receiver (e.g. the TopSeed) requires a patch to the LIRC source code, you'll need to download the latest LIRC software from http://www.lirc.org/software.html and build LIRC.

And, note that even if you do see the driver in the list, you still may need to download the latest LIRC because some of the devices that you'll want to control (e.g. the Pace DC50X DTA) may use remote control features that are not available in earlier releases of LIRC (such as XMP, which is only in 0.8.6). If that's the case, download and build the latest version with support for your IR device included.

Once you've downloaded the software, you can uncompress it and unpack it, then build LIRC with the appropriate driver enabled (here we show irman):

     cd lirc
     tar -xvzf lirc-0.8.6.tar.gz
     cd lirc-0.8.6
     ./configure --with-driver=irman
     make

To install the new lircd, become super user and do the install:

     sudo make install

This should put the new lircd in /usr/local/sbin while keeping the original in /usr/sbin -- handy if you need to fall back on the original lircd.

The next step is exactly like one of the steps that must be done to set up a remote control to control Mythbuntu. Begin by making sure that lircd is not running (if you are not doing this for the first time) and then record the STB/DTA's remote's buttons as follows (picking the appropriate invocation of irrecord, depending on which IR receiver you are using):

     [sudo /etc/init.d/lirc stop]
     sudo irrecord -f -H tira -d /dev/ttyUSB0 Tira-2_myremote.conf
     sudo irrecord -f -H irman -d /dev/ttyS0 Ira_myremote.conf
     sudo irrecord -f -n -H iguanaIR -d /dev/iguanaIR/0 Iguana_myremote.conf
     sudo irrecord -f -d /dev/lirc0 MCE_myremote.conf

When you run irrecord, you should follow its instructions. There are notes in the Remote Controls section (above), that you should read about how to record a remote. Be sure to carry out the instructions, as described, because failure to do so will lead to the remote not being set up correctly.

Note that the original MCE receiver doesn't do a very good job of catching the remote codes from many remote controls. If it doesn't, you will most likely get a config file that is recorded in raw mode. In all probability, this file will be junk but you never know. You can analyse it with irrecord to see if there is anything good in it like this:

     irrecord -a MCE_myremote.conf > MCE_myremote-codes.conf

In fact, for some of the DTA remotes that use newer transmission protocols (e.g. Pace DC50X), none of the IR receivers do a very good job of catching their codes. You may get a raw file that cannot be analysed by irrecord or you may get what looks like a good config file but is actually filled with bad or duplicate codes.

In other cases (e.g. Motorola DCT700), the raw file may look good and even appear to work but one or two keys, for example the zero key, will not be received by the DTA or STB. This may make channel changing a challenge.

Many of these devices use the newer XMP protocol from UEI. Rumors are that the a**holes at the cable company (you know who you are) deliberately picked this protocol because it is a b***ard to record and thereby thwarts attempts by owners of non-cable-company DVRs to use their DVR to record the cable company's content. Conspiracy theory or truth? Who knows? But, they are right about one thing. Capturing the protocol is a b***ard.

For these remotes, you may have to start with one of the generic config files:

     http://lirc.sourceforge.net/remotes/generic/

Here is an example of how to do it with the Pace DC50X, using a serial receiver, after downloading the XMP (renamed to XMP.conf) generic file:

     cp XMP.conf Ira_myremote
     sudo irrecord -n -H irman -d /dev/ttyS0 Ira_myremote

After you capture the remote's keys, the Ira_myremote file will be left untouched and new file named Ira_myremote.conf will be created with the captured keys.

Good luck. In truth, the problem undoubtedly lies with irrecord. Despite the fact that the prototype XMP file clearly says "flags XMP", irrecord does not seem to take this fact into account and the protocol does not get captured properly. Nor does using the raw flag yield much joy. If irrecord "thinks it knows" what the protocol is, it doesn't record a raw file regardless of the flag being set. And, we've never seen it not "think it knows" all about the XMP protocol, despite the fact that it has no clue....

If you can't get irrecord to capture your remote's codes, you can look around on the Internet. There are plenty of smart people out there who hate the cable company as much or more than you do. If you're in luck, they'll have figured out your remote's codes and posted them on a Web page, somewhere. Essentially, all you need are the key codes for the ten digits and the Enter key, so that Myth TV can change channels on the DTA/STB. Here, for example, are the codes for the dreaded Pace DC50X:

/etc/lirc/lircd.conf:

     # contributed by Mike Silliman
     #
     # brand: Comcast Branded Motorola DTA100 and Pace DC50X
     # model no. of remote control: Unknown, Comcast Label
     # devices being controlled by this remote: Pace DC50X
     #
     # Protocol: XMP-R
     # Device: 62.16
     #
     # Although this remote uses the XMP protocol, this config should still
     # work with lirc 0.8.5 or earlier because we've defined raw codes herein.
     begin remote
        name             PaceDC50X
        flags            RAW_CODES
        eps              30
        aeps             100
     gap              80412
         begin raw_codes
             name One
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 2656 210 763
             210 763 210 763 210 894
             210 763 210 763 210 80413
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 1578 210 1841
             210 763 210 763 210 894
             210 763 210 763 210
             name Two
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 2524 210 763
             210 763 210 763 210 1026
             210 763 210 763 210 80413
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 1446 210 1841
             210 763 210 763 210 1026
             210 763 210 763 210
             name Three
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 2393 210 763
             210 763 210 763 210 1157
             210 763 210 763 210 80413
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 1315 210 1841
             210 763 210 763 210 1157
             210 763 210 763 210
             name Four
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 2261 210 763
             210 763 210 763 210 1315
             210 763 210 763 210 80413
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 1157 210 1841
             210 763 210 763 210 1315
             210 763 210 763 210
             name Five
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 2130 210 763
             210 763 210 763 210 1446
             210 763 210 763 210 80413
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 1026 210 1841
             210 763 210 763 210 1446
             210 763 210 763 210
             name Six
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 1972 210 763
             210 763 210 763 210 1578
             210 763 210 763 210 80413
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 894 210 1841
             210 763 210 763 210 1578
             210 763 210 763 210
             name Seven
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 1841 210 763
             210 763 210 763 210 1709
             210 763 210 763 210 80413
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 763 210 1841
             210 763 210 763 210 1709
             210 763 210 763 210
             name Eight
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 1709 210 763
             210 763 210 763 210 1841
             210 763 210 763 210 80413
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 2787 210 1841
             210 763 210 763 210 1841
             210 763 210 763 210
             name Nine
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 1578 210 763
             210 763 210 763 210 1972
             210 763 210 763 210 80413
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 2656 210 1841
             210 763 210 763 210 1972
             210 763 210 763 210
             name Zero
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 2787 210 763
             210 763 210 763 210 763
             210 763 210 763 210 80413
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 1709 210 1841
             210 763 210 763 210 763
             210 763 210 763 210
             name Enter
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 1841 210 763
             210 763 210 1026 210 1446
             210 763 210 763 210 80413
             210 894 210 1709 210 763
             210 2787 210 1315 210 1315
             210 1157 210 2656 210 13805
             210 894 210 763 210 1841
             210 763 210 1026 210 1446
             210 763 210 763 210
         end raw_codes
     end remote

The raw codes should work with any version of LIRC and any IR blaster. However, you might not experience proper or reliable channel changing using raw codes with some IR blasters and DTAs/STBs (e.g. using the raw codes with the Pinnacle IR blaster and the Pace DC50X often results in a single key press being replicated as two key presses, although using the same raw codes with the MCE or Iguanna IR blaster and the Pace DC50X works fine). If you have a later version of LIRC (i.e. >= 0.8.6) that supports the XMP protocol, you can try a config file that has the generated codes. Using the proper XMP codes seems to work much more reliably, as in this example, once again for the dreaded Pace DC50X:

/etc/lirc/lircd.conf:

     # Please make this file available to others
     #
     # this config file was automatically generated
     # using lirc-0.8.6-CVS(default) on Mon Jan 11 21:34:36 2010
     #
     # contributed by Kirk Bocek
     #
     # brand: Comcast Branded Motorola DTA100 and Pace DC50X
     # model no. of remote control: Unknown, Comcast Label
     # devices being controlled by this remote: Motorola DTA100 & Pace DC50X
     #
     # These are a couple of the cheap digital converters being provided by
     # Comcast as part of their analog shutdown. DTA100 information here:
     # 
     # http://www.motorola.com/Business/US-EN/Business+Product+and+Services/
     #   TV+Video+Distribution/Customer+Premises+Equipment+%28Set-tops%29/
     #   All-Digital+QAM+Set-tops/DTA100_US-EN
     #
     # This remote also has power and volume buttons. You can program these
     # to control your TV. But these DTAs do have internal volume and mute
     # controls. The power button, however, is only for your TV and has no
     # effect on the DTA.
     #
     # Because this remote uses the XMP protocol, this config requires
     # lirc 0.8.6 or later.
     #
     # Generated by starting with the generic XMP protocol configuration:
     # http://lirc.sourceforge.net/remotes/generic/XMP
     # and then using irrecord to add the keys.
     #
     # V.2 - Added Volume Up and Volume Down
     #
     begin remote
     #  name             MotorolaDTA100
        name             PaceDC50X
        bits             24
        flags            XMP
        eps              20
        aeps             300
     one              0    137
     zero             250  710
     ptrail           250
     pre_data_bits    32
     pre_data         0x170F443E
     post_data_bits   8
     post_data        0x0
     pre              250  12921
     gap              81698
     toggle_bit_mask  0x0
         begin codes
             Info                         0x170026
             One                          0x1E0001
             Two                          0x1D0002
             Three                        0x1C0003
             Four                         0x1B0004
             Five                         0x1A0005
             Six                          0x190006
             Seven                        0x180007
             Eight                        0x170008
             Nine                         0x160009
             Zero                         0x1F0000
             Enter                        0x180025
             Last                         0x190051
             ChannelUp                    0x12000D
             ChannelDown                  0x11000E
             Mute                         0x13000C
             VolumeUp                     0x15000A
             VolumeDown                   0x14000B
             Language                     0x150082
         end codes
     end remote

Here is a working config file that can be used with the Motorola DCT700 (or QIP2500) that is preferred by the "other" cable company (or, so they think of themselves):

/etc/lirc/lircd.conf:

     # Contributed by lisat at Launchpad.
     #
     # Modified DCT2000 configuration for use with Verizon-
     # branded Motorola QIP2500 STB and DCT700 DTA.
     #
     # This config should work with lirc 0.8.5 or earlier because
     # we've defined raw codes herein.
     begin remote
        name             DCT700
        flags            RAW_CODES
        eps              30
        aeps             100
     ptrail           520
     repeat           0  0
     gap              100000
         begin raw_codes
     #          Note that numbers, particularly zero, are special.  If you
     #          record the remote with irrecord, you will not get a reliable
     #          sequence for IR blasting.  Quite possibly you will be able to
     #          receive all of the codes from the remote but the trailing
     #          "42050 9000 2250 500", which has been added to all of the
     #          following numeric codes, is often required to make IR blasting
     #          work reliably and repeatedly (a key requirement, when
     #          unattended channel changing is involved).
                name One
                9000 4400 550 4450 550 2150
                550 2200 550 2200 550 2150
                550 2200 550 2200 550 2150
                550 2200 550 2200 550 2150
                550 2200 550 4400 550 4450
                550 4400 550 4450 550 42050
                9000 2250 500
             name Two
             9000 4400 550 2200 550 4400
             550 2200 550 2150 550 2200
             550 2200 550 2150 550 2200
             550 2200 550 2150 550 2200
             550 2200 550 2150 550 4450
             550 4400 550 4450 500 42050
             9000 2250 500
             name Three
             9000 4400 550 4450 550 4400
             550 2200 550 2150 550 2200
             550 2200 550 2150 550 2200
             550 2200 550 2150 550 2200
             550 2200 550 4400 550 2200
             550 4400 550 4450 500 42050
             9000 2250 500
             name Four
             9000 4400 550 2200 550 2150
             550 4450 550 2150 550 2200
             550 2200 550 2150 550 2200
             550 2200 550 2150 550 2200
             550 2200 550 2150 550 2200
             550 4400 550 4450 550 42050
             9000 2250 500
             name Five
             9000 4450 550 4400 550 2200
             550 4400 550 2200 550 2150
             550 2200 550 2200 550 2150
             550 2200 550 2200 550 2150
             550 2200 550 4400 550 4450
             550 2200 500 4450 550 42050
             9000 2250 500
             name Six
             9000 4500 550 2150 550 4450
             550 4450 550 2200 500 2200
             550 2200 550 2200 550 2150
             550 2200 550 2200 550 2200
             500 2200 550 2200 550 4450
             500 2200 550 4450 550 42050
             9000 2250 500
             name Seven
             9000 4450 550 4450 550 4450
             500 4450 550 2200 550 2200
             550 2150 550 2200 550 2200
             550 2200 500 2200 550 2200
             550 2200 500 4450 550 2200
             550 2200 550 4450 500 42050
             9000 2250 500
             name Eight
             9000 4400 550 2200 550 2150
             550 2200 550 4400 550 2200
             550 2200 550 2150 550 2200
             550 2200 550 2150 550 2200
             550 2200 550 2150 550 2200
             550 2200 550 4400 550 42050
             9000 2250 500
             name Nine
             9050 4450 550 4450 550 2150
             550 2200 550 4450 550 2150
             550 2200 550 2200 550 2200
             500 2200 550 2200 550 2200
             500 2200 550 4450 550 4450
             550 4450 500 2200 550 42050
             9000 2250 500
             name Zero
             9000 4400 550 2200 550 2200
             550 2150 550 2200 550 2200
             550 2150 550 2200 550 2200
             550 2150 550 2200 550 2200
             550 2150 550 2200 550 2200
             550 2150 550 2200 550 42050
             9000 2250 500
             name Enter  # Same as OK
             9050 4400 550 4400 550 2200
             550 2200 550 2150 550 4450
             550 2150 550 2200 550 2200
             550 2150 550 2200 550 2200
             550 2150 550 2200 550 4400
             550 4450 550 4400 550
         end raw_codes
     end remote

These raw codes should work with any version of LIRC and any IR blaster.

Once you have the config file for the STB's or DTA's remote, you can either concatenate it to Myth TV's remote information in /etc/lirc/lircd.conf or, if you modified /etc/init.d/lirc to honor the information in hardware.conf, you can set up one config file for Myth TV's remote and one for the STB/DTA. I prefer the later solution, as this snippet from /etc/lirc/hardware.conf shows:

     # /etc/lirc/hardware.conf
     #
     #Chosen Remote Control
     REMOTE="SamsungLN32A450"
     REMOTE_MODULES=""
     REMOTE_DRIVER="iguanaIR"
     REMOTE_DEVICE="/dev/iguanaIR/0"
     REMOTE_LIRCD_CONF="/etc/lirc/IguanaIR_SamsungLN32A450.conf"
     REMOTE_LIRCD_ARGS=""
     #Chosen IR Transmitter
     TRANSMITTER="PaceDC50X"
     TRANSMITTER_MODULES=""
     TRANSMITTER_DRIVER="iguanaIR"
     TRANSMITTER_DEVICE="/dev/iguanaIR/0"
     TRANSMITTER_LIRCD_CONF="/etc/lirc/XMP_PaceDC50X.conf"
     TRANSMITTER_LIRCD_ARGS=""

Note that this configuration has both a receiver and a transmitter and uses two drivers (albeit both the same one). As shown here, /etc/init.d/lirc will start up two instances of lirc and create two pipes, /dev/lircd and /dev/lircd1. When you run irsend, you will need to specify the second pipe for the transmitter. Myth TV (and other applications) should use the first pipe by default.

For the MCE xceiver, only one copy of LIRC must be run. Furthermore, in some earlier versions of LIRC (e.g. 0.8.3) the lirc_mceusb2 module must be used instead of lirc_mceusb to drive the xceiver. You can find all of the details about which versions of the MCE remote will also allow IR blasting and which kernel module to use at:

     http://www.mythtv.org/wiki/MCE_Remote

This snippet from /etc/lirc/hardware.conf shows how to set things up (again with the modified /etc/init.d/lirc):

     # /etc/lirc/hardware.conf
     #
     #Chosen Remote Control
     REMOTE="Windows Media Center Remotes"
     REMOTE_MODULES="lirc_dev lirc_mceusb"
     REMOTE_DRIVER=""
     REMOTE_DEVICE="/dev/lirc0"
     REMOTE_LIRCD_CONF="/etc/lirc/MCEUSB.conf"
     REMOTE_LIRCD_ARGS=""
     #Chosen IR Transmitter
     TRANSMITTER="PaceDC50X"
     TRANSMITTER_MODULES=""
     TRANSMITTER_DRIVER=""
     TRANSMITTER_DEVICE=""
     TRANSMITTER_LIRCD_CONF="/etc/lirc/Raw_PaceDC50X.conf"
     TRANSMITTER_LIRCD_ARGS=""

When using irsend, there is no need to specify the second pipe, since there is only one.

Now that LIRC is configured correctly, start it up. If your remote was working before, it should still work (duh).

Incidentally, even slight errors in the config file can cause LIRC to fail silently so be careful. Be especially careful with comments because comment handling leaves a bit to be desired. Inside raw_codes, if the comment character doesn't appear in column 1 or if it doesn't appear on a line that has a command on it, it will silently break the config file and LIRC won't see any of your remotes. Nice, huh? Here's a few examples:

     #         This comment is good
               # This comment breaks the config file
               name Enter  # This comment is OK

To test blasting, you can send commands to the IR blaster as follows:

     sudo irsend set_transmitters 1 2 3 4
     sudo irsend send_once PaceDC50X One

If you compiled your own version of LIRC and you kept the original, you will probably want to use:

     sudo /usr/local/sbin/irsend set_transmitters 1 2 3 4
     sudo /usr/local/sbin/irsend send_once PaceDC50X One

OK, so since humans can't see IR radiation, how do we know if the IR blaster is working? Excellent question. One you'd like to have answered before you tape the IR blaster and the IR receiver together, in your version of a homemade optocoupler, with a half a pound of black tape. The answer is simple. Get your digital camera and turn it on so that its ready to take pictures. Point it at a white wall and depress the shutter release part way. Do you see a circular orange-ish glow bouncing back from the wall in the camera's viewfinder? That's the auto-focus IR range finder's light. If you can see it, you'll be able to see the light from the IR blaster too.

Aim the camera directly down the bore-sight of the IR blaster at its typical working distance. While looking at the IR blaster through the camera's viewfinder, run irsend send_once. You should see a momemtary glow from the IR blaster as it transmits the chosen code. This indicates that all is working correctly. You can also use this method to decide which IR blaster to actually select (instead of selecting them all), before you proceed to writing your STB/DTA control script.

Once you're sure the IR blaster is working, fashion an optocoupler from the IR blaster and the STB/DTA's remote IR receiver (if it has one). Usually, a short piece of tube, say 3/4", of the correct diameter can be employed to hold the blaster and receiver in close proximity to each other, so that the light from the blaster impinges directly on the face of the receiver. When you've arranged them in a suitable configuration, the whole thing can be taped up with black electrical tape, thereby excluding any extraneous light.

If your STB/DTA doesn't have a remote IR receiver, you'll need to position the IR blaster in front of its IR receiver, wherever that is on the STB/DTA box. The double sided tape, supplied with the IR blaster, can be used for this task. Or, black electrical tape may prove helpful.

You may have to experiment with the best location for the IR blaster so that it changes channels reliably on the DTA/STB. In the case of one DTA that we know of (Motorola DCT700), positioning the IR blaster 4-6 inches away from front of the DTA/STB actually makes it work better. Clearly some experimentation may be in order.

The next thing required is a script that can send channel change commands to the IR blaster. You'll need a script that accepts the numeric channel number that Myth sends when changing channels and then sends the appropriate keys to the correct blaster. The name of this script will be entered into the MythTV configuration page that connects the lineup (source) to an input (encoder card) so that MythTV can use it to change channels on the STB/DTA whenever it needs to record something.

The requirement to have a separate script for each IR blaster is annoying. And, we've seen lots of channel changer scripts in Internetland that require you to edit the remote name, LIRC pipe name, etc. into the script before you use it. This too is annoying.

The following script can be used to change channels on any IR blaster (by adding a symlink to it with the blaster number in the linked name) while configuring itself from the information in /etc/lirc/hardware.conf. In short, it is pretty much automagic. Install the following script somewhere convenient (I use /etc/lirc):

/etc/lirc/IRChangeChannel:

     #! /bin/sh
     # Shell script used to send channel change commands to a set top box (STB)
     # or digital transport adapter (DTA) via LIRC.
     #
     # This script is commonly used by applications such as Myth TV to change
     # the channels on a STB/DTA when the STB/DTA must be used to convert the
     # channels that a subscriber can see to a single channel (e.g. when
     # digital channels are to be viewed by the application on channel 3 with
     # an analog decoder card).
     #
     # The application invokes this script and passes the channel number to it
     # as the first parameter.  This script deconstructs the channel number and
     # decides what command sequence the STB/DTA's remote would have to send in
     # order to change to that channel (typically its the channel number,
     # followed by the Enter button).  It sends the channel change commands to
     # the STB/DTA through the IR blaster that was started by lircd.  The
     # information necessary to do this is obtained from the lircd config file
     # /etc/lirc/hardware.conf.
     #
     # If you need to send commands to a different IR emitter than number 1,
     # you can alias this script and use the aliases to send to any emitter
     # from 1 thru 4.  You must set up the aliases as follows:
     #
     #   ln -s IRChangeChannel IR1ChangeChannel
     #   ln -s IRChangeChannel IR2ChangeChannel
     #   ln -s IRChangeChannel IR3ChangeChannel
     #   ln -s IRChangeChannel IR4ChangeChannel
     #
     # You can then send commands to the alternate emitters as follows:
     #
     #   /path/to/scripts/IR1ChangeChannel 12
     #   /path/to/scripts/IR2ChangeChannel 22
     #        .
     #        .
     #        .
     #
     # Because of the nature of the way that the program name is determined,
     # you must use some kind of path prefix on the name (i.e. at the very
     # least, use "./IR3ChangeChannel 44").
     #
     # Note that, unless you are using stereo emitters on the IguanaIR, the two
     # emitters on the stick are IR1 and IR3 (two and four are not used).
     #
     # Some DTAs do not change the channel reliably, every time.  Or, they do it
     # fine with one IR blaster and not another.  In this case, if they typically
     # miss some digits and do nothing because of it (i.e. stay on the same
     # channel that they were originally on), you can set CHANGE_TRIES to
     # something other than one (below).  This will cause the script to try
     # changing the channel the number of times given and, hopefully, one will
     # stick.
     ##########################################################################
     # Constants that define how this script works.  Set these up once at
     # install time.
     # Where we load irsend from (depends whether this is a system install or
     # a local build).
     #ew LOAD_PATH=/usr/bin
     LOAD_PATH=/usr/local/bin
     # The delay (in seconds) that we should sleep between each key press (a
     # half a second seems to be a reasonable number).
     KEY_DELAY=0.5
     # The number of times this script should try changing the channel (see
     # above).
     CHANGE_TRIES=1
     # See if we can find the send module in the place where the user told us to
     # look.  If not, we're outta here quick.
     test -f ${LOAD_PATH}/irsend || exit 0
     # The user can symlink to this program to use an emitter other than 1.  We
     # figure this out from our invoking program name.
     Emitter=0
     ProgName=`echo $0 | sed -r s:.+/\([^/]+\)$:\\\1:`
     if [ ! -n "$ProgName" ] || [ "$ProgName" = "IRChangeChannel" ]; then
         Emitter=1
     else
         case "$ProgName" in
             IR1ChangeChannel)
                 Emitter=1
                 ;;
             IR2ChangeChannel)
                 Emitter=2
                 ;;
             IR3ChangeChannel)
                 Emitter=3
                 ;;
             IR4ChangeChannel)
                 Emitter=4
                 ;;
             *)
                 Emitter=1
         esac
     fi
     # Let's get the config file that was used to start lircd with.  It will
     # tell us what remote we're using (hopefully).
     if [ -f /etc/lirc/hardware.conf ]; then
         . /etc/lirc/hardware.conf
     fi
     # We need a remote name.
     if [ -z "$TRANSMITTER" ] || [ "$TRANSMITTER" = "none" ]; then
         exit 0
     fi
     # Figure out where the transmitter is.
     if [ -n "$PIPE_PATH" ] && [ "$PIPE_PATH" != "none" ]; then
         DEV_PATH=$PIPE_PATH
     else
         DEV_PATH="/var/run/lirc"
     fi
     # If there's a transmitter device or driver defined, the lirc init script
     # started a second copy of lircd.
     if [ ! -z "$TRANSMITTER_DEVICE" ] \
         || [ ! -z "$TRANSMITTER_DRIVER" ]; then
         DevArgs="--device=$DEV_PATH/lircd1"
     else
         DevArgs="--device=$DEV_PATH/lircd"
     fi
     # Select the appropriate IR emitter on the device.
     ${LOAD_PATH}/irsend $DevArgs set_transmitters $Emitter
     # Try setting the channel the number of times the user has requested us to
     # do so (some DTAs with some blasters don't get the message the first
     # time).
     Tries=1
     while [ $Tries -le $CHANGE_TRIES ]; do
      # Send the channel number.
      for Digit in $(echo $1 | sed -e 's/./& /g'); do
          case "$Digit" in
              1)
                  Key="One"
                  ;;
              2)
                  Key="Two"
                  ;;
              3)
                  Key="Three"
                  ;;
              4)
                  Key="Four"
                  ;;
              5)
                  Key="Five"
                  ;;
              6)
                  Key="Six"
                  ;;
              7)
                  Key="Seven"
                  ;;
              8)
                  Key="Eight"
                  ;;
              9)
                  Key="Nine"
                  ;;
              *)
                  Key="Zero"
          esac
          ${LOAD_PATH}/irsend $DevArgs send_once $TRANSMITTER $Key
          sleep 0.5
      done
      # Send the enter key.
      ${LOAD_PATH}/irsend --device=/dev/lircd SEND_ONCE $TRANSMITTER Enter
      if [ $Tries -lt $CHANGE_TRIES ]; then
          sleep $KEY_DELAY
      fi
      # Increment the try count, in case we're doing this more than once.
      Tries=`expr $Tries + 1`
     done

Don't forget to set the permissions to execute for everyone. Test the script to see that it changes channels OK. Plug a TV into the STB/DTA, tune it to channel 3, make sure the STB/DTA channel switch is set to 3, and send it a channel change command like this:

     /etc/lirc/IR1ChangeChannel 12

You should see the chosen channel on your TV. Try all of the other digits in your channel numbers, to make sure that all digits work, and try long and short channel numbers. If all of them work, you can cable the STB/DTA up to the input of the appropriate encoder card that you want to use with the DTA/STB.

Proceed to the "Connect source to input" MythTV configuration page. You can get to this page by launching the Mythbuntu Control Center off the desktop menu or, in earlier versions of MythTV, from the frontend, by selecting the Utilities/Setup | Setup | Mythbuntu menus. You must do this on the system that actually has the encoder card installed in it (if you have multiple systems networked to a single backend).

Enter your password to get the Mythbuntu Control Center to launch. From there, pick the MythTV Configuration menu item and then Launch MythTV Setup, once it becomes visible. You will need to shut down the backend to continue.

From the MythTV Setup main menu, pick the Input Connections item. Then, from the list of encoders, pick the encoder card that is physically connected to the STB/DTA. That should bring up the "Connect source to input" page. Under the "External channel change command" field, enter the full path to the change channel script. Make sure the path is absolutely correct because, if you make a typo, MythTV will simply hang for a while and then do nothing (i.e. you won't get any error messges or warnings).

Note that, if you are connecting multiple STB/DTAs to multiple encoder cards, you should set each one up so that it points to the symlinked file name for the appropriate IR blaster that controls the STB/DTA connected to that card. For example, the setup for /dev/video0 might look like this:

     /etc/lirc/IR1ChangeChannel

While the setup for /dev/video1 might look like this:

     /etc/lirc/IR2ChangeChannel

There is no other way to pass the IR emitter number to the channel changer script except by its file name, hence the reason for symlinking aliases to the channel changer script to tell it which IR emitter to change.

Under the "Preset tuner to channel" field, you should enter the channel number that the STB/DTA transmits on (typically it is channel 3). This will cause the encoder card to be set to the

Note that all of the channels in the lineup defined by the video source that is connected to this encoder will be selected by sending the channel number to the STB/DTA via the channel changer script and by presetting the encoder to the chosen channel (e.g. channel 3). If this doesn't work for some of your channels (e.g. you have a mixture of digital channels that can be directly tuned and analog channels that require the STB/DTA), you will need to construct more than one video source (lineup) and assign the separate sources to the disparate encoders.

After you've set up the external channel changer script, you can save the configuration, restart the backend and restart the frontend. From the frontend, pick Watch Live TV. Choose the tuner that you've set up to use the STB/DTA and see if it shows live TV. You should be able to change channels by entering a channel number, followed by Enter or by using the up/down arrows. If you don't see your chosen channel after 3 or 4 seconds, you need to go find out what's wrong with your configuration. Good luck! There are plenty of places for it to go wrong, including where you entered the path name of the external channel changer script. No errors are reported so it helps if you are psychic. If it works, you are basically in business.

Incidentally, some people have pointed out that the "Preset tuner to channel" field doesn't seem to work. If that's the case, you can install the ivtv-utils package and use one of its utilities to pretune the tuner to the correct channel:

     sudo apt-get install ivtv-utils

Add a line something like this to rc.local:

     /etc/rc.local:
     ivtv-tune -c 3 -d /dev/video0 -t us-cable

This should tune the encoder to the correct channel at startup.