@@ -127,15 +127,64 @@ You can download the code for the Opta PLC [here]().
127
127
128
128
Let's go through some important code sections to make this application fully operative; starting with the required libraries:
129
129
130
- - ArduinoBLE.h
131
- - Ethernet.h
132
- - ArduinoModbus.h and ArduinoRS485.h
133
- - ArduinoIoTCloud.h
134
- - Arduino_ConnectionHandler.h
130
+ - ` ArduinoBLE.h ` enables the support for Bluetooth® Low Energy (BLE) communication, install it by searching for it on the Library Manager.
131
+ - ` Ethernet.h ` enables the Ethernet support for the Modbus TCP communication.
132
+ - ` ArduinoModbus.h ` and ` ArduinoRS485.h ` manage the Modbus TCP protocol, install them by searching for them on the Library Manager.
133
+ - ` ArduinoIoTCloud.h ` enable the Arduino Cloud integration, install it by searching for it on the Library Manager.
134
+ - ` Arduino_ConnectionHandler.h ` manages the internet connectivity for the board, install it by searching for it on the Library Manager.
135
135
136
136
There is a header included in the project code for the Arduino Cloud configuration:
137
137
138
- - thingProperties.h
138
+ - ` thingProperties.h ` includes the WiFi credentials and Arduino Cloud configuration.
139
+
140
+ ``` arduino
141
+ #include "thingProperties.h"
142
+ #include <ArduinoBLE.h>
143
+
144
+ // For Modbus TCP
145
+ #include <Ethernet.h>
146
+ #include <ArduinoRS485.h> // ArduinoModbus depends on the ArduinoRS485 library
147
+ #include <ArduinoModbus.h>
148
+
149
+ // Ethernet + Modbus objects
150
+ EthernetClient ethClient;
151
+ ModbusTCPClient modbusTCPClient(ethClient);
152
+
153
+ IPAddress server(10, 0, 0, 227); // update with the IP Address of your Modbus server
154
+
155
+ #define DEBUG false
156
+
157
+ // Anomalies thresholds
158
+ #define CURRENT_LIMIT 12 // in Amps
159
+ #define PRESSURE_LIMIT 8 // in Bar
160
+ #define TEMP_LIMIT 85 // in Celsius
161
+
162
+ // Sensor inputs
163
+ #define C_SENSOR A0
164
+ #define T_SENSOR A1
165
+ #define P_SENSOR A2
166
+
167
+ #define GRID_V 120.0 // replace this value with the Grid AC voltage
168
+
169
+ float P_I3 = 0; // variable to store pressure (Bar)
170
+ float T_I2 = 0; // variable to store temperature (C)
171
+ float C_I1 = 0; // variable to store current (A)
172
+
173
+ byte AlertValue = 0; // last alert value received.
174
+
175
+ bool control_once = 1; // flow control variable
176
+
177
+ unsigned long previousMillis = 0; // will store last time readings were done
178
+ const long interval = 1000; // interval at which to repeat readings
179
+ ```
180
+
181
+ In the ` setup() ` function the different board peripherals are initiated including:
182
+
183
+ - Serial communication
184
+ - LEDs and relay outputs
185
+ - ADC configuration
186
+ - Arduino Cloud properties
187
+ ### Nicla Sense ME Code
139
188
140
189
### Arduino Cloud Dashboard
141
190
0 commit comments