Mitsubishi FX and Arduino

bgmaxy

Member
Join Date
Aug 2011
Location
ku
Posts
7
Hello ,
I am trying to connect Arduino Mega to FX3u-32MR using serial communication
board FX232 BD
but nothing works
i am sending a number (in binary format ) over the serial port and checking that it is moved to the address i designated in the PLC but the result is always nothing o_O
can anybody send me a sample ladder for serial comm in this PLC to try as the one i found in Mitsubishi manual isn't working
HELP
 
Hi bgmaxy,
I would recommend you to verify as following,
1) Use MAX232 to convert RS232/TTL <-> RS232/V.24 because the Arduino it use RS232 TTL Level (it's normal for the Controllers)
Maxims MAX232 is one of those wonderful components that solves so many signal conversion problems. Here is my Paintbrush animation for electronics students to better explain how this chip works.

This chip converts RS232 signal voltage levels to TTL voltage levels and visa-versa, hence if you need to communicate to your PC through it's serial port (COM1 or COM2) then this is the chip that can perform that function. If you have a microcontroller circuit, or a phone, or a calculator that requires a PC connection then this is the chip that is needed to make that communication happen.

The RS232 serial port protocol (v.24) states -15 V to represent binary 1 and +15 V to represent binary 0. For TTL communication this is incompatible since TTL uses 0 V to represent binary 0 and +5 V to represent binary 1. MAX232 chip converts serial signal voltage levels to TTL standards, and also visa versa. It therefore has a driver and a receiver to perform this function.
2) If you still need my help about the program, pls do not hesitate contact me.

Tutor-A
 
Presuming that your Arduino works fine, you need to give us additional data... Posting your GX IEC Developer, or GX Developer or GX Works application would be good start. Explaining protocol you are using would be also very helpful.... Also don't forget to write about things, like MSB/LSB order and similar... then we can be pretty helpful.
 
Hi goghie,
Thank you for your replied, I will explain much as I can do on this text forum.
Please note that, This is the prototype project. I must continue to do data manipulation on both sides of PLC and Arduino.
Once I had achieve my expectation of the project I will give clearly representation such as Photo and Graphical documents on my Website soon.

1. The Project simplified diagram of PLC and Arduino Uno R3, and Interface diagram as below,
1.1 Main Equipment
1.1.1 Mitsubishi PLC
- FX1S-30MR (CPU with DI/DO)
- FX1N-232-BD (RS-232 Board)
1.1.2 Maxim IC : Max232
1.1.3 Micro-Controller : Arduino Uno R3

[ MITSUBISHI PLC ] [ IC Signal Converter ] [ Micro-Controller]
[ FX Family PLC ]<-------->[ Max232 ]<----->[ Aduino Uno R3 ]


DB9 connector TTL side V.24 side
(RX) Pin#2 --------- Pin#7 (TX) Pin#10 ------ Pin#10 (RX)
(TX) Pin#3 --------- Pin#8 (RX) Pin#11 ------ Pin#11 (TX)
(SG) Pin#5 --------- Pin#15 (G ) Pin#15 ------ GND
(DTR)Pin#4--/
(DSR)Pin#6--\

(RTS)Pin#7--/
(CTS)Pin#8--\

Please read the technical manual from Main Equipment maker (OEM).

To be continues ...đź“š
 
2. The Aduino Code is as below,

#include <SoftwareSerial.h>
#include "Timer.h"
//#include <Stdint.h>
// software serial #1: TX = digital pin 10, RX = digital pin 11
SoftwareSerial portOne(10,11);

String plcString = "";
String inputPLC = "";
boolean plcComplete =false;
boolean flag_save_plc =false;
uint8_t count_words;
String words[2] ="";
int LEDpin3 = 3;
int LEDpin4 = 4;
int LEDpin5 = 5;
int LEDpin6 = 6;
int LEDpin7 = 7;
const int PBpin2 = 2; // the number of the pushbutton pin
int PBpin2State = 0; // variable for reading the pushbutton status
int PBpin2StatePrev = 0;
int AI0Pin = A0; // select the input pin for the potentiometer
int AI0Value = 0; // variable to store the value coming from the sensor
Timer t; // Timer
String resultBuf[6];

