Hi.
I´m trying to replace our old (broken) doorbell with a few Arduinos.
Because of the long distance and needed communication in both ways for the electrical door opener, I thought of using RS485 for this.
So I´ve got a few Arduino Nanos laying around and got some MAX485 breakout boards and put them together on a breadboard.
Both Arduinos have currently the same code. They listen for Serial Input and send it with SoftwareSerial to the MAX485 module. Then listen for the input from the MAX485 and printing it back on the Serial connection.
But the communication seems only to be working in one direction.
I can send the serial input from one device to the other and it´s printed out on the serial port.
But in the other direction nothing is received.
I first thought either the sending part on one RS485 module or the receiving part on the other one is broken, so I replaced both. But it´s still the same.
Maybe someone can tell me whats wrong here.
Here´s how I connected everything. (Of course not the MAX485 directly but a breakout board with the pullup resistors.)
And here the code that´s on both Arduinos. (Only difference is that it prints out Slave on the Serial port instead of Master at Setup)
#include <SoftwareSerial.h>
#define SSerialRX 10 //Serial Receive pin
#define SSerialTX 11 //Serial Transmit pin
#define SSerialTxControl 3 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
int byteReceived;
int byteSend;
void setup()
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(9600);
Serial.println("Master");
pinMode(Pin13LED, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
// Start the software serial port, to another device
RS485Serial.begin(4800); // set the data rate
}
void loop()
{
digitalWrite(Pin13LED, HIGH); // Show activity
if (Serial.available())
{
byteReceived = Serial.read();
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
RS485Serial.write(byteReceived); // Send byte to Remote Arduino
digitalWrite(Pin13LED, LOW); // Show activity
digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit
}
if (RS485Serial.available()) //Look for data from other Arduino
{
digitalWrite(Pin13LED, HIGH); // Show activity
byteReceived = RS485Serial.read(); // Read received byte
Serial.write(byteReceived); // Show on Serial Monitor
digitalWrite(Pin13LED, LOW); // Show activity
}
}
