Skip to content

Commit deb4adf

Browse files
committed
Tutorial finished
1 parent 75f6fc3 commit deb4adf

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed
Loading
Loading
Loading

content/hardware/05.pro-solutions/solutions-and-kits/portenta-machine-control/tutorials/pmc-opta-modbus-tcp/content.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Now, in the upper left corner, click on the **Connect** button and wait for the
156156

157157
![Connecting the board](assets/connected-opta.png)
158158

159-
***The Opta doesn’t need any license activation to be used with the PLC IDE***
159+
***The Opta doesn’t need any license activation to be used with the PLC IDE***
160160

161161
#### Modbus TCP - Client
162162

@@ -216,3 +216,65 @@ Finally, define the Opta™ outputs behavior in function of the temperature read
216216
The same with the LED outputs, LED1, 2, 3 and 4.
217217

218218
![LEDs definitions](assets/led-opta.png)
219+
220+
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.
221+
222+
![Create a local variable](assets/variable-opta.png)
223+
224+
In the code editor, match the local variable with the shared one sent by the Portenta Machine Control.
225+
226+
And once stored locally, design the logic to control the outputs as you want. In this case, four different temperature levels will be set to control each output with the temperature rise respectively. Copy and paste the following script into the **main code** section.
227+
228+
```
229+
temp_local:= temp_reg;
230+
231+
IF temp_local >= 30 THEN
232+
relay_1 := TRUE;
233+
LED1 := TRUE;
234+
ELSE
235+
relay_1 := FALSE;
236+
LED1 := FALSE;
237+
END_IF;
238+
239+
IF temp_local >= 50 THEN
240+
relay_2 := TRUE;
241+
LED2 := TRUE;
242+
ELSE
243+
relay_2 := FALSE;
244+
LED2 := FALSE;
245+
END_IF;
246+
247+
IF temp_local >= 70 THEN
248+
relay_3 := TRUE;
249+
LED3 := TRUE;
250+
ELSE
251+
relay_3 := FALSE;
252+
LED3 := FALSE;
253+
END_IF;
254+
255+
IF temp_local >= 100 THEN
256+
relay_4 := TRUE;
257+
LED4 := TRUE;
258+
ELSE
259+
relay_4 := FALSE;
260+
LED4 := FALSE;
261+
END_IF;
262+
263+
```
264+
![Final code to control the outputs](assets/main-code-opta.png)
265+
266+
With the final code written, compile the project and upload it the the Opta™ micro PLC.
267+
268+
### Final Test
269+
270+
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.
271+
272+
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.
273+
274+
![Testing the project](assets/final.gif)
275+
276+
#### Conclusion
277+
278+
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.
279+
280+
As you can notice, the configuration process is very straightforward and the results were as expected.

0 commit comments

Comments
 (0)