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
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.
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)
}
}
/*
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.
/*
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?