RichardPowrie
I am trying to connect OpenPLC to a controllino, which is Arduino Mega based. Using a simple program of a button turning on a light, I have the following Ladder Diagram.
Screenshot 2021-01-13 154245.png      
The Controllino that I have is on a training board, which has toggle switches connected to pins A0-A7, which are on the Arduino Analogue pins A0-A7 because they can switch out with potentiometers. There are LEDs connected to pins D0-D7, which are on the Arduino pins 2-9.

As far as I understand this should work. The simulation works, compilation works, and then when I upload the .st file on the dashboard it gives an error:


Optimizing ST program...
Generating C files...
./st_files/983225.st:3-6..3-25: error: Bit size of data type is incompatible with bit size of location.
./st_files/983225.st:4-6..4-25: error: Bit size of data type is incompatible with bit size of location.
2 error(s) found. Bailing out!
Error generating C files
Compilation finished with errors!


From my understanding this means I've defined the variables with the wrong type. I changed the data types to INT and that worked on the Controllino just fine.

When I tried a more complex circuit with AND, OR and NOT functions, then OpenPLC wouldn't compile saying it is the wrong data type. The error is below. I've tried all of the different variable types and BOOL is the only one that compiles (which makes sense), but it gets the "Bit size of data type is incompatible with bit size of location." error. What am I doing wrong?
Screenshot 2021-01-13 160621.png 

The error received was:

exited with status 1 (pid 19408)
C:\Users\01464686\Documents\OpenPLC\MEC4127F_tut2\build\plc.st:107-44..107-43: error: Invalid data type for 'NOT' expression.
In section: PROGRAM T205
0107:   D0 := NOT(A7) AND NOT(A1) AND (A0 OR D0);
C:\Users\01464686\Documents\OpenPLC\MEC4127F_tut2\build\plc.st:107-44..107-43: error: Invalid data type for 'NOT' expression.
In section: PROGRAM T205
0107:   D0 := NOT(A7) AND NOT(A1) AND (A0 OR D0);
C:\Users\01464686\Documents\OpenPLC\MEC4127F_tut2\build\plc.st:107-44..107-43: error: Data type mismatch for 'OR' expression.
In section: PROGRAM T205
0107:   D0 := NOT(A7) AND NOT(A1) AND (A0 OR D0);
C:\Users\01464686\Documents\OpenPLC\MEC4127F_tut2\build\plc.st:108-9..108-15: error: Invalid data type for 'NOT' expression.
In section: PROGRAM T205
0108:   D1 := NOT(A6) AND NOT(A7) AND NOT(A1) AND (A0 OR D0);
C:\Users\01464686\Documents\OpenPLC\MEC4127F_tut2\build\plc.st:108-21..108-27: error: Invalid data type for 'NOT' expression.
In section: PROGRAM T205
0108:   D1 := NOT(A6) AND NOT(A7) AND NOT(A1) AND (A0 OR D0);
C:\Users\01464686\Documents\OpenPLC\MEC4127F_tut2\build\plc.st:108-33..108-39: error: Invalid data type for 'NOT' expression.
In section: PROGRAM T205
0108:   D1 := NOT(A6) AND NOT(A7) AND NOT(A1) AND (A0 OR D0);
C:\Users\01464686\Documents\OpenPLC\MEC4127F_tut2\build\plc.st:108-47..108-53: error: Data type mismatch for 'OR' expression.
In section: PROGRAM T205
0108:   D1 := NOT(A6) AND NOT(A7) AND NOT(A1) AND (A0 OR D0);
7 error(s) found. Bailing out!
Error : IEC to C compiler returned 1
PLC code generation failed !


