Boss lady
Boss lady
DIIDevHeads IoT Integration Server
Created by Enthernet Code on 6/27/2024 in #middleware-and-os
Can i use Edge Impulse to collect data, train a model and deploy it on an Arduino Nano 33 BLE Sense
}

// Assign the features array to the signal data
signal->total_length = EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE;
signal->get_data = [](size_t offset, size_t length, float *out_ptr) -> int {
memcpy(out_ptr, features + offset, length * sizeof(float));
return 0;
};
}

float runInference() {
ei_impulse_result_t result = { 0 };

// Run the Edge Impulse model and get the result
if (ei_run_impulse(&result) != EI_IMPULSE_OK) {
Serial.println("Failed to run Edge Impulse model");
return 0.0;
}

// Return the anomaly score from the result
return result.anomaly;
}

void loop() {
ei::signal_t signal;

// Collect data
collectData(&signal);

// Run anomaly detection
float anomalyScore = runInference();

// Check if the score is above a threshold indicating an anomaly
if (anomalyScore > THRESHOLD) {
// Handle anomaly (e.g., turn on an LED, send a notification)
Serial.println("Anomaly detected!");
digitalWrite(LED_BUILTIN, HIGH); // Turn on the built-in LED
} else {
digitalWrite(LED_BUILTIN, LOW); // Turn off the built-in LED
}

// Small delay to prevent excessive looping
delay(1000);
}
}

// Assign the features array to the signal data
signal->total_length = EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE;
signal->get_data = [](size_t offset, size_t length, float *out_ptr) -> int {
memcpy(out_ptr, features + offset, length * sizeof(float));
return 0;
};
}

float runInference() {
ei_impulse_result_t result = { 0 };

// Run the Edge Impulse model and get the result
if (ei_run_impulse(&result) != EI_IMPULSE_OK) {
Serial.println("Failed to run Edge Impulse model");
return 0.0;
}

// Return the anomaly score from the result
return result.anomaly;
}

void loop() {
ei::signal_t signal;

// Collect data
collectData(&signal);

// Run anomaly detection
float anomalyScore = runInference();

// Check if the score is above a threshold indicating an anomaly
if (anomalyScore > THRESHOLD) {
// Handle anomaly (e.g., turn on an LED, send a notification)
Serial.println("Anomaly detected!");
digitalWrite(LED_BUILTIN, HIGH); // Turn on the built-in LED
} else {
digitalWrite(LED_BUILTIN, LOW); // Turn off the built-in LED
}

// Small delay to prevent excessive looping
delay(1000);
}
15 replies