Rs232 to TTL Convertor junk characters received on Arduino serial

I am having a project where the Arduino needs to receive a string from RS232 port of the Delta DVPSX2 PLC and display it on an oled screen connected to the Arduino.

I have purchased the RS232 <-> ttl convertor (max3232) smd board. For test purpose I am sending a string through the hyperterminal of the PC usb port through the USB <-> RS232 convertor to RS232 <-> TTL convertor and then taking the TTL output on the input pins 10,11 of the Arduino through software serial. I am printing the received string on serial port of the Arduino to check the received string on the serial monitor of the Arduino.
But the received string is having lot of garbled characters like inverted question marks in the string.

I have checked with two different RS232 <-> TTL Max3232 boards but the result is the same with output string consisting of the garbled characters.

E.g. if i send the string “testinputstring” i get the response as “te⸮ti⸮⸮⸮t⸮tri⸮”

Please see the code below

#include<SoftwareSerial.h>


SoftwareSerial debuggingSerial(10,11);//RX,TX




String readlineString="";



void setup()   {                
         Serial.begin(9600);
        debuggingSerial.begin(9600);
      
}


void loop() {


  if (debuggingSerial.available())
  {   
      readlineString= debuggingSerial.readString();
  }

 if(readlineString.length()>0)
      {
       Serial.print(readlineString);
        readlineString="";
      }



}

I assume you have ground as well as the RX/TX lines - is there a frame ground as well? How long is the RS232 cable?

It's generally safer and simpler to copy the characters one at a time:

void loop()
{
  if (debuggingSerial.available())
  {
    Serial.write(debuggingSerial.read());
  }
}

wildbill:
I assume you have ground as well as the RX/TX lines - is there a frame ground as well? How long is the RS232 cable?

I have a ground and RX,TX line taken from the rs232 connector which connects to the input of the RS232<-> TTL convertor. The cable is hardly 150mm long.

johnwasser: It's generally safer and simpler to copy the characters one at a time:

void loop()
{
  if (debuggingSerial.available())
  {
    Serial.write(debuggingSerial.read());
  }
}

Are you referring to following

void loop()
{
String message="";
  while (debuggingSerial.available())
 {
   message+=debuggingSerial.read();
  }
Serial.write(message);
}

Do baud rates of PLC-to-arduino and arduino-to-serial monitor match up?

ecovativetechnologies: Are you referring to following

void loop()
{
String message="";
  while (debuggingSerial.available())
 {
   message+=debuggingSerial.read();
  }
Serial.write(message);
}

Yes. That is an example of the kind of code I do not recommend. The Arduino can repeat loop() fast enough to not require a second level of buffering. If a character is available, read it and write it. Nothing more complex (like adding it to a buffer and writing and clearing the buffer) is needed.

johnwasser:
Yes. That is an example of the kind of code I do not recommend. The Arduino can repeat loop() fast enough to not require a second level of buffering. If a character is available, read it and write it. Nothing more complex (like adding it to a buffer and writing and clearing the buffer) is needed.

I am reading a string on the serial. Should I use the Serial.readString(). Please suggest.

dougp: Do baud rates of PLC-to-arduino and arduino-to-serial monitor match up?

The problem was with the transmit Protocol parameters. The data bits i was using while transmitting was 7-E-1- None. But default for software serial is 8-N-1-None. Thanks!!

ecovativetechnologies: The problem was with the transmit Protocol parameters. The data bits i was using while transmitting was 7-E-1- None. But default for software serial is 8-N-1-None. Thanks!!

Excellent!

Don't ask how I thought of that. ;)