You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/05.pro-solutions/solutions-and-kits/portenta-machine-control/tutorials/pmc-opta-modbus-tcp/content.md
+48-35Lines changed: 48 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: 'Modbus TCP with Portenta Machine Control & Opta™'
3
3
difficulty: intermediate
4
-
description: "Modbus TCP communication on a real industrial application using a Portenta Machine Control, Opta™, a temperature sensor, and the Arduino® PLC IDE."
4
+
description: "Learn to use Modbus TCP communication on a real industrial application using a Portenta Machine Control, Opta™, a temperature sensor, and the Arduino® PLC IDE."
5
5
tags:
6
6
- Thermocouple
7
7
- IEC-61131-3
@@ -17,18 +17,20 @@ software:
17
17
- plc-ide
18
18
---
19
19
20
-
## Overview
20
+
## Overview & Video Tutorial
21
21
22
-
In this tutorial, a Portenta Machine Control and an Opta micro PLC will be used as **server** and **client** respectively to share temperature information through Modbus TCP using the PLC IDE. The server will do the measurements using a type K thermocouple and the client will activate its relay outputs when a certain threshold is reached.
22
+
In this tutorial, a Portenta Machine Control and an Opta™ micro PLC will be used as **server** and **client** respectively to share temperature information through Modbus TCP using the PLC IDE. The server will do the measurements using a type K thermocouple and the client will activate its relay outputs when a certain threshold is reached.
23
23
24
-
Here is a detailed guide in video format if you are a visual learner.
24
+
We have prepared a detailed guide in video format in case you are a visual learner.
25
25
26
26
<iframewidth="100%"height="480"src="https://www.youtube.com/embed/reBrbCq86uQ?si=q0EkR-B8bR0MeF5p"title="YouTube video player"frameborder="0"allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"allowfullscreen></iframe>
27
27
28
+
If you prefer to follow the tutorial in a written format, or need to review the steps and code done in the video tutorial, in the following sections you will find a step-by-step guide explaining how the temperature measurement and Modbus communication between both devices were done.
29
+
28
30
## Goals
29
31
30
32
- Learn how to measure temperature with the Portenta Machine Control using a thermocouple and the PLC IDE
31
-
-Learn how to use the Modbus protocol over TCP/IP using the PLC IDE
33
+
-Discover how to use the Modbus protocol over TCP/IP using the PLC IDE
32
34
- Leverage Arduino Pro products for real industrial applications
33
35
34
36
## Hardware and Software Requirements
@@ -39,7 +41,7 @@ Here is a detailed guide in video format if you are a visual learner.
39
41
- Type K thermocouple (x1)
40
42
- Ethernet cables (x2)
41
43
- Wired internet access
42
-
- 24 VDC Power Supply (x2)
44
+
- 24 VDC/0.5 A power supply (x2)
43
45
### Software
44
46
- The [Arduino PLC IDE](https://www.arduino.cc/pro/software-plc-ide) (including Arduino PLC IDE Tools)
45
47
-[Portenta Machine Control - PLC IDE Activation](https://store-usa.arduino.cc/products/plc-key-portenta-machine-control?queryID=undefined&selectedStore=us)
@@ -50,21 +52,21 @@ Here is a detailed guide in video format if you are a visual learner.
- In the __Portenta Machine Control__, connect the thermocouple terminals to TP0 and TN0 respectively. The 24 VDC power supply to the 24-volt input and GND.
55
+
- In the __Portenta Machine Control__: connect the thermocouple terminals to TP0 and TN0 respectively and the 24 VDC power supply to the 24-volt input and GND.
54
56
55
-
- In the __Opta micro PLC__, connect the power supply to the respective inputs on the screw terminals.
57
+
- In the __Opta™ micro PLC__: connect the power supply to the respective inputs on the screw terminals.
56
58
57
-
- Connect both the PMC and the Opta to your router using ethernet cables.
59
+
- Connect both the Portenta Machine Control and the Opta™ to your local network using ethernet cables.
58
60
59
61
### Portenta Machine Control Setup
60
62
61
63
After downloading the [PLC IDE](https://www.arduino.cc/pro/software-plc-ide), open it and create a __new project__ for the Portenta Machine Control.
62
64
63
-

65
+

64
66
65
67
A license is needed for this product to be used with the PLC IDE, you can buy it directly from the [Arduino store](https://store-usa.arduino.cc/products/plc-key-portenta-machine-control), and it will include the **product key** to activate the device.
66
68
67
-
Connect the PMC to the computer using a micro USB cable, the board needs to run a specific program (runtime) in order to interact with the **PLC IDE**. To flash it, select the device serial port and click on download.
69
+
Connect the Machine Control to the computer using a micro USB cable, the board needs to run a specific program (runtime) in order to interact with the **PLC IDE**. To flash it, select the device serial port and click on download.
68
70
69
71

70
72
@@ -81,7 +83,7 @@ The device will show its activation status, in this case, **No License** as it i
81
83
82
84

83
85
84
-
After that, the status should say **OK**, and now you are ready to start programming the Portenta Machine Control with the PLC IDE.
86
+
After the activation, the status should say **OK**. Now you are ready to start programming the Portenta Machine Control with the PLC IDE.
85
87
86
88
To learn more about the PLC IDE first setup, continue reading this [detailed guide](https://docs.arduino.cc/software/plc-ide/tutorials/plc-ide-setup-license/#6-license-activation-with-product-key-portenta-machine-control).
87
89
@@ -90,9 +92,9 @@ For the Modbus TCP configuration, on the **resources tab** go to the **Ethernet*
90
92
91
93

92
94
93
-
Now, go to the **sketch editor** and uncomment the library and setup function code lines. As the IP, we must use the same as the Portenta Machine Control, as it is connected to your router, you can find it on its configurations.
95
+
Go to the **sketch editor** and uncomment the library and setup function code lines. As the IP, we must use the same as the Portenta Machine Control, as it is connected to your local network, you can find it on its configurations.
94
96
95
-
In this case, the following configurations are used.
97
+
In this case, the following configurations are used:
96
98
97
99
```arduino
98
100
// Enable usage of EtherClass, to set static IP address and other
IPAddress ip(10, 0, 0, 157); // Portenta Machine Control IP address
106
108
IPAddress dns(10, 0, 0, 1); // gateway IP address
107
109
IPAddress gateway(10, 0, 0, 1); // gateway IP address
108
110
IPAddress subnet(255, 255, 255, 0);
@@ -113,15 +115,15 @@ void setup()
113
115
```
114
116

115
117
116
-
Now, create the variable that will be shared with the temperature sensor data in the network. For this, we go to **status variables** and click on **Add**. Configure it as follows:
118
+
Now create the variable that will be shared with the temperature sensor data in the network. Go to **status variables** and click on **Add**. Configure it as follows:
Next, go to **Temperature probes** and select the sensor type, for this tutorial, enable the **thermocouple** connected to the first channel by setting it to true.
126
+
Next go to **Temperature probes** and select the sensor type, for this tutorial, enable the **thermocouple** connected to the first channel by setting it to true.
@@ -137,13 +139,13 @@ To check if everything is okay, click on compile, and if no error is shown, you
137
139
138
140

139
141
140
-
Once uploaded, click on the **Connect** button again. Now, you can monitor the **temp_send** variable in the **Watch** window dragging and dropping it from the __Global shared__ variables in the project tab.
142
+
Once uploaded, click on the **Connect** button again. Now you can monitor the **temp_send** variable in the **Watch** window dragging and dropping it from the __Global shared__ variables in the project tab.
141
143
142
-
You should see the temperature value measured by the sensor.
144
+
You should see the temperature value measured by the sensor inside the "Watch" window.
143
145
144
-

146
+

145
147
146
-
### Opta Micro PLC Setup
148
+
### Opta™ Micro PLC Setup
147
149
148
150
Now the server is configured, create a new project, this time for the Opta™ micro PLC that will be the Client or Master.
149
151
@@ -164,7 +166,9 @@ Now, in the upper left corner, click on the **Connect** button and wait for the
164
166
165
167

166
168
167
-
***The Opta™ doesn’t need any license activation to be used with the PLC IDE***
169
+
***The Opta™ is Pre-Licensed so you don't have to buy any license to use it with the PLC IDE***
170
+
171
+
If the Opta status says **No License**, click on the **Activate PLC runtime** button to activate it. Learn more about this case in this [guide](https://docs.arduino.cc/tutorials/portenta-machine-control/plc-ide-setup-license/#7-license-activation-with-pre-licensed-products-opta).
168
172
169
173
#### Modbus TCP - Client
170
174
@@ -176,27 +180,27 @@ In the **Ethernet** tab, enable the Modbus TCP Master mode.
176
180
177
181
Then right-click on the **Ethernet** tab, click on **Add** and select the _Generic Modbus device_.
Now, click on the function and in the general settings, enter the shared variable address that you defined earlier in the server, `25000` in this case.
193
+
Now click on the function and in the general settings, enter the shared variable address that you defined earlier in the server, `25000` in this case.
In the Input Register tab, create a label for it, which could be `temp_reg`.
194
198
195
199

196
200
197
-
Now, go to the **sketch editor** and uncomment the library and setup function code lines. As the IP, we must use the same as the Opta™.
201
+
Go to the **sketch editor** and uncomment the library and setup function code lines. As the IP, we must use the same as the Opta™.
198
202
199
-
In this case, the following configurations are used.
203
+
In this case the following configurations are used:
200
204
201
205
```arduino
202
206
// Enable usage of EtherClass, to set static IP address and other
@@ -217,15 +221,15 @@ void setup()
217
221
```
218
222

219
223
220
-
Finally, define the Opta™ outputs behavior in function of the temperature read from the Portenta Machine Control. For this, go to the **resources tab > Relay Outputs** and give a variable name to each relay, in this case, call them `relay_1`, 2, 3 and 4 respectively.
224
+
Finally, define the Opta™ outputs behavior in function of the temperature read from the Portenta Machine Control. To do this, go to the **resources tab > Relay Outputs** and give a variable name to each relay, in this case, call them `relay_1`, `relay_2`, `relay_3` and `relay_4` respectively.
221
225
222
226

223
227
224
-
The same with the LED outputs, `LED1`, 2, 3 and 4.
228
+
The same with the LED outputs, `LED1`, `LED2`, `LED3` and `LED4`.
225
229
226
230

227
231
228
-
Now, go to the main code in the Project tab. Create a variable by right-clicking on the local variables window and then **insert**, call it **temp_local** and _integer_ as the type.
232
+
Now go to the main code in the Project tab. Create a variable by right-clicking on the local variables window and then **insert**, call it **temp_local** and _integer_ as the type.
229
233
230
234

231
235
@@ -277,12 +281,21 @@ With the final code written, compile the project and upload it the the Opta™ m
277
281
278
282
You can leave each device connected separately to the internet router or connect them together directly with one ethernet cable. The first option will let you update the preferred device remotely as you can access it through the local network.
279
283
280
-
Now, you can expose the temperature sensor to some heat and monitor it from the PLC IDE. The Opta™ relay outputs and LEDs will close and turn on when the temperature surpasses the programmed thresholds respectively.
284
+
Now you can expose the temperature sensor to some heat and monitor it from the PLC IDE. The Opta™ relay outputs and LEDs will close and turn on when the temperature surpasses the programmed thresholds respectively.
281
285
282
286

283
287
284
-
####Conclusion
288
+
### Conclusion
285
289
286
290
In this tutorial you learned how to communicate two Arduino PRO products using the Modbus TCP protocol, demonstrating a simple application of sharing temperature data to control a device's outputs.
287
291
288
-
As you can notice, the configuration process is very straightforward and the results were as expected.
292
+
As you can notice, the configuration process is very straightforward and the results were as expected, being a good starting point to adapt the work done here to create your own professional solution.
293
+
294
+
#### Next Steps
295
+
296
+
Extend your knowledge about the Portenta Machine Control, PLC IDE and the variety of industrial protocols it supports by following these tutorials:
297
+
298
+
-[Programming Introduction with Arduino PLC IDE](https://docs.arduino.cc/tutorials/portenta-machine-control/plc-programming-introduction/)
299
+
-[Tank Thermoregulation with Portenta Machine Control & Opta™](https://docs.arduino.cc/tutorials/portenta-machine-control/pmc-opta-temp-ctrl/)
300
+
-[Connect an RTD/Thermocouple to the Portenta Machine Control](https://docs.arduino.cc/tutorials/portenta-machine-control/rtd-thermocouple-pmc/)
301
+
-[Arduino PLC IDE Setup & Device License Activation](https://docs.arduino.cc/tutorials/portenta-machine-control/plc-ide-setup-license/)
0 commit comments