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
+48Lines changed: 48 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,6 +86,54 @@ For the Modbus TCP configuration, on the **resources tab** go to the **Ethernet*
86
86
87
87

88
88
89
+
Now, go to **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.
90
+
91
+
In this case, the following configurations are used.
92
+
93
+
```arduino
94
+
// Enable usage of EtherClass, to set static IP address and other
95
+
#include <PortentaEthernet.h>
96
+
arduino::EthernetClass eth(&m_netInterface);
97
+
98
+
void setup()
99
+
{
100
+
// Configure static IP address
101
+
IPAddress ip(10, 0, 0, 157); // Portenta IP address
102
+
IPAddress dns(10, 0, 0, 1); // gateway IP address
103
+
IPAddress gateway(10, 0, 0, 1); // gateway IP address
104
+
IPAddress subnet(255, 255, 255, 0);
105
+
// If cable is not connected this will block the start of PLC with about 60s of timeout!
106
+
eth.begin(ip, dns, gateway, subnet);
107
+
108
+
}
109
+
```
110
+

111
+
112
+
Now, let's 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**, we give it a name, in this case: `temp_send`, change the variable address to `25000`, and the type to `REAL`.
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.
Finally, let's go to the **main program** in **project** and match the temperature variable with the temperature sensor lectures as follows:
121
+
122
+
```
123
+
temp_send := sysTempProbes[0].temperature;
124
+
```
125
+
126
+

127
+
128
+
To check if everything is okay, click on compile, and if no error is shown, you can upload the code to your Portenta Machine Control.
129
+
130
+

131
+
132
+
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.
133
+
134
+
You should see the temperature value measured by the sensor.
135
+
136
+

0 commit comments