Making an LG TV Controller from a Linux box.
A Stupid Linux trick...
Summary: I wrote a web page to control the LG 37LC7D TV via it's RS232 Port.
So I got a wild-hair one day to buy a new tv. So I took my wife to Best Buy and we looked at TV's. An awe inspiring selection made me briefly think that I should have researched it first to find the best, but screw it! I was there with money to burn! My wife hunted around and found the "open-box" TV's. These are TV's that have been returned for one reason or another. Usually they are much cheaper than the off-the-shelf models. So woot I found my "open-Box" 37" (about 1m diagonal) TV. It is an LG 37LC7D, with no remote. So we got it home and had dinner while I started pulling coax for Cable.
Poking around I noticed it had both an RGB in dsub15 port and a 9pin RS232 port. Ahhhh!!! In geek heaven I hunted on LG's website for a manual (Local Copy). Reading it, I found the section on the serial commands to send to the tv to control it. I instantly thought this is a job for LINUX!
I only had one spare machine, an old PII-350 that a friend had been throwing out. I snagged it, and I knew no fancy distribution should grace this box. I also knew the while I could probably do mythTV on it, I wanted the computer to control the TV not just the input to the TV. I needed functionality and stripped down power, Slackware called. Machine info. I have a Slackware subscription but the latest release got screwed in shipping(cracked case and crap on the CD's) and the previous release I have loaned out to a friend, so Slack 10.2.0 it was.
Basic install, added minicom (terminal client for testing the serial port), apache, and php. I added the apache user to the serial port group, "uucp", and gave it write perms to the serial port. I grabbed a 9pin serial cable and null-modem adaptor from a local radio shack (where the counter troll asked me if I was sure of what I was doing, HAH!). I had an old wyse-60 terminal that I was able to test things with as well. It was neat seeing the old amber characters come up, <sniff> call me sentimental.
Time for some programming. I went with php b/c I know it well, and I can program in it fast (and badly). I arranged each function to handle a specific task(duh) and only send it's specific function to the serial port.
Each LG command uses a specific format:
[CMD1][CMD2] [DATA] [CRLF]
I could have made a giant class and functions building the eventual string to send to the serial port in one fell swoop. But that's for version 2. ;-) The tv does an echo back with a success code on the serial port, but I ignore the return codes... They can be used for error detection but since I write bug free code that's not a big deal. ;-)
So after some fiddling with the linux box in minicom & shell (turning off flow control to the serial port). There are two slight "issues", one, when you tell the TV to turn on it takes about 15 to 20 seconds. I should have some javascript or something to pause for that time before jumping back to accept user input. So a slight pause is needed. Secondly, the channel selection data string while correct, doesn't always change the channel. I'm not sure about this one, I am pretty sure I've gotten the format of the statement correct, but there seem to be breaks in the data range needed to be sent to the TV. I blame my programming (features not bugs!) for this one. I should probably read the manual again.
All in all it works well for changing the volume, turning on/off the TV, setting the channel. The TV is nice too. I like the selection of inputs. The picture is clear and nice. I've had X (The windowing system for those who don't know) up on it as well as DVD's from a real dvd player and from a PS2 and both look nice. The Transformers movie was awesome on the big screen. I think an HD Tivo is in my future now.
- Future Features:
- Needs channel up down for surfing
- Since the channels are input to the serial port, an up/down channel control would mean keeping the old channel setting. This isn't a big deal but since my wife can also control the channels, her or my state information about which channel is on, could be different.
- Needs Volume up down.
- See the channel changing explanation above, this has the same problem. In practice though, this hasn't been a big deal.
- Channel previews
- I like this idea a lot (which means it should be implemented soon). I've got an Hauppagge TV card, I can stick in the computer. I would like to set it up then to grab a frame of video from each channel once every five mins, and then have that displayed on the page with the channel selection. This way I can preview what's on all channels b4 deciding to jump to one or the other.
- Last viewed channel
- Allow me to jump between two channels. Maybe even setup "channel sets", sets of channels to cycle between.
All in all, it's been a fun project, of course the "source" for what I did is here: lg_tv.tgz I release it under the GNU GPLv2. Here are some Pics of the finished "product":
The Setup (TV on top, Computer on Bottom, Wyse Terminal making appearance)
Back of the TV (with INputs EveryWhere!)
A Null Modem Adapter!!! (OK, not that exciting)
Well I hope you found this informative and even more importantly inspiring to let you do your own TV/Device/Toaster controlling linux box.
The web design on the TV interface was done by Helen at www.elemental.name, all bad php coding was done by me. dzcowart@gmail.com