Pages: [1]   Go Down
Author Topic: Arduino Mega 2560 via RS232 to Omron PLC  (Read 2057 times)
0 Members and 1 Guest are viewing this topic.
Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

For my personal project (windmill : www.windmolensite.be) I'm trying to use an Arduino to read real-time data from the PLC controlling my windmill.
I figured out how the PLC 'hostlink' protocol works and did some simple tests using an RS232 serial cable and my laptop using a terminal program.

PC --> Serial Cable --> PLC

The terminal connection settings are 9600, 7 Data bits, Even Parity and 2 Stop bits.

When I send the command : @00TS123443* the PLC responds with the same string : @00TS123443* (This is for testing purpose)

https://www.dropbox.com/s/40a3wvip5coo480/PLC_from_PC.JPG

No I would like to get the same thing working with my Arduino.

Arduino --> WaveShare RS232 shield --> Serial Cable --> PLC (The shield has it's RX and TX pins connected to the Arduino pins 16 (TX2) and 17 (RX2), VCC and GND to 3v3 and GND)

But in this setup, it isn't working.

https://www.dropbox.com/s/ccvq22yf3hnt43h/PLC_from_PC_Arduino.JPG

The code, as you can see it basic :-)

Code:
/*
PLC
 */

int incomingByte = 0;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize Serial1
  Serial.begin(9600);  //For debugging, towards PC
  if (Serial) {
    Serial.println("Connected to Computer!");
  }
 
  Serial2.begin(9600,SERIAL_7E2); //SERIAL_7E2 = 0x2C, see HardwareSerial.h
  Serial.println("Waiting for Serial2...");
}

// the loop routine runs over and over again forever:
void loop() {
  Serial2.println("@00TS123443*");
 
  while (Serial2.available() > 0) {
    incomingByte = Serial2.read();
    // say what you got:
    Serial.print("I received: ");
    Serial.println(incomingByte, DEC);
   }
   delay(1500); 
}

If I connect the Arduino to a serial port on my PC, I can see the correct string being sent by the Arduino.

Arduino --> WaveShare RS232 shield --> Serial Cable --> Serial-to-USB adapter --> PC

https://www.dropbox.com/s/2ssoqbnpxuit077/PC_from_Arduino.JPG

Any ideas where to look?

Regards,

Andy
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16548
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your

Code:
Serial2.println("@00TS123443*");

The serial print line command adds carriage return/new line characters to the end of your message which might be causing problems. Try just using the serial print command as such:

Code:
Serial2.print("@00TS123443*");

Lefty

Logged

Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lefty,

Thanks for the reply. I already tried all sorts of combinations with write & print/println, none seem to work :-( If I test it manually, I need to press <enter> after the test string @00TS123443* so println() sounds the correct method of sending the string?

I find it a bit odd, because a normal terminal session works. Could it be the rare serial settings like 9600, 7E2?

ps: The PLC doesn't respond if you don't enter a correct command. Maybe the string isn't beeing sent like I expect, but how to check this...
ps2: I also notice that the 'communication' light on the PLC doesn't lit when sending data with the arduino but when using the terminal session it does!

Regards,

Andy.

« Last Edit: February 08, 2013, 11:39:16 am by angeraer » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4755
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried this versions too?

Code:
Serial2.print("@00TS123443*\n");

or

Code:
Serial2.print("@00TS123443*\r");

Device like PLCs can be very picky in these aspects.
Logged

Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, also tried these :-(

The communication led stays off. Like it doesn't get sent...

Andy.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4755
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The communication LEDs are connected only to the RX0/TX0 lines on the Arduino.

Do you have a link to that Waveshare shield? I cannot find that product to check it's electrical parameters.
Logged

Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I meant that the communication lights on the PLC don't flash when connected to the Arduino. They do when connected to the PC.

Here is the link to the documentation : http://www.wvshare.com/product/RS232-Board.htm

It contains an SIPEX SP3232E chip.

See attachement for details (File downloaded from URL above)

Andy.

* RS232-Board.7z (1835.23 KB - downloaded 34 times.)
« Last Edit: February 09, 2013, 05:24:27 am by angeraer » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4755
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To be a little picky: this is not a shield, it's just a RS232 adapter module. Shields are designed for Arduino and are stacked on it. That ensures that every connector goes to the right pin.

How have you connected the module to your Arduino? Describe every connection you made.

My guess is you have to cross the RX/TX lines.
Logged

Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I made the connections like this :

RS232 <------> Arduino
VCC                5V
GND               GND
RXout             RX2
TXin               TX2
CTS (not connected)
RTS (not connected)

When I swap the TX/RX (wrong!) I randomly get a response which is exactly what I'm sending, so that's very strange, even without the PLC connected!?! Looks like garbage to me?

Andy.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4755
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My guess is, you have to swap the TX/RX lines behind the module, between the module and the PLC. Your module is wired to be a DCE, pin 2 of the sub-d connector is TX, while pin 3 is RX. A DTE (e.g. the PC) has it the other way around. So try a null modem cable between the module and the PLC.
Logged

Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey Pylon,

Thanks for the input. Took me a while to test again, but I've succeeded to get the Arduino to read out the PLC! It was all a matter of cabling (see attachement).

I'm able to read/set the configuration of the PLC.

Code:
/*
PLC
 */

int incomingByte = 0;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize Serial1
  Serial.begin(9600);  //For debugging, towards PC
  if (Serial) {
    Serial.println("Connected to Computer!");
  }
  
  Serial2.begin(9600,SERIAL_7E2); //SERIAL_7E2 = 0x2C, see HardwareSerial.h
  Serial.println("Waiting for Serial2...");
  Serial2.println("@00RD0100000354*");
}

// the loop routine runs over and over again forever:
void loop() {

  while (Serial2.available() > 0) {
    incomingByte = Serial2.read();
    Serial.print("I received: ");
    Serial.write(incomingByte);
    Serial.println(".");
   }
   delay(2000);  
}

If I run it, it gives me the expexted result :

Code:
Connected to Computer!
Waiting for Serial2...
I received: @.
I received: 0.
I received: 0.
I received: R.
I received: D.
I received: 0.
I received: 0.
I received: 9.
I received: 8.
I received: 7.
I received: 6.
I received: 1.
I received: 2.
I received: 3.
I received: 4.
I received: 8.
I received: 0.
I received: 0.
I received: 0.
I received: 5.
I received: A.
I received: *.
I received:
.

Thanks a lot for the assistance!

Andy




* RS232_Cable.JPG (34.76 KB, 610x243 - viewed 122 times.)
« Last Edit: February 23, 2013, 07:54:56 am by angeraer » Logged

Pages: [1]   Go Up
Jump to: