Sending RS232 commands to LG Web OS player WP 401, to change HDMI input

Hi All, I am working on my 1st project for sending RS232 command via R4 Uno Wifi.
I have an RS232 shield connected to it. To change HDMI input for LG WebOS player, I found the corresponding command reference list which is, Command 1 and 2, x and b respectively.

image|690x297
How to send the serial command? Is there a sample code I can see or use? thank you

Serial.write('x') or Serial.write('b')

for switching? Is that correct?

I would like to see a schematic of what you have connected and a links to the hardware. RS232 is a hardware standard, not software although many assume it is. Reason for the schematic there is level changes and inversions in the typical circuit.

kudos for getting the hard connections rights! :smiley:

managed to find the manual online. along with that you shared already you would need this info as well :wink:

in terms of coding something like this could work (change the set ID to the value you used if required) :
(Compiles, NOT tested)

/*
Transmission
(Command1)(Command2)( )(Set ID)( )(Data)(Cr)
(x)(b)( )(Set ID)( )(Data)(Cr)
*/

uint16_t SET_ID = 0x00; // Selecting '00H' for Set ID allows the simultaneous control of all connected monitors.

void setup() {

  Serial.begin(115200); //serial monitor (Serial USB)
  Serial1.begin(9600); //D0 D1 connection. LG WebOS player baud rate is 9600

  //select input
  Serial1.write('x');
  Serial1.write('b');
  Serial1.write(' ');
  Serial1.write(SET_ID);
  Serial1.write(0xA0); //Select HDMI1(PC). value assumed to be hexadecimal format
  Serial1.write('\r'); //carriage return
}

void loop() {
  if (Serial1.available()) {     // If anything comes in Serial1 (pins 0 & 1)
    Serial.print(Serial1.read());   // read it and send it out Serial (USB)
  }
}

hope that helps...

thank you . Will update with the success this week!

1 Like

Nice job and thanks for posting the additional information it will help a lot o users.

/*
Transmission
(Command1)(Command2)( )(Set ID)( )(Data)(Cr)
(x)(b)( )(Set ID)( )(Data)(Cr)
*/
int LED_PIN = 13;               //  choose the output pin (for LED)
int PIR_PIN = 2;               // choose the input pin (for PIR sensor)
int PIR_State = LOW;             // we start, assuming no motion detected
int MOTION_Status = 0;           // variable to store the PIR sensor's motion status (high or low)
int delayT = 100;
uint16_t SET_ID = 0x00;

void setup() {
// put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
  pinMode(PIR_PIN, INPUT);     // declare sensor as input
}


void loop() { 
// put your main code here, to run repeatedly:
  MOTION_Status = digitalRead(PIR_PIN); // read the PIR pin's current output (is it HIGH or LOW?)

   // if the motion status is HIGH
   if (MOTION_Status == HIGH) { 
     if (PIR_State == LOW ) {
     
        PIR_State = HIGH; // update the previous state to HIGH
        delay(1000);  // optional delay to slow down the PIR sensor reading intervals
        digitalWrite(LED_PIN, HIGH);
        Serial.write('x');
        Serial.write('b');
        Serial.write(' ');
        Serial.write(SET_ID);
        Serial.write(' ');
        Serial.write(0xA0);
        Serial.write('\r');        
     }
   } 
//or else if motion status is low
    else { 
      if (PIR_State == HIGH) {
    
        PIR_State = LOW; // update the previous state to LOW
        digitalWrite(LED_PIN, LOW);
        Serial.write('x');
        Serial.write('b');
        Serial.write(' ');
        Serial.write(SET_ID);
        Serial.write(' ');
        Serial.write(0xA1);
        Serial.write('\r');
      }
     delay(delayT);
     }
}

I have attached the code above but cant get the RS232 to work.

Basically, I want to switch between HDMI 1 and HDMI 2. thanks

you were not attentive to my sample code. did you try it btw?! did that work?

D0, D1 on the R4 is Serial1 and not Serial!

make the change, try again and let us know! :wink:

ok. haha. Let me try

/*
Transmission
(Command1)(Command2)( )(Set ID)( )(Data)(Cr)
(x)(b)( )(Set ID)( )(Data)(Cr)
*/

uint16_t SET_ID = 0x00; // Selecting '00H' for Set ID allows the simultaneous control of all connected monitors.

void setup() {

  Serial.begin(115200); //serial monitor (Serial USB)
  Serial1.begin(9600); //D0 D1 connection. LG WebOS player baud rate is 9600

  //select input
  Serial1.write('x');
  Serial1.write('b');
  Serial1.write(' ');
  Serial1.write(SET_ID);
  Serial1.write(0xA0); //Select HDMI1(PC). value assumed to be hexadecimal format
  Serial1.write('\r'); //carriage return
}

void loop() {
  if (Serial1.available()) {     // If anything comes in Serial1 (pins 0 & 1)
    Serial.print(Serial1.read());   // read it and send it out Serial (USB)
  }
}

Tried. Did not work? Should I change anything else?

someone else in the forum used this format instead,


void setup() {
  Serial.begin(9600);
}

void loop() {
  if(Serial.read()='1'){
    Serial.write("ka 01 00\r");
  }
}

If you look closely at sherzaad's code, you will see that he has forgotten to send the second space. (the one between SET_ID and the data)

Put the missing space in and try again.

That code does send the following:

I modified that code to use Serial1to send the data instead of Serial.
I also changed the = (assignment operator) to == (comparison operator).

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  if (Serial.read() == '1') {
    Serial1.write("ka 01 00\r");
  }
}

Typing 1 into the Serial monitor causes it to write the following to Serial1:

as pointed out by other forum fellow, I missed out the second 'space' character after SET_ID.

please add that line in (ie Serial1.write(' '); after SET_ID)and try if you may...

It doesnt work. I have added the space after SET_ID