11-15-2021, 04:06 PM
(11-15-2021, 10:57 AM)admin Wrote: if you want to test RS232, you just use a USB-RS232 cable connect board with PC, you can send and receive command.
THank you ,I think as the same as I done by the program to test rs232 port is working or not :
#define RXD2 16
#define TXD2 17
void setup() {
// Note the format for setting a serial port is as follows: Serial2.begin(baud-rate, protocol, RX pin, TX pin);
Serial.begin(115200);
//Serial1.begin(9600, SERIAL_8N1, RXD2, TXD2);
Serial2.begin(300, SERIAL_8N1, RXD2, TXD2);
Serial.println("Serial Txd is on pin: "+String(TX));
Serial.println("Serial Rxd is on pin: "+String(RX));
}
/*void loop() {
//Choose Serial1 or Serial2 as required
if (Serial.available())
Serial2.write(Serial.read());
while (Serial2.available())
Serial.write(Serial2.read());
delay(500);
}
*/
void loop()
{
Serial2.print("hello");
Serial2.write("hellowrite");
Serial.println(String(Serial2.readString())); //ทดสอบ port rs232 โดยการส่งค่าwrite(hellowwrite) แล้วอ่านค่ากลับ read
//ผ่านทาง serial2 (Tx ขา 2 ,Rx ขา 3 ต่อกัน และ Tx ต่อ LED ,R 1K แสดงติดๆดับๆ
Serial.println("Tested");
delay(2000);
}