void setup()
{

inputPLC.reserve(32);
plcString.reserve(128);
words[0].reserve(32);
words[1].reserve(32);

count_words =0;
pinMode(LEDpin3, OUTPUT); // initialize the LED pin as an output:
pinMode(LEDpin4, OUTPUT); // initialize the LED pin as an output:
pinMode(LEDpin5, OUTPUT); // initialize the LED pin as an output:
pinMode(LEDpin6, OUTPUT); // initialize the LED pin as an output:
pinMode(LEDpin7, OUTPUT); // initialize the LED pin as an output:
digitalWrite(LEDpin3, LOW);
digitalWrite(LEDpin4, LOW);
digitalWrite(LEDpin5, LOW);
digitalWrite(LEDpin6, LOW);
digitalWrite(LEDpin7, LOW);
pinMode(PBpin2, INPUT); // initialize the pushbutton pin as an input:
PBpin2State = digitalRead(PBpin2); // read the initial state
// t.every(1000, takeReading); // Timer .... msec for reading data and sending to Serial
t.every(1000, takeReading); // Timer .... msec for reading data and sending to Serial
t.oscillate(LEDpin7, 1000, LOW); // Pin, time mSec, initial state

Serial.begin(9600);
portOne.begin(9600);
// portOne.begin(19200);
// portOne.begin(38400);
}

void loop() {
t.update(); // Timer
// read the value from the sensor:
AI0Value = analogRead(AI0Pin);
PBpin2StatePrev = digitalRead(PBpin2); // read input value and store it in val
if (PBpin2StatePrev != PBpin2State) { // the button state has changed!
if (PBpin2StatePrev != LOW) { // check if the button is pressed
digitalWrite(LEDpin6, HIGH); // turn LED on
// AI0Value = analogRead(AI0Pin);
// portOne.println(AI0Value);
// portOne.println("ABCDEF");
SendData();
}
if (PBpin2StatePrev != HIGH) { // check if the button is not pressed
digitalWrite(LEDpin6, LOW); // turn LED off
}
}
PBpin2State = PBpin2StatePrev; // save the new state in our variable

// Read data from PLC
if (portOne.available()) {
char inByte = (char)portOne.read();
// portOne.write(inByte);
// portOne.print(inByte);
if (inByte == 0x03) { //ETX
flag_save_plc =false;
plcComplete =true;
digitalWrite(LEDpin3, LOW);
Serial.print(">");
Serial.println(plcString);
// portOne.print(plcString);
// portOne.print(inByte);
}
else if (inByte == 0x02) { //STX
flag_save_plc =true;
inputPLC ="";
digitalWrite(LEDpin3, HIGH);
// portOne.print(inByte);

}
if (flag_save_plc == true) { //Data body
if (inByte != 0x02) {
plcString += inByte;
// portOne.print(inByte);
// portOne.print(plcString);
}
}
}
if (plcComplete) {
digitalWrite(LEDpin4, HIGH);
for(int i=0; i<plcString.length(); i++) {
if(plcString.charAt(i) != ' ') {
words[count_words] += plcString.charAt(i);
if (words[0].equals("D10012345")) {
digitalWrite(LEDpin5, HIGH);
} else {
digitalWrite(LEDpin5, LOW);
}
} else {
count_words++;
}
} //End for
// clear variable
count_words = 0;
words[0] = "";
words[1] = "";
plcString = "";
plcComplete = false;
} // End plcComplete
else
{
digitalWrite(LEDpin4, LOW);
}
// delay(10);
} //End loop

// Timer task
void takeReading()
{
SendData();
} //End takeReading

