Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SoftwareSerial support for RS485 transport #1510

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions MySensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions examples/GatewaySerialRS485/GatewaySerialRS485.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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.h>
// SoftwareSerial RS485SoftwareSerial(D1, D2); // RX, TX
// #define MY_RS485_SOFTWARESERIAL RS485SoftwareSerial

// Enable serial gateway
#define MY_GATEWAY_SERIAL

Expand Down
2 changes: 2 additions & 0 deletions hal/transport/RS485/MyTransportRS485.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down