rs485 and serial

Hi friends
Help me please with realization scheme linux --rs485_bus--> 2xArduino slave
i want use rs485 without modbus protocol and i create scatch for work this rs485

my connection scheme in the attachement

i use Linux system(mint distributive) and i send from linux command echo "1" > /dev/ttyUSB0 then the light turns on Arduino#1(ledPin 2) and if i send "2" then the light turns on Arduino#2(ledPin 2) and it work!

but does not work feedback. When Arduin 1 includes a lamp she say to the serial port "on_1", but when Arduino 2 includes a lamp, it is silent :frowning:

at the stage of physical connection Arduino 2 begins to shine in TX if the control pin is connected to the DE / RE, and this takes nothing (as if the line is busy)

please, guys, show where my mistake

What about switching to transmit before transmitting, that might help.

Even better, lose the blocking while loop and organize your loop so you can do other stuff too:

unsigned long LED_starttime = 0 ;

void loop(void)
{
  // cancel LED if due
  if (digitalRead (ledPin) && millis () - LED_starttime > 2000)
    digitalWrite (ledPin, LOW) ;

  if (Serial.available () > 0)
  {
    int val = Serial.read() - '0';
    if (val == 1)
    //if (val == 2) #for arduino number 2
    {
      digitalWrite(ledPin, HIGH);
      LED_starttime = millis () ;
      digitalWrite (SerialTxControl, RS485Transmit) ;
      delayMicroseconds (50) ; // a little settling time
      Serial.println("On_1");
      //Serial.println("On_2"); #for arduino number 2
      Serial.flush () ;
      digitalWrite (SerialTxControl, RS485Receive) ;
    }
  }
}

thank you, today i check it, may be it may help me
I'll give you the answer

hi guys, i check your source and it problem is not solved :frowning:
if i turn off DE then i can send 1 or 2 via rs485 serial but i not received "On_1" or "On_2"
if DE and RE are connected to the Arduino then RX always lit and ardiono#2 can't receive command

in the attachment my photo with status

Do these transceivers have standard termination networks? You have to bias the signals at idle to read
the correct sense on the RX pin.

Is there interaction with the USB serial - which Arduinos are these? Nanos?

please tell me how to properly make bias?
i use arduino nano on the my network and use standart rs485/ttl converter

Dude,
It's a STANDARD.( CANBUS , DeviceNet, MODBUS etc)
All differential bus networks use one 120 ohm termination resistor across A & B and another 120 ohm resistor across A & B at the other end of the main trunk of thr bus. The "drops" that branch left and right of the main trunk don't have termination resistors. With one at each end and both in parallel, the resistance across A & B is 60 ohms.

raschemmel, you're saying that the resistors are needed at both ends of the converters on the Arduino? or on the master side?
in the attachment my scheme

wherein Rt is 120ohm resistor and Rt too 120ohm resistor, right?

termination bus.jpg

You don't need a schematic !

There is only ONE A line and ONE B line. That IS the bus.
Every tranceuver on the bus is connected to those two lines because EVERY tranceiver has an A pin and a B pin. ALL the A pins and ALL the B pins connect go the A line and B line . The main trunk can be up to 300 meters long. REGARDLEES of how long it is , there is ONE 120 ohm resistor at on the bus at one end and another one on the bus at the other end .
Why would you need a schematic to understand that ?
Could it possibly be any SIMPLER than that ?

LOOK AT THE DATASHEET for the TRANCEIVERS (they are NOT called "converters"

This is sales/marketing: (came from vendor)
rs485 to TTL converter

. They are called TRANCEIVERS)
This is technical data: (came from manufacturer)
MAX485

LOOK AT THE PINOUT .Do you see the pin labeled "A" and the one labeled " B" ? Those two pins ( of ALL the devices on the bus) are the differential drive pins
That IS "the bus" !
It doesn't matter where the master is or if there is an arduino. The "bus" is the A-B wire pair running from one end to the other with one resistor at each end

Obviously the resistor can't be on the arduino side because the arduino is TTL . The resustors go on the A/B lines.(at each end)

1 Like

Thank you, it seems now I understand. I corrected my scheme, and now I think it should be correct

scheme_2.jpg

I'm talking about the RS485 bias network:

Without the bias the state of the RX pin from the transceiver is undefined. The fact you have a
termination resistor is a given, the bias network is not always needed (for instance in a simplex
link)

thank you! my problem is solved, now i will make parser /dev/ttyUSB0 for change status on the web interface

BEFORE

but does not work feedback. When Arduin 1 includes a lamp she say to the serial port "on_1", but when Arduino 2 includes a lamp, it is silent :frowning:

at the stage of physical connection Arduino 2 begins to shine in TX if the control pin is connected to the DE / RE, and this takes nothing (as if the line is busy)

please, guys, show where my mistake

AFTER

my problem is solved,

So WHAT was the problem ? (software (transmit enable), OR hardware (termination resistors)

the problem was with the terminator

Hy friends,
I even read this post very interested because I have a similar case. My question now is, is it right, that I need R120 resistors at the "beginning" and at "the end" of my RS485 although I use the ready TTL to RS485 adapter like megahertzmetal does? I thought, that the needed resistors are alreadyd onboard?! That makes me confused.

Thank your for your support!

If you read this thread you will see the OP's sysytem did jot work UNTIL he installed the terminatirs as I described.