diff --git a/MyConfig.h b/MyConfig.h index c519f2745..074b9d3c9 100755 --- a/MyConfig.h +++ b/MyConfig.h @@ -2440,6 +2440,7 @@ #define MY_RS485_DE_PIN #define MY_RS485_DE_INVERSE #define MY_RS485_HWSERIAL +#define MY_RS485_SOFTWARESERIAL // PJON #define MY_PJON #define MY_DEBUG_VERBOSE_PJON diff --git a/MySensors.h b/MySensors.h index f7d109a72..b4a4ac97e 100644 --- a/MySensors.h +++ b/MySensors.h @@ -373,8 +373,10 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs #if defined(__linux__) #error You must specify MY_RS485_HWSERIAL for RS485 transport #endif +#if !defined(MY_RS485_SOFTWARESERIAL) #include "drivers/AltSoftSerial/AltSoftSerial.cpp" #endif +#endif #include "hal/transport/RS485/MyTransportRS485.cpp" #elif defined(MY_RADIO_RFM69) #if defined(MY_RFM69_NEW_DRIVER) diff --git a/examples/GatewaySerialRS485/GatewaySerialRS485.ino b/examples/GatewaySerialRS485/GatewaySerialRS485.ino index 2dc5396a1..b3d6e32a6 100644 --- a/examples/GatewaySerialRS485/GatewaySerialRS485.ino +++ b/examples/GatewaySerialRS485/GatewaySerialRS485.ino @@ -34,6 +34,8 @@ * * If your Arduino board has additional serial ports * you can use to connect the RS485 module. +* Alternatively, use the Arduino SoftwareSerial library to use any of the supported +* GPIO pins for communicating with the RS485 module. * Otherwise, the gateway uses AltSoftSerial to handle two serial * links on one Arduino. Use the following pins for RS485 link * @@ -65,6 +67,11 @@ // Enable this if RS485 is connected to a hardware serial port //#define MY_RS485_HWSERIAL Serial1 +// Enable if using SoftwareSerial to communicate with RS485 transceivers. +// #include +// SoftwareSerial RS485SoftwareSerial(D1, D2); // RX, TX +// #define MY_RS485_SOFTWARESERIAL RS485SoftwareSerial + // Enable serial gateway #define MY_GATEWAY_SERIAL diff --git a/hal/transport/RS485/MyTransportRS485.cpp b/hal/transport/RS485/MyTransportRS485.cpp index fdf963125..748776d44 100644 --- a/hal/transport/RS485/MyTransportRS485.cpp +++ b/hal/transport/RS485/MyTransportRS485.cpp @@ -88,6 +88,8 @@ unsigned char _recCalcCS; #if defined(__linux__) SerialPort _dev = SerialPort(MY_RS485_HWSERIAL); +#elif defined(MY_RS485_SOFTWARESERIAL) +SoftwareSerial& _dev = MY_RS485_SOFTWARESERIAL; #elif defined(MY_RS485_HWSERIAL) HardwareSerial& _dev = MY_RS485_HWSERIAL; #else diff --git a/keywords.txt b/keywords.txt index 70f5885e2..8cdabfa0a 100755 --- a/keywords.txt +++ b/keywords.txt @@ -236,6 +236,7 @@ MY_RS485_BAUD_RATE LITERAL1 MY_RS485_DE_PIN LITERAL1 MY_RS485_DE_INVERSE LITERAL1 MY_RS485_HWSERIAL LITERAL1 +MY_RS485_SOFTWARESERIAL LITERAL1 MY_RS485_MAX_MESSAGE_LENGTH LITERAL1 MY_RS485_SOH_COUNT LITERAL1