title: PC to Arduino RS-485 connection via converters
body: <p>I'm trying to make modbus RS-485 connection between PC (Windows) and Arduino.</p>
  
  <p>On the PC side I use USB-to-RS485 converter like this one <a href="http://ru.aliexpress.com/item/USB-to-485-RS485-converter-Adapter-Support-Windows-7-8-for-Arduino/1577970568.html" rel="nofollow">http://ru.aliexpress.com/item/USB-to-485-RS485-converter-Adapter-Support-Windows-7-8-for-Arduino/1577970568.html</a></p>
  
  <p>On the Arduino side I use TTL-to-RS-485 like this one <a href="http://ru.aliexpress.com/item/5pcs-lot-MAX485-Module-RS-485-TTL-to-RS485-Module-for-Arduino/32262338107.html" rel="nofollow">http://ru.aliexpress.com/item/5pcs-lot-MAX485-Module-RS-485-TTL-to-RS485-Module-for-Arduino/32262338107.html</a></p>
  
  <p><strong>Problem1:</strong>
  When I send byte from PC to Arduino. Nothing happens. Arduino does not receive anything. In this case i upload to Arduino this code:</p>
  
  <pre><code>#include &lt;SoftwareSerial.h&gt;
  #include "RS485_protocol.h"
  
  SoftwareSerial rs485 (10, 11);  // receive pin, transmit pin
  const byte ENABLE_PIN = 3;
  
  void setup()
  {
    Serial.begin(9600);
    rs485.begin (28800);
    pinMode (ENABLE_PIN, OUTPUT);  // driver output enable
  }
  
  void loop()
  { 
    byte buf [1];
    byte received = recvMsg (fAvailable, fRead, buf, sizeof (buf));
  
    if (received)
      {
        Serial.println(buf[0]);
      } else {
        Serial.println("--");
      }      
  }  // end of loop
  
  int fAvailable ()
    {
    return rs485.available ();  
    }
  
  int fRead ()
    {
    return rs485.read ();  
    }
  </code></pre>
  
  <p>And open Serial Monitor in Arduino IDE to show received data. 
  Then I open new instance of Arduino IDE, chose proper USB-to-RS485 COM port and opens it Serial Monitor to send some data.</p>
  
  <p>So in Arduino side Serial Monitor I see only "--" lines. Even when I'm trying to send something in PC side Serial Monitor.</p>
  
  <p><strong>The other problem is:</strong></p>
  
  <p>Vice versa. When i sending some byte from Arduino to PC I receive some odd symbols instead sent byte.</p>
  
  <p>The Arduino code in this case is:</p>
  
  <pre><code>#include &lt;SoftwareSerial.h&gt;
  #include "RS485_protocol.h"
  
  SoftwareSerial rs485 (10, 11);  // receive pin, transmit pin
  const byte ENABLE_PIN = 3;
  
  void setup()
  {
    rs485.begin (28800);
    pinMode (ENABLE_PIN, OUTPUT);  // driver output enable
  
  }
  
  void loop()
  { 
    byte msg[1] = {3};
    sendMsg(msg);
  }  // end of loop
  
  void sendMsg(byte msg[])
  {
    delay (1);  // give the master a moment to prepare to receive
    digitalWrite (ENABLE_PIN, HIGH);  // enable sending
    sendMsg (fWrite, msg, 1);
    digitalWrite (ENABLE_PIN, LOW);  // disable sending
  }
  
  void fWrite (const byte what)
    {
    rs485.write (what);  
    }
  
  int fAvailable ()
    {
    return rs485.available ();  
    }
  </code></pre>
  
  <p>On the PC side (in the Arduino IDEs Serial Monitor) I receive odd symbols instead "3" symbol.</p>
  
  <p>=======</p>
  
  <p>RS485 converters wired with twisted pare A to A and B to B.
  RS485 to TTL converter connected to Arduino properly. (Communication between two arduinos works fine).</p>
  
  <p>Please help.</p>