My understanding of the mapping between the three systems (Controllino doesn't use the OpenPLC digital pins for my purposes):

 

Arduino Pin

Controllino

OpenPLC I/O

Analog inputs

A0 / 54

A0

%IW100.0

A1 / 55

A1

%IW100.1

A2 / 56

A2

%IW100.2

A3 / 57

A3

%IW100.3

A4 / 58

A4

%IW100.4

A5 / 59

A5

%IW100.5

A6 / 60

A6

%IW100.6

A7 / 61

A7

%IW100.7

A8 / 62

A8

%IW100.8

A9 / 63

A9

%IW100.9

A10 / 64

A10

%IW100.10

A11 / 65

A11

%IW100.11

A12 / 66

D_IN_0 (DI0)

%IW100.12

A13 / 67

D_IN_1 (DI1)

%IW100.13

A14 / 68

A12

%IW100.14

A15 / 69

A13

%IW100.15

Analog outputs

2

D0

%QW100.0

3

D1

%QW100.1

4

D2

%QW100.2

5

D3

%QW100.3

6

D4

%QW100.4

7

D5

%QW100.5

8

D6

%QW100.6

9

D7

%QW100.7

10

D_IN_2 (DI2)

%QW100.8

11

D_IN_3 (DI3)

%QW100.9

12

A_OUT_0 (AO0)

%QW100.10

13

A_OUT_1 (AO1)

%QW100.11


Reply 0 0
thiagoralves
%IW locations are always 16-bit integers. You can only use INT, UINT, and WORD types on them. Simulation works because since it doesn't run on any hardware, it completely ignores locations. Also, there is not such thing as %IW100.0. The dot notation should only be used with %QX and %IX locations (boolean locations). Check  https://www.openplcproject.com/reference/plc-addressing/ for more information.

Finally, I don't think it is a good idea to associate integer with contacts. Contacts are expecting boolean values. Perhaps a good suggestion would be to create a function block that receives your %IW100 integer and then outputs a boolean value depending on the integer input. This will allow you to have a threshold for when the input is activated (potentiometer half way through for example). You can save this boolean output on a variable and use it on a contact as usual.
Reply 1 0
RichardPowrie
Thank you for the reply. I will see how I can change the addressing to implement your suggestion. I am confused though, you say that the %IW100.0 is wrong. The documentation on  https://www.openplcproject.com/runtime/arduino/ needs to be changed then because it indicates a "." used for W addresses. Is that correct?
Reply 0 0
thiagoralves
Yes, that is wrong, from OpenPLC_v2 days... Main problem is that the table is an image, which makes it a pain to edit
Reply 0 0
RichardPowrie
How do I address an analog pin that I wish to use as digital? In arduino you can specify a pin as digital, even though it is one of the analog pins. Does OpenPLC do this, or is the only way to do a comparison as you suggested earlier?

I've done my best to line up the pins between the Arduino Mega, my Controllino Maxi (which is nearly pin compatible with Arduino Mega) and the OpenPLC addresses. You can use this to update that page if you wish. My problem is that the Controllino pins I need to use are all on the analog input or output of the OpenPLC addresses. So because I want to learn basic ladder diagrams. I myself am new to the Addressing standard, so I don't know what actual number to use. Can I address the same analog pin using %IX instead of %IW to make sure it's boolean? If yes, how do I know what number to use after the designator?
Physical pinPort PinArduino PinOpenPLC AddressOpenPLC labelControllinoControllino Labels
78PA022%IX100.0Digital inputsR0Relay
76PA224%IX100.1Digital inputsR2Relay
74PA426%IX100.2Digital inputsR4Relay
72PA628%IX100.3Digital inputsR6Relay
60PC730%IX100.4Digital inputsR8Relay
58PC532%IX100.5Digital inputs  
56PC334%IX100.6Digital inputs  
54PC136%IX100.7Digital inputs  
50PD738%IX101.0Digital inputs  
52PG140%IX101.1Digital inputs  
42PL742%IX101.2Digital inputsDigital 12 
40PL544%IX101.3Digital inputsDigital 14 
38PL346%IX101.4Digital inputs  
36PL148%IX101.5Digital inputs  
22PB350%IX101.6Digital inputsMISO 
20PB152%IX101.7Digital inputsSCK 
64PJ114%IX102.0Digital inputs  
63PJ015%IX102.1Digital inputs  
13PH116%IX102.2Digital inputsTXD2 
12PH017%IX102.3Digital inputsRXD2 
46PD318%IX102.4Digital inputsInterrupt 0 
45PD219%IX102.5Digital inputsInterrupt 1 
44PD120%IX102.6Digital inputsSDA 
43PD021%IX102.7Digital inputsSCL 
77PA123%QX100.0Digital outputsR1Relay
75PA325%QX100.1Digital outputsR3Relay
73PA527%QX100.2Digital outputsR5Relay
71PA729%QX100.3Digital outputsR7Relay
59PC631%QX100.4Digital outputsR9Relay
57PC433%QX100.5Digital outputs  
55PC235%QX100.6Digital outputs  
53PC037%QX100.7Digital outputs  
70PG239%QX101.0Digital outputs  
51PG041%QX101.1Digital outputs  
41PL643%QX101.2Digital outputsDigital 13 
39PL445%QX101.3Digital outputsDigital 15 
37PL247%QX101.4Digital outputs  
35PL049%QX101.5Digital outputs  
21PB251%QX101.6Digital outputsMOSI 
19PB053%QX101.7Digital outputs/SS 
97PF0A0 / 54%IW0Analog inputsAI0Analog inputs
96PF1A1 / 55%IW1Analog inputsAI1Analog inputs
87PK2A10 / 64%IW10Analog inputsAI10Analog inputs
86PK3A11 / 65%IW11Analog inputsAI11Analog inputs
85PK4A12 / 66%IW12Analog inputsDI0Digital inputs
84PK5A13 / 67%IW13Analog inputsDI1Digital inputs
83PK6A14 / 68%IW14Analog inputsAI12Analog inputs
82PK7A15 / 69%IW15Analog inputsAI13Analog inputs
95PF2A2 / 56%IW2Analog inputsAI2Analog inputs
94PF3A3 / 57%IW3Analog inputsAI3Analog inputs
93PF4A4 / 58%IW4Analog inputsAI4Analog inputs
92PF5A5 / 59%IW5Analog inputsAI5Analog inputs
91PF6A6 / 60%IW6Analog inputsAI6Analog inputs
90PF7A7 / 61%IW7Analog inputsAI7Analog inputs
89PK0A8 / 62%IW8Analog inputsAI8Analog inputs
88PK1A9 / 63%IW9Analog inputsAI9Analog inputs
6PE42%QW0Analog outputsDO0Digital outputs
7PE53%QW1Analog outputsDO1Digital outputs
25PB612%QW10Analog outputsAO0/ Digital 10Analog outputs
26PB713%QW11Analog outputsAO1/ Digital 11Analog outputs
1PG54%QW2Analog outputsDO2Digital outputs
5PE35%QW3Analog outputsDO3Digital outputs
15PH36%QW4Analog outputsDO4Digital outputs
16PH47%QW5Analog outputsDO5Digital outputs
17PH58%QW6Analog outputsDO6Digital outputs
18PH69%QW7Analog outputsDO7Digital outputs
23PB410%QW8Analog outputsDI2Digital inputs
24PB511%QW9Analog outputsDI3Digital inputs
Reply 0 0
thiagoralves
I feel it would be much easier for you to just change the pin mapping on the Arduino firmware side. A pin that comes as analog (on %IW location) can only be used as analog input by OpenPLC. If you change the pin type on Arduino firmware to digital, it will come on the %IX range. Just keep in mind that you can’t change the total number of inputs/outputs otherwise you won’t be able to use the Arduino template on the slave devices page. That template takes into consideration the exact number of inputs and outputs on the original OpenPLC firmware. So if you make an A pin as digital input, you will have to use it in place of another pin that is configured as digital input to keep the size the same
Reply 0 0
Konrad_B
I had the same problem. I solved it on the lowest resistance line with the INT -> BOOL converter and an additional bool variable.
It looks like :
 
Reply 0 0
Mahedi
How to make a function block?
Reply 0 0
Reply