04-12-2024, 06:34 AM
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);
}
}
RS485.zip (Size: 475 bytes / Downloads: 82)