Smart Home Automation Forum
[Arduino code for KC868-A32 Pro]-03 read / write by RS485 - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20)
+--- Forum: KC868-A32/A32 Pro (https://www.kincony.com/forum/forumdisplay.php?fid=27)
+--- Thread: [Arduino code for KC868-A32 Pro]-03 read / write by RS485 (/showthread.php?tid=5523)



[Arduino code for KC868-A32 Pro]-03 read / write by RS485 - admin - 04-12-2024

Code:
#include <arduino.h>
#include "HardwareSerial.h"
String comdata1,comdata2;
HardwareSerial my485Serial(1);
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  my485Serial.begin(9600,SERIAL_8N1,8,9);///rx:32  tx:33
  Serial.println("UsbSerial say hello");
  my485Serial.println("R485 say hello");
}

void loop() {
  // put your main code here, to run repeatedly:
 
    while (my485Serial.available() > 0) {
      delay(100);
      comdata1 = my485Serial.readString();
      my485Serial.print("R485.readString:");
      my485Serial.println(comdata1);
    }
    while (Serial.available() > 0) {
        delay(100);
      comdata1 = Serial.readString();
      Serial.print("UsbSerial.readString:");
      Serial.println(comdata1);
    }
}
source code download:

.zip   RS485.zip (Size: 475 bytes / Downloads: 74)