2

I am following the instructions from this page to set up RS485 communication between two Arduinos.

https://arduino-info.wikispaces.com/SoftwareSerialRS485Example

My wiring varies slightly from the demo in that;

DI (data in)is Pin 18 (11 in the example) RO (receive out) is pin 19 (10 in the example) DE (data enable) and RE (receive enable) jumpered together and to pin 5

When I use the script, I can see the built in LED go dark when sending, but I don't get the echo back, nor do I see the LED on the remote blink for the receive.

Is there a fundamental problem with the pins I am using on the MEGA, or am I having difficulty with the script?

Thanks!

2
  • it is not possible to comment on your script for obvious reasons
    – jsotola
    Commented May 24, 2018 at 4:14
  • Have you connected ground correctly? Commented May 24, 2018 at 9:26

1 Answer 1

1

I don't know what is wrong with your setup, but I suggest you start by testing with a simpler program.

Below is a program that simply copies bytes from the USB link (the bytes coming from the Arduino's serial monitor) to the RS-485 bus, or the other way around depending on a #define. Both Arduinos should be connected as follows:

Arduino     transceiver
--------------------------------
GND         GND
5V          VCC
TX1 (18)    DI (driver input)
RX1 (19)    RO (receiver output)

Additionally, connect:

  • on the sending side:
    • the USB plug to your computer
    • the transceiver's DE (driver output enable) and RE (receiver output enable) to the Arduino 5V
  • on the receiving side:
    • the transceiver's DE and RE to the Arduino GND

Make sure both Arduinos are powered and share a common ground. Optionally, you can connect the receiving Arduino to your computer, if you can manage to tell the USB links apart.

Then load the program below to both of them. Make sure you comment-out the line #define SENDER before programming the receiver.

// The "sender" copies bytes from the USB link (Serial) to the RS-485
// bus (Serial1). The receiver copies them the other way around.
// Comment-out this line for the receiver.
#define SENDER

#ifdef SENDER
HardwareSerial &inputStream  = Serial;
HardwareSerial &outputStream = Serial1;
#else
HardwareSerial &inputStream  = Serial1;
HardwareSerial &outputStream = Serial;
#endif

void setup()
{
    inputStream.begin(9600);
    outputStream.begin(9600);
    pinMode(LED_BUILTIN, OUTPUT);  // used to show activity
}

void loop()
{
    // Copy input stream to output stream.
    if (inputStream.available()) {
        digitalWrite(LED_BUILTIN, HIGH);
        outputStream.write(inputStream.read());
        outputStream.flush();
        digitalWrite(LED_BUILTIN, LOW);
    }
}

Now you can test sending strings through the serial monitor and seeing whether both LEDs blink. If you connect both Arduinos to your computer, you could use a terminal emulator (screen, putty, minicom... depending on your OS) to get the characters back from the receiving Arduino.

If all that fails, get a scope and look at all the signals along the path.

1
  • Thanks! I can't tell you how much of a huge help that was! The part I had missed was setting up the transceiver's DE (driver output enable) and RE (receiver output enable) to the Arduino 5V and on the receiving side: the transceiver's DE and RE to the Arduino GND. Works a treat now!
    – Joe Bisson
    Commented May 24, 2018 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.