Bidirectional communication from RS-232 to half-duplex RS-485 using arduino nano

What you are trying to do is possible with an Arduino Nano, BUT there some limitations.

I think the connecting and disconnecting is maybe not quite the way to describe it - or I'm not quite getting what you are describing.

Let's assume that you can't use the built-in hardware serial port on the Nano - maybe because you are going to use that for debugging the code etc.

The big assumption will be that the RS-232 device will pause between sending commands to either wait for the response from the other device or time out and send the command again.

If that is the case, then you could have 2 software serial ports. There are limitations such that only 1 software serial port can listen for (i.e. receive) data at once, and that the baud rate is fairly slow - less than 38400 baud.

Your code would likely do something like this:

  1. configure software serial port #1 to listen for the 1 character command
  2. on reception of that command you would tell software serial port #2 to listen
  3. configure the RS485 module for transmit mode
  4. send the command out on software serial port #2
  5. once transmission completes, switch the RS485 module back to receive mode
  6. wait a period of time for the RS485 device to respond on software serial port #2
  7. send the response back on serial port #1
  8. back to step 1

A lot depends on the baud rates involved. At higher baud rates (i.e. greater than 38400), you would be better with an Arduino MEGA2560 based board with 4 hardware serial ports.