I recently got a really good deal on a LC-70LE732U Sharp TV. I saw on the box it had all the "Smart TV" apps but was delighted to find out it had a Serial port for control. I was even more happy when i realized it can be controlled via ethernet.... but this bubble burst when i realized a username/password was needed each time and only one client can Winsock at any one time for control.
So i moved back over to the serial connection.
I have been looking at doing Ethernet control for a little while because i will be building a little Ethernet controlled submarine soon so i figured this would be a good project to get my feet wet on UDP.
What i did was put an Ethernet Shield on a Mega. Build a little shield for the other side of the board that contains a max232 and it's supporting components as well as a DB9 female.
As my first functional project with processing i took the easy way out and used the G4P GUI builder for buttons and made a PC interface. The PC interface creates a UDP string and sends it to the ethernet shield on the Mega. The Mega will use that to create a serial string and output that to the TV through the MAX232.
I have a few more things i want to do as well.
-
Create a green flash driven by the OK reply from the TV when a good command is recieved and a red flash that would be the result of an ERR reply when command did not get processed.
-
Create an APK from the little app so i can use my phone to control my TV as long as i am connected to the LAN.
-
Make the app a few pages so i can have one page of each set of buttons on the actual remote. (ex. number pad, DLNA controls, Menu/Options, etc.)
As of now things are working great from the PC. Now my challenge is to get this app ported over to Android.
Code isn't very hard. I did keep some of the stuff from the UDPSendRecieve example and modded it for my purpose.
Added .zip file for processing so it has all the dependent files for the basic controller.
Arduino Code:
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0x90, 0xA2, 0xDA, 0x00, 0xA5, 0xC4 };
IPAddress ip(192, 168, 5, 200);
unsigned int localPort = 8888; // local port to listen on
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged"; // a string to send back
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
// start the Ethernet and UDP:
Ethernet.begin(mac,ip);
Udp.begin(localPort);
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if(packetSize)
{
Serial.print("Received packet of size "); //Print Packet Information to USB/Serial Port
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i =0; i < 4; i++)
{
Serial.print(remote[i], DEC);
if (i < 3)
{
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer); //Print contents of packet to USB/Serial for Debug
Serial1.println(packetBuffer); //Print contents of packet to Serial1 (connected to MAX232 -> TV Serial Port)
// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
delay(10);
}
TV_Control_Processing.zip (544 KB)