Serial Communication with PLC

Hi Guys.

I’m battling to get my Arduino Nano to receive data from my Siemens S7-1200 PLC.

I’m trying to receive information (a string) from the PLC into the Arduino and use it as I want.

The PLC sends the information using the PTP command in the TIA library and outputs it on the expansion card RS232, which I have matched Baud rates, Parity bits, stop bits, etc with the Arduino.

I’m using AltSoftSerial.h library and now this is where it gets strange.

If I use a RS 232 converter from my PC to the Arduino (with converter) it Works!

If I use the PLC to the RS 232 Converter on my PC I receive the correct Information.

When the PLC is connected to the Arduino I get nothing not even garbage out on the serial monitor.

And before someone asks I’m not dasy chaining I’m removing the RS232 cables each time to where they need to be.

// Set serial for debug console (to the Serial Monitor, speed 115200)
#define SerialMon Serial

#include <AltSoftSerial.h>
AltSoftSerial SerialAT;


// or Software Serial on Uno, Nano
// #include <SoftwareSerial.h>
//SoftwareSerial SerialAT(2, 3); // RX, TX
String a;

void setup() {
 // Set console baud rate
 SerialMon.begin(115200);
 delay(3000);
}
void loop() {
 SerialMon.println("starting");
 SerialAT.begin(115200);
 //SerialAT.write("serial message");

   if (SerialAT.isListening()) {
  Serial.println("Port One is listening!");
   }
  
   while(true) {
   if (SerialAT.available()) {
     SerialMon.println("got something");
     a= SerialAT.readString();// read the incoming data as string
     SerialMon.println("read done");
     SerialMon.println(a);
   }
   if (SerialMon.available()) {
     SerialAT.write(SerialMon.read());
   }
   delay(0);
 }
}

I thought initially that it was because the grounds were not common so I’ve matched the ground from the PLC power supply to the Arduino power supply, but still no luck.

 SerialAT.begin(115200);

Any software serial has trouble receiving at higher baud rates. Can you change the baud rate of the PLC (and Arduino) to a lower value. Start at 9600 and work up.

I've tried that already.

I did start at 9600 with everything however I read somewhere (trying to do my own fault finding) that the software serial doesn't respond well to lower baud rates so I increased it to 19200 and then I tried 115200

however I read somewhere (trying to do my own fault finding) that the software serial doesn't respond well to lower baud rates

Can you link to that? On the face of it, it’s rubbish.

Why is there no line that defines the TX and RX pins? The only one is commented out.

AltSoftSerial is capable of running up to 31250 baud on 16 MHz AVR

From the AltSoftSerial reference.

And why initialize the soft serial port every time through loop()? That is not right.

groundFungus: From the AltSoftSerial reference.

Like i said the first Baud rate I tried was 9600 with no luck

Grumpy_Mike: Can you link to that? On the face of it, it’s rubbish.

Why is there no line that defines the TX and RX pins? The only one is commented out.

I'm going to have to search where I found it, I can't remember off the top of my head.

I'm using the AltSoftSerial which sets pin 8 and 9 to RX and TX.

https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html

So the TX from the PLC goes to pin 8 of the Arduino and PLC RX goes to pin 9?

And why initialize the soft serial port every time through loop()?

groundFungus: So the TX from the PLC goes to pin 8 of the Arduino and PLC RX goes to pin 9?

And why initialize the soft serial port every time through loop()?

No the TX and RX from the PLC goes through a RS232 to TTL converter, and from that the TX and RX goes to the Arduino.

The initialize soft serial was a mistake on my side, I moved it the Void setup (and I've dropped the Baud rate) but it didn't make a difference. Still no information received from the PLC