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/06.nicla/boards/nicla-sense-env/tutorials/03.elevator-monitoring-application-note/content.md
+129-1Lines changed: 129 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -124,6 +124,134 @@ The Nicla Vision will use a built-in FOMO model for face detection, with a very
124
124
125
125
### Portenta H7 Code
126
126
127
+
Let's go through some important code sections to make this application fully operational, starting with the required libraries:
128
+
129
+
-`Arduino_NiclaSenseEnv.h` includes the support for the Nicla Sense Env sensor data gathering.
130
+
-`Wire.h` enables the I2C communication for the Nicla Sense Env and Nicla Vision boards.
131
+
-`modulino.h` includes the support for the Modulino Pixels.
132
+
133
+
There is a header included in the project code for the Arduino Cloud configuration:
134
+
135
+
-`thingProperties.h` includes the Wi-Fi® credentials and Arduino Cloud configuration.
136
+
137
+
This header includes other two libraries necessary for the cloud communication which are:
138
+
139
+
-`ArduinoIoTCloud.h` enables Arduino Cloud integration. Search for *ArduinoIoTCloud* in the Library Manager to install it.
140
+
-`Arduino_ConnectionHandler.h` manages the board's internet connectivity. Search for *Arduino_ConnectionHandler* in the Library Manager to install it.
141
+
142
+
```arduino
143
+
// Include necessary libraries for Nicla Sense Env sensors and Arduino Cloud
144
+
#include "Arduino_NiclaSenseEnv.h"
145
+
146
+
// Automatically generated by Arduino Cloud for property synchronization
147
+
#include "thingProperties.h"
148
+
149
+
// Include support for the Modulino Pixels
150
+
#include <Modulino.h>
151
+
152
+
// Include Wire library for I2C communication
153
+
#include <Wire.h>
154
+
155
+
// Set time interval (in milliseconds) for sensor readings (10 seconds)
156
+
static const uint32_t READ_INTERVAL = 10000;
157
+
uint32_t lastReadTime = 0;
158
+
159
+
// Global Parameters
160
+
byte people = 0; // people count variable.
161
+
162
+
// Sensor object for Nicla Sense Env data collection
163
+
NiclaSenseEnv device;
164
+
165
+
// Modulino Pixels object
166
+
ModulinoPixels leds;
167
+
168
+
// The Nicla Vision I2C address
169
+
#define I2C_ADDR 0x35
170
+
```
171
+
In the `setup()` function, a variety of peripherals are initialized, including:
172
+
173
+
- Serial communication
174
+
- I2C connection
175
+
- Arduino Cloud properties
176
+
- Nicla Sense Env communication and sensor objects
177
+
- Modulino Pixels
178
+
179
+
```arduino
180
+
void setup() {
181
+
// Initialize serial communication at 9600 baud rate
182
+
Serial.begin(9600);
183
+
184
+
// Short delay to wait for Serial Monitor to be ready
185
+
delay(1500);
186
+
187
+
Wire.begin();
188
+
189
+
// Initialize Cloud properties and connect to Arduino IoT Cloud
// The ZMOD4410 can take a sample every 3 seconds in IAQ mode and requires 60 warm-up samples,
208
+
// meaning the sensor will take about 3 minutes to fully warm-up before accurate readings can
209
+
// be obtained. In this example, we allow 5 seconds for the sensor to start delivering data.
210
+
211
+
} else {
212
+
Serial.println("- ERROR: Nicla Sense Env device not found!");
213
+
}
214
+
215
+
Modulino.begin();
216
+
leds.begin();
217
+
}
218
+
```
219
+
220
+
In the `loop()` function, the Nicla Sense Env sensores are read every 10 seconds, the people count is requested to the Nicla Vision and the Cloud connection is updated.
221
+
222
+
```arduino
223
+
void loop() {
224
+
225
+
// Get the current time
226
+
uint32_t currentTime = millis();
227
+
228
+
// Read sensors every 10 seconds
229
+
if (currentTime - lastReadTime >= READ_INTERVAL) {
230
+
lastReadTime = currentTime;
231
+
auto temperatureSensor = device.temperatureHumiditySensor();
232
+
auto airQualitySensor = device.indoorAirQualitySensor();
233
+
readSensors(temperatureSensor, airQualitySensor);
234
+
}
235
+
getPeopleCount(); // retrieve the people count from the Nicla Vision
236
+
delay(100);
237
+
// Update Arduino Cloud connection
238
+
ArduinoCloud.update();
239
+
}
240
+
```
241
+
242
+
One of the main functions in the `loop()` is the `readSensors()` one, here we use the Nicla Sense Env API to read the following variables:
243
+
244
+
- Temperature (°C)
245
+
- Relative Humidity (%)
246
+
- CO₂ (ppm)
247
+
- Ethanol (ppm)
248
+
- TVOC (mg/m3)
249
+
- Relative Air Quality (IAQ)
250
+
251
+
We also control the Modulino Pixels color based on the IAQ and update the cloud variables.
252
+
253
+
The `getPeopleCount()` function creates an I2C request asking for the people detected by the Nicla Vision.
254
+
127
255
### Nicla Vision Code
128
256
129
257
### Arduino Cloud Dashboard
@@ -139,7 +267,7 @@ The complete improved example sketch can be downloaded [here]().
139
267
140
268
The Arduino Cloud allows us to create a dashboard with professional real-time Human-Computer Interaction (HCI) elements, as seen in the following animation shows an active outdoor air quality monitor. **The animation has been sped up for illustrative purposes**.
0 commit comments