Read/write to two RS-232 devices using RX1/TX1 & RX2/TX2

Hi,

I am looking at connecting two RS-232 devices using RX1/TX1 & RX2/TX2 with a Mega2560. I also want to read/write to the stock USB connection (for DAQ and parameter control).

I was thinking of trying some stock RS-232 - TTL modules as shown below (one uses the MAX3232 and thee other uses the MAX202).

I also thought at it may be neater (from a wiring and packaging POV) to use 2 stacked RS-232 shields (which use the MAX3232). These look like these use dedicated connection to RX0/RT0, so I was going to cut tracks and either jumper each one to RX1/TX1 & RX2/TX2, or use the Softwareserial commands to other reassign digital pins for each port, as shown below.

image

Any thoughts/advice?

Many thanks.

That makes sense, depending a bit on your electronic skill level, creating a shield yourself may also be a good option.

I don't think that will work better in the end, and don't use swSerial if you have hwSerial available. swSerial works, but with a lot restrictions, you can only listen to 1 port at a time, and it is a lot more cpu intensive.

you first image shows the RS232 shields connected to the Mega Serial1 and Serial2 ports so why use SoftWareSerial in particular as it cannot handle two ports concurrently
if you cross pins 2 and 3 of the two RS232 9 pin Dtype connectors you should be able to transmit from Serial1 to Serial2 and vice versa as a simple initial hardware/software test

I find MEGA Grove shields and connectors useful.

... and I've found MEGA prototype boards with screw terminals very helpful as well.

simple test with a Mega and two RS232 shields using hardware serial ports Serial1 and Serial2

test program

// Arduino Mega serial1 and serial2 test

// mega Serial1 pin 18 is Tx  pin 19 is Rx
// mega Serial2 pin 16 is Tx  pin 17 is Rx

// test connect pin 18 Tx and pin 17 Rx and pin 16 Tx to pin 19 Rx
// test RS232 shields  9 pin D type connectors cross connect pins 2 and 3 to each other

// characters from Serial are transmitted to Serial1 and Serial2
// if cross connected characters sent to Serial1 should appear on Serial 2 and vice versa


void setup() {
  Serial.begin(115200);   // initialise serial monitor port
  Serial1.begin(115200);  // initialise Serial1
  Serial2.begin(115200);  // initialise Serial1
  Serial.println("Arduino Mega Serial1 to Serial2 test");
  Serial.println(" test connect pin 18 Tx and pin 17 Rx and pin 16 Tx to pin 19 Rx");
  Serial.println(" test RS232 shields  9 pin D type connectors cross connect pins 2 and 3 to each other");
  Serial.println(" characters from Serial are transmitted to Serial1 and Serial2");
  Serial.println(" if cross connected characters sent to Serial1 should appear on Serial 2 and vice versa");
}

void loop() {
  if (Serial1.available()) {  // read from Serial1 output to Serial
    char ch = Serial1.read();
    Serial.print("1>");
    Serial.println(ch);
  }
  if (Serial2.available()) {  // read from Serial1 output to Serial
    char ch = Serial2.read();
    Serial.print("2>");
    Serial.println(ch);
  }

  if (Serial.available()) {  // read from Serial outut to Serial1
    char ch = Serial.read();
    if (ch < ' ') return;
    Serial1.write(ch);
    Serial2.write(ch);
  }
}

serial monitor output when testing two cross connected RS232 shield

 test connect pin 18 Tx and pin 17 Rx and pin 16 Tx to pin 19 Rx
 test RS232 shields  9 pin D type connectors cross connect pins 2 and 3 to each other
 characters from Serial are transmitted to Serial1 and Serial2
 if cross connected characters sent to Serial1 should appear on Serial 2 and vice versa
1>6
2>6
2>5
1>5
1>4
2>4
1>3
2>3

Hi Horace,

Many thanks for that, this was my intended first test when I get the RS-232 - TTL modules today.

I did subsequently wonder what the MTBF of those Ebay/Alibaba modules are, and found an interesting blog post (Google "Investigating Fake MAX3232 TTL-to-RS-232 Chips", will bring it up as the first hit) which actually shows that exact module and some of the issues found with lifetime and overheating issues.

Once I have checked that it works with the cheap modules (same as your image, with the D-type on board) that I ordered, if it looks like they may cloned MAX3232's I will probably source some with genuine MAXIM chips from Sparkfun, as they have a module that will fit inside a D-type shell)

the cheap components are fine for prototypes but when builting industrial products I always use components from Radio Spares or Farnell in the UK

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.