Skip to content

Commit 5ae5c77

Browse files
committed
Content update (assets)
1 parent 81c75d5 commit 5ae5c77

File tree

7 files changed

+36
-65
lines changed

7 files changed

+36
-65
lines changed
Loading
Loading
37.8 KB
Loading
Loading
739 KB
Loading

content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/content.md

Lines changed: 36 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ The complete example sketch is shown below.
143143
accelerometer connected to an Arduino Nano R4. The data is formatted
144144
for Edge Impulse data collection and training.
145145
146-
@version 1.0 01/12/24
146+
@version 1.0 01/06/25
147147
@author Arduino Product Experience Team
148148
*/
149149
@@ -159,62 +159,23 @@ const float vRef = 3.3; // Reference voltage
159159
160160
// Sampling parameters
161161
const int sampleRate = 100; // 100 Hz
162-
const int windowSize = 200; // 2-second windows
163162
const unsigned long sampleTime = 1000 / sampleRate; // 10ms between samples
164163
165164
// Data collection variables
166165
unsigned long lastSample = 0;
167-
int sampleCount = 0;
168-
bool collecting = false;
169166
170167
void setup() {
171168
Serial.begin(115200);
172169
analogReadResolution(14);
173170
174171
Serial.println("- Motor Vibration Data Collector");
175-
Serial.println("- Send 'start' to begin data collection");
172+
Serial.println("- Streaming continuous data for Edge Impulse");
176173
Serial.println("- Data format: X_accel,Y_accel,Z_accel");
177174
178175
delay(1000);
179176
}
180177
181178
void loop() {
182-
// Check for commands
183-
if (Serial.available()) {
184-
String command = Serial.readString();
185-
command.trim();
186-
187-
if (command == "start" && !collecting) {
188-
startCollection();
189-
} else if (command == "stop" && collecting) {
190-
stopCollection();
191-
}
192-
}
193-
194-
// Collect data if active
195-
if (collecting) {
196-
collectData();
197-
}
198-
}
199-
200-
void startCollection() {
201-
collecting = true;
202-
sampleCount = 0;
203-
lastSample = millis();
204-
205-
Serial.println("- Starting data collection...");
206-
delay(100);
207-
}
208-
209-
void stopCollection() {
210-
collecting = false;
211-
Serial.println();
212-
Serial.print("- Data collection stopped. Samples: ");
213-
Serial.println(sampleCount);
214-
Serial.println("- Send 'start' for another window");
215-
}
216-
217-
void collectData() {
218179
unsigned long currentTime = millis();
219180
220181
if (currentTime - lastSample >= sampleTime) {
@@ -240,12 +201,7 @@ void collectData() {
240201
Serial.print(",");
241202
Serial.println(zAccel, 4);
242203
243-
sampleCount++;
244204
lastSample = currentTime;
245-
246-
if (sampleCount >= windowSize) {
247-
stopCollection();
248-
}
249205
}
250206
}
251207
```
@@ -285,22 +241,21 @@ To ensure accurate vibration analysis and successful machine learning training,
285241
```arduino
286242
// Sampling parameters
287243
const int sampleRate = 100; // 100 Hz
288-
const int windowSize = 200; // 2-second windows
289-
const unsigned long sampleTime = 1000 / sampleRate; // 10ms between samples
244+
const unsigned long sampleTime = 1000 / sampleRate; // 10 ms between samples
290245
```
291246

292247
In this code:
293248

294249
- Sample rate of 100 Hz captures enough frequency response for detecting most motor faults
295-
- Window size of 200 samples creates 2-second data segments that work well with Edge Impulse training
296250
- Sample time calculation automatically determines the precise timing needed between measurements
251+
- The system streams data continuously without requiring manual start/stop commands
297252

298253
### Signal Processing and Conversion
299254

300255
Once we have the raw sensor readings, we need to convert them into useful acceleration values. This conversion process transforms the ADC readings into data we can analyze:
301256

302257
```arduino
303-
void collectData() {
258+
void loop() {
304259
unsigned long currentTime = millis();
305260
306261
if (currentTime - lastSample >= sampleTime) {
@@ -347,12 +302,14 @@ In this code:
347302

348303
After uploading the example sketch to the Nano R4 board, you should see this output in the Arduino IDE's Serial Monitor when data collection is active:
349304

350-
![Example sketch output showing vibration data collection](assets/data-collection-output.png)
305+
![Example sketch output showing vibration data collection](assets/example-sketch-1.png)
351306

352307
### Complete Example Sketch
353308

354309
Download the complete data collection example sketch [here](assets/motor_vibration_collector.zip).
355310

311+
[![ ](assets/download-button.png)](assets/motor-vibration-data-collection.zip)
312+
356313
## Connecting the Vibration Monitor to Edge Impulse
357314

358315
As vibration-based condition monitoring becomes more important for predictive maintenance, connecting our data collection system to Edge Impulse enables the development of intelligent anomaly detection models. Edge Impulse provides a complete platform for embedded machine learning, allowing us to transform raw vibration data into useful insights about motor health.
@@ -372,6 +329,8 @@ The first step involves creating an Edge Impulse account and setting up a new pr
372329
- Choose project type: Personal (free tier with 60 min job limit, 4 GB data limit)
373330
- Choose project setting: Private (recommended for this application)
374331

332+
![Creating a new project on Edge Impulse](assets/new-project.png)
333+
375334
3. **Project Configuration**: Once created, the project will be ready for data collection. Sampling frequency and window settings will be configured later during impulse design.
376335

377336
### Data Collection with Edge Impulse CLI
@@ -395,6 +354,8 @@ Verify the installation with the following command:
395354
edge-impulse-daemon --version
396355
```
397356

357+
![Edge Impulse Daemon version](assets/daemon-version.png)
358+
398359
#### Setting up Data Forwarding
399360

400361
Now that you have the CLI installed, you can set up data forwarding to stream vibration data directly from your Nano R4 board to Edge Impulse.
@@ -407,14 +368,18 @@ edge-impulse-data-forwarder
407368

408369
The tool will guide you through the setup process:
409370

410-
1. Log in with your Edge Impulse credentials when prompted
411-
2. Select your motor anomaly detection project
412-
3. Choose the correct serial port for your Arduino
413-
4. Set baud rate to `115200`
414-
5. Select data format: `CSV`
415-
6. Configure 3 columns for `X`, `Y`, `Z` acceleration data
371+
1. **Login**: Enter your Edge Impulse username/email and password when prompted
372+
2. **Select Device**: Choose the correct serial port for your Arduino (for example, `COM5`)
373+
3. **Data Detection**: The tool will automatically detect the data frequency (100 Hz) and number of sensor axes (3)
374+
4. **Name Axes**: When asked "What do you want to call them?", enter: `X`,`Y`,`Z`
375+
5. **Device Name**: Give your device a name (for example, `nano-r4`)
376+
6. **Project Connection**: If you have multiple projects, the tool will ask which Edge Impulse project you want to connect the device to. Select your motor anomaly detection project.
377+
378+
![Setting up the data forwarder tool](assets/data-forwarder-configuration.png)
379+
380+
Once configured, the forwarder will stream data from your Nano R4 board to Edge Impulse. You can verify the device connection by checking the "Devices" tab in Edge Impulse Studio. You can then start collecting training data for your machine learning model.
416381

417-
Once configured, the forwarder will stream data from your Nano R4 to Edge Impulse when you send the `start` command through the Arduino IDE's Serial Monitor.
382+
![Device connection verification to Edge Impulse Studio](assets/device-verification.png)
418383

419384
#### Data Collection Process
420385

@@ -453,37 +418,43 @@ The spectral analysis block extracts relevant features from the raw vibration si
453418

454419
#### Model Training Process
455420

456-
Follow these steps to train the anomaly detection model using the collected normal operation data:
421+
Follow these steps to train the anomaly detection model using the collected idle and nominal operation data:
457422

458423
1. **Generate Features**: Click "Generate features" to extract spectral features from all training data
459424
2. **Feature Explorer**: Review the feature explorer visualization to verify data quality and feature separation
460425
3. **Anomaly Detection Setup**: Configure K-means clustering with 32 clusters for pattern recognition
461-
4. **Axis Selection**: Use "Select suggested axes" to automatically choose most relevant spectral features
462-
5. **Start Training**: Initiate the training process and monitor convergence metrics
426+
4. **Axis Selection**: Use "Select suggested axes" to automatically choose the most relevant spectral features
427+
5. **Start Training**: Start the training process and monitor convergence metrics
428+
429+
***__Important note__: The feature explorer shows how well your idle and nominal data separate in the feature space. Good separation means the model can clearly distinguish between different operating states. If the data points overlap significantly, you may need to collect more diverse data or adjust your sensor mounting.***
463430

464431
The training process creates clusters representing normal motor operation patterns. Any future data that falls outside these established clusters will be identified as anomalous.
465432

433+
***__Important note__: The 32 clusters create a detailed map of normal operation patterns. Each cluster represents a different "type" of normal vibration signature. When new data doesn't fit well into any existing cluster, it's flagged as an anomaly. More clusters provide finer detail but require more training data.***
434+
466435
#### Model Validation and Testing
467436

468437
After training completion, validate the model performance using the following methods:
469438

470439
- **Live Classification**: Test with new motor data to verify anomaly detection capability
471440
- **Threshold Tuning**: Adjust anomaly threshold (typically 0.3-0.5) based on desired sensitivity
472441
- **Performance Analysis**: Review clustering quality and feature importance rankings
473-
- **False Alarm Testing**: Validate with known normal conditions to minimize false positives
442+
- **False Alarm Testing**: Validate with known normal conditions to reduce false positives
443+
444+
***__Important note__: The anomaly threshold is critical for system performance. A lower threshold (0.2 to 0.3) makes the system more sensitive and catches subtle problems but may trigger false alarms. A higher threshold (0.4 to 0.6) reduces false alarms but might miss early-stage faults. Start with 0.3 and adjust based on your specific application requirements.***
474445

475446
### Model Deployment
476447

477448
After successful training and validation, deploy the model as an Arduino library for embedded inference:
478449

479450
1. **Deployment Section**: Navigate to the "Deployment" tab in Edge Impulse Studio
480451
2. **Arduino Library**: Select "Arduino library" as the deployment target
481-
3. **Optimization Settings**: Choose "int8" quantization for memory efficiency on the Nano R4
482-
4. **Model Analysis**: Review memory usage and inference timing estimates
452+
3. **Optimization Settings**: Choose `int8` quantization for memory efficiency on the Nano R4
453+
4. **Model Analysis**:Review memory usage and inference timing estimates
483454
5. **Download Library**: Download the generated Arduino library ZIP file
484455
6. **Library Installation**: Install in Arduino IDE using "Sketch > Include Library > Add .ZIP Library"
485456

486-
The generated library includes optimized inference code specifically compiled for the Arduino Nano R4's ARM Cortex-M4 processor, ensuring efficient real-time anomaly detection with minimal computational overhead.
457+
The generated library includes optimized inference code specifically compiled for the Nano R4's Arm® Cortex®-M4 processor, ensuring efficient real-time anomaly detection with low computational overhead.
487458

488459
## Improving the Vibration Monitor with Machine Learning
489460

0 commit comments

Comments
 (0)