Re: How to use SoftwareSerial Library?
Hi.
Anyone managed to run SoftwareSerial on RS485 gateway?
I tried to do everything according to what is said in the link above, but with no success.
This works (using hardware serial1 of my Mega):
#define MY_RS485
#define MY_RS485_DE_PIN 3
#define MY_RS485_BAUD_RATE 9600
#define MY_RS485_HWSERIAL Serial1
#define MY_GATEWAY_SERIAL
#include <MySensors.h>
void setup(){}
void presentation(){}
void loop(){}
and this one doesn't work (trying to use SoftwareSerial pins 4 and 2)
#define MY_RS485
#define MY_RS485_DE_PIN 3
#define MY_RS485_BAUD_RATE 9600
#include <SoftwareSerial.h>
SoftwareSerial mySerial(4,2); //rx, tx
#define MY_RS485_HWSERIAL
#define MY_RS485_SWSERIAL mySerial
#define MY_GATEWAY_SERIAL
#include <MySensors.h>
void setup(){}
void presentation(){}
void loop(){}
I also made a change in MyTransportRS485.cpp
before:
#if defined(__linux__)
SerialPort _dev = SerialPort(MY_RS485_HWSERIAL);
#elif defined(MY_RS485_HWSERIAL)
HardwareSerial& _dev = MY_RS485_HWSERIAL;
#else
AltSoftSerial _dev;
#endif
and after:
#if defined(MY_RS485_SWSERIAL)
SoftwareSerial& _dev = MY_RS485_SWSERIAL;
#elif defined(__linux__)
SerialPort _dev = SerialPort(MY_RS485_HWSERIAL);
#elif defined(MY_RS485_HWSERIAL)
HardwareSerial& _dev = MY_RS485_HWSERIAL;
#else
AltSoftSerial _dev;
#endif
What am I doing wrong?
I'm using MySensors 2.3.1 library.