Oct

2

LG TV Serial Control

7 years ago, at the start of October | 1 Comment

Finally, upgraded the TV after living with a 28″ Sony CRT for 14 years. If I’m honest I didn’t really spend much time thinking about which TV to pick, I went for the LG32LD350. So far the TV has worked perfectly and has the added bonus of a serial port. LG don’t hide what this port is for, in fact the protocol and port settings are in the user manual. This is a real breath of fresh air. Look at Sony with their Control-S / Control-L protocols that they didn’t really want you to use. So that’s put LG in my good books and I hope they continue to supply this information. I was also intrigued to get copies of both the GPL and LGPL licences with the documentation. Another project to take a look at.. but later.

Straight away I decided to get working on some serial port control interface. As I said the documentation is there but control needed to be very simple. Luckily I’d already got a SheevaPlug for my birthday in February, so I was just a case of connecting this to the TV with a USB to RS232 device and a Null modem adapter or and serial cable. The USB Serial port uses the PL2303 so is detected without issue. The serial port settings are nothing special, standard console settings

Baud rate : 9600 bps 
Data length : 8 bits 
Parity : None 
Stop bit : 1 bit 

I installed apache2 and php on the SheevaPlug and set about building a test class to control it. It works, although it needs some tidying up. If you want to try it out you can download it. It makes use of the PHP serial class, which I’ve included in the tarball.

LGTV.php       - Main class
control.php    - Example script    
channels.csv   - Channel list
data.csv       - Command list

Configuration and setup is simple. After including the class we create an instance

include('LGTV.php');
 
$tv = new LGTV;

There are a couple of variables that we can set, first of all we set the setId. This should match the id of your TV set, configured from its “Options” menu. If you use a value of 0x00 then all TV sets connected would respond to all the commands issued. I guess this could be useful if you had a big wall of screens or were using them as in store displays or something.

$tv->setId=sprintf("%02x",1);

The default serial port is set as /dev/ttyUSB0 but you can change this using the tty variable.

$tv->tty = '/dev/ttyS0';

Next we need actually try and connect to the TV. If all is well the result of the serialInit command will be true.

$stat = $tv->serialInit();

You can now send commands and query the TV set. By default the variable confirm is true. This means that after you send a command and that command is executed, the class will also query the TV for its current state of that command. In other words if your TV has a current volume of 10 and you request a volume of 9 the command will execute and then will return the current volume. In this example it should be 9. This allows you to verify that a command has taken place, although it does mean that two commands are sent to the TV, not just one. You can disable this by using

$tv->confirm=false;

You should remember to end your script by closing the serial port

$tv->serialExit();

Take a look at control.php to see some basic example code. Please note that this is a preliminary release which I’ll keep updating.



[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

October 2, 2010 22:12


Comments

Name (required)

Email (required)

Website

Speak your mind

1 Comment so far

  1. Rightup on November 21, 2010 18:55

    Nice Code!

Current Electricity Use (15min)


iPhone/Webkit RSS Reader

Links


Tags

1-Wire android api Apple arduino currentcost DDAR development DVD FIC freerunner G1 google Google Phone gphone gprs GPS hardware image image builds inspiration iphone jailbreak kiosk linux Mac monitoring Music neo 1973 Nokia openmoko opensource OSX Pachube personal qtopia rhubarb rikki Rio slimp3 slimserver software tracking Trolltech u-boot


Twitpic


Graphy Stuff






Nasty Spam Monkeys