From 40e785839be5f45abbe3da6207b2887f9418cc75 Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Sat, 13 Apr 2024 16:14:48 +0200 Subject: [PATCH] implemented new code "SerialTransceiver" Signed-off-by: Stephan Richter --- .../SerialTransceiver/SerialTransceiver.ino | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Software/SerialTransceiver/SerialTransceiver.ino diff --git a/Software/SerialTransceiver/SerialTransceiver.ino b/Software/SerialTransceiver/SerialTransceiver.ino new file mode 100644 index 0000000..9d08222 --- /dev/null +++ b/Software/SerialTransceiver/SerialTransceiver.ino @@ -0,0 +1,39 @@ +/* + * Demonstrates how to use LCDisplay in conjunction with SoftRS485: + * + * The main _loop_ of this program listens on the RS485 bus. + * Whenever a message is received from the bus, it is displayed on the LCD. + */ + +// include the library code: +#include + +#define PROGRAM "RS485-Nano Rev 2.0 / Transceiver 1.0" + +#define Max485_RO 3 // read-output of Max485 +#define Max485_RE 5 // not-read-enable of Max485 +#define Max485_DE 9 // data enable of Max485 +#define Max485_DI 8 // data input of Max485 + +String message = ""; + +void setup() { + Serial.begin(115200); + init485(Max485_RO,Max485_RE,Max485_DE,Max485_DI); // library initialization: +} + +void loop() { + if (available485()) { + Serial.println(get485message()); + } + if (Serial.available()) { + // get the new byte: + char c = (char)Serial.read(); + if (c == '\n') { + send485(message.c_str()); + message = ""; + } else { + message += c; + } + } +}