void SendData()
{
// read the value from the sensor:
// AI0Value = analogRead(AI0Pin);

String StrBuf[10];

// String StrAI0 = String(StrDataIn);
String StrAI0 = String(AI0Value);

//String Length & Trim
// portOne.print("StrAI0 = ");
// portOne.println(StrAI0);
StrAI0.trim();
// portOne.print("StrAI0_Length = ");
int StrAI0_Length = StrAI0.length();
// portOne.println(StrAI0_Length);
// portOne.println(StrDataIn);

if (StrAI0_Length == 5 ) {
StrBuf[0] = "+";
StrBuf[1] = String(StrAI0[0]);
StrBuf[2] = String(StrAI0[1]);
StrBuf[3] = String(StrAI0[2]);
StrBuf[4] = String(StrAI0[3]);
StrBuf[5] = String(StrAI0[4]);
} else if (StrAI0_Length == 4 ) {
StrBuf[0] = "+";
StrBuf[1] = "0";
StrBuf[2] = String(StrAI0[0]);
StrBuf[3] = String(StrAI0[1]);
StrBuf[4] = String(StrAI0[2]);
StrBuf[5] = String(StrAI0[3]);
} else if (StrAI0_Length == 3 ) {
StrBuf[0] = "+";
StrBuf[1] = "0";
StrBuf[2] = "0";
StrBuf[3] = String(StrAI0[0]);
StrBuf[4] = String(StrAI0[1]);
StrBuf[5] = String(StrAI0[2]);
} else if (StrAI0_Length == 2 ) {
StrBuf[0] = "+";
StrBuf[1] = "0";
StrBuf[2] = "0";
StrBuf[3] = "0";
StrBuf[4] = String(StrAI0[0]);
StrBuf[5] = String(StrAI0[1]);
} else if (StrAI0_Length == 1 ) {
StrBuf[0] = "+";
StrBuf[1] = "0";
StrBuf[2] = "0";
StrBuf[3] = "0";
StrBuf[4] = "0";
StrBuf[5] = String(StrAI0[0]);
} else {

} //End if StrAI0_Length
StrBuf[6] = "D";
StrBuf[7] = "1";
StrBuf[8] = "0";
StrBuf[9] = "0";

//Tx data => PLC
portOne.print(0x02); //STX - D0
portOne.print(StrBuf[0]); //Sign - D1
portOne.print(StrBuf[1]); //x1 - D2
portOne.print(StrBuf[2]); //x10 - D3
portOne.print(StrBuf[3]); //x100 - D4
portOne.print(StrBuf[4]); //x1000 - D5
portOne.print(StrBuf[5]); //x10000 - D6
portOne.print(StrBuf[6]); //D - D7
portOne.print(StrBuf[7]); //1 - D8
portOne.print(StrBuf[8]); //0 - D9
portOne.print(StrBuf[9]); //0 - D10
portOne.print(0x03); //ETX - D11

//Serial Mornitor on P0, P1, and on Console
Serial.print(0x02);
Serial.print(StrBuf[0]);
Serial.print(StrBuf[1]);
Serial.print(StrBuf[2]);
Serial.print(StrBuf[3]);
Serial.print(StrBuf[4]);
Serial.print(StrBuf[5]);
Serial.print(StrBuf[6]);
Serial.print(StrBuf[7]);
Serial.print(StrBuf[8]);
Serial.print(StrBuf[9]);
Serial.print(0x03);
Serial.println();

} //End SendData

To be continues ...
 
3. The Mitsubishi GX IEC Developer Application Program (Ladder diagram) is as below,

M8000
|---| |---------------------------------------------------(M8161)-----|

M8002
|---| |------------------------------------------[ MOV H81 D8120]-----|

M8000
|---| |--------------------------------------[ RS D240 K8 D0 K12 ]-----|
| M8123
|------|^|----------------------------[ PLF M0 ]-----|
|
|-----------------[ RST M8123 ]-----|

M0
|---| |--------------------------------------------[ MOV H2 D240 ]-----|
|
|------------------[ MOV D1 D241 ]-----|
|
|------------------[ MOV D2 D242 ]-----|
|
|------------------[ MOV D3 D243 ]-----|
|
|------------------[ MOV D4 D244 ]-----|
|
|------------------[ MOV D5 D245 ]-----|
|
|------------------[ MOV D6 D246 ]-----|
|
|------------------[ MOV H3 D247 ]-----|
|
|--------------------[ SET M8122 ]-----|


|----------------------------------------------------------[ END ]-----|

OK, It's hard to explain in text mode 555+++
Any question, please do not hesitate to ask me.

Regards,
Tutor-A
 
3. The Mitsubishi GX IEC Developer Application Program (Ladder diagram) is as below,

M8000
|---| |---------------------------------------------------(M8161)-----|

This is to force 8bit operation

