RS-485 with long cable, external supply prblem

Hi everybody,
I have a problem with my rs-485 comunication (module) from Arduino Mega with ethetner shield to Arduino nano v3.
If I use usb cable to supply the arduino everything is ok even with a 20m cable in pins A and B, if I supply arduino with 5v to 5v pin the arduino slave continuos recived crazy char (ýý¿ÿ2o16#35#29 µÿÿÿÿ÷�þ) but with corret code inside (2o16#35#29) if I use a 20cm cable to pins A and B the data is ok.

A part of master:

#include <SoftwareSerial.h>
#define SSerialRX        11  
#define SSerialTX        12
#define SSerialTxControl 3  
#define RS485Transmit    HIGH
#define RS485Receive     LOW
SoftwareSerial RS485Serial(SSerialRX, SSerialTX);

.
.
.
.
void invia_dati_stanze_temp (int stanza,float temp){

  digitalWrite(SSerialTxControl, RS485Transmit);  // Enable RS485 Transmit   
  String richiesta=String(stanza)+"t"+ String(temp);
  //Serial.println(richiesta);
  invia_stringa(richiesta);

A part of slave:

#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

SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX


if (RS485Serial.available()){
  
while(RS485Serial.available()){
           byteRecived = RS485Serial.read();
           delay(10);
         }// finito lettura dati
}

Can someone help me?

davidino81:
Hi everybody,
I have a problem with my rs-485 comunication (module) from Arduino Mega with ethetner shield to Arduino nano v3.
If I use usb cable to supply the arduino everything is ok even with a 20m cable in pins A and B, if I supply arduino with 5v to 5v pin the arduino slave continuos recived crazy char (ýý¿ÿ2o16#35#29 µÿÿÿÿ÷�þ) but with corret code inside (2o16#35#29) if I use a 20cm cable to pins A and B the data is ok.

Can someone help me?

You are probably seeing a signal reflection when using your long cable.
At each 'end' of your RS485 network, add a 120ohm resistor between A and B. this resistance will 'terminate' the network and absorb the signal instead of reflecting it back at the transmitter.

Chuck.

In this module there is a 130 ohm resistor

davidino81:
In this module there is a 130 ohm resistor

I see you are using a software UART, does the library enable the pullup resistor on the RX terminal?
I have always used the hardware UART, and added a 4.7k pullup.

When you shift from RX to TX mode a standard MAX485 lets the RX pin float. This can cause weird character to appear in the transmitters RX buffer. These character appear due to cross talk from the RS485 buss. It is acting as a radio transmitter, and the RX wire is the receiver.

check for a pullup on the RX line, or Add a 4.7k between VCC and RX.

Chuck.

chucktodd:
I see you are using a software UART, does the library enable the pullup resistor on the RX terminal?
I have always used the hardware UART, and added a 4.7k pullup.

When you shift from RX to TX mode a standard MAX485 lets the RX pin float. This can cause weird character to appear in the transmitters RX buffer. These character appear due to cross talk from the RS485 buss. It is acting as a radio transmitter, and the RX wire is the receiver.

check for a pullup on the RX line, or Add a 4.7k between VCC and RX.

Chuck.

I tried with the 4.7k between vcc and RX but nothing, if add a 4.7k between gnd and A or B the signal get better.
I'm very happy but do you know why?

davidino81:
I tried with the 4.7k between vcc and RX but nothing, if add a 4.7k between gnd and A or B the signal get better.
I'm very happy but do you know why?

the only thing I can thing of is a poor connection on the network.

Can you layout the cabling such that you can measure the voltage between the GND connections at each Arduino? Maybe you have a cable fault.

Chuck.