M8002
|---| |------------------------------------------[ MOV H81 D8120]-----|
This is 9600, 8, N, 1... Also for first channel I think it should be D8400 (I'm not shore with FX3S, but with FX3G and FX3U it is)

M8000
|---| |--------------------------------------[ RS D240 K8 D0 K12 ]-----|
| M8123
|------|^|----------------------------[ PLF M0 ]-----|
|
|-----------------[ RST M8123 ]-----|
Why are you using M8000? It is always on..
If you are using GX IEC developer it should be RS_M or even better RS2_M.
M8123 is finished receiving data,so it is better to use PLS instead of PLM.
Also maybe you want to use M8403 instead.

M0
|---| |--------------------------------------------[ MOV H2 D240 ]-----|
|
|------------------[ MOV D1 D241 ]-----|
|
|------------------[ MOV D2 D242 ]-----|
|
|------------------[ MOV D3 D243 ]-----|
|
|------------------[ MOV D4 D244 ]-----|
|
|------------------[ MOV D5 D245 ]-----|
|
|------------------[ MOV D6 D246 ]-----|
|
|------------------[ MOV H3 D247 ]-----|
|
|--------------------[ SET M8122 ]-----|


|----------------------------------------------------------[ END ]-----|

M8402 is data sent flag, and M8063 is communication parameter setting error flag, and nibbles are rotated with Mitsubishi.
 
Mitsubishi PLC
- FX1S-30MR (CPU with DI/DO)
- FX1N-232-BD (RS-232 Board)
According to this model of PLC and RS232 Board, I try to follow the programming manual but there is something to do by trial.

Quote:
Originally Posted by Tutor-A View Post
M8000
|---| |--------------------------------------[ RS D240 K8 D0 K12 ]-----|
| M8123
|------|^|----------------------------[ PLF M0 ]-----|
|
|-----------------[ RST M8123 ]-----|
Why are you using M8000? It is always on..
If you are using GX IEC developer it should be RS_M or even better RS2_M.
M8123 is finished receiving data,so it is better to use PLS instead of PLM.
Also maybe you want to use M8403 instea
This rung I already use PLS but the result of link was not good enough. The program I show you is the practical program, let say good enough to work to communicate between FX1S-30MR using FX1N-232-BD with Arduino Uno R3. It fast enough and stable, not delay response.
 
Mitsubishi PLC
- FX1S-30MR (CPU with DI/DO)
- FX1N-232-BD (RS-232 Board)
According to this model of PLC and RS232 Board, I try to follow the programming manual but there is something to do by trial.

Quote:
Originally Posted by Tutor-A View Post
M8000
|---| |--------------------------------------[ RS D240 K8 D0 K12 ]-----|
| M8123
|------|^|----------------------------[ PLF M0 ]-----|
|
|-----------------[ RST M8123 ]-----|
Why are you using M8000? It is always on..
If you are using GX IEC developer it should be RS_M or even better RS2_M.
M8123 is finished receiving data,so it is better to use PLS instead of PLM.
Also maybe you want to use M8403 instea
This rung I already use PLS but the result of link was not good enough. The program I show you is the practical program, let say good enough to work to communicate between FX1S-30MR using FX1N-232-BD with Arduino Uno R3. It fast enough and stable, not delay response.

FX1S Model has some limitation, It's unable to use RS2 T^To_O
 
Can you guys please explain function RS and RS2, with examples on FX3U, I don't understand how is working. In manual so short information about it.
 

Similar Topics

I'm looking to get some spare keys for this PLC. Does anyone know a source or have a part number? My searches are turning up nothing at the moment.
Replies
1
Views
64
I'm struggling to get an FR-E800SCE to work on CC-Link IE TSN. I'm sure the issue is with the drive, when I plug in the network cable I get no...
Replies
1
Views
90
Hi , Where i can find Mitsubishi PLC Card end of line & replacement model details. i am looking for Q02CPU replacement model. Please advice. thanks
Replies
2
Views
126
Hi guys, Im trying to set the real time clock in my Mitsubishi FX1N, but it shows this error ES: 01800001 I have good communication with...
Replies
3
Views
142
Hello there is a way to do the polyfit on 3rd degree on this plc. for imput i have a munimum value of 5 X and 5 Y value for example Measured...
Replies
58
Views
2,572
Back
Top Bottom