Hi, I want to know if its possible to use external sensors connected to analog input of arduino nano 33 BLE sense for machine learning.
I have collected the data from an external sensor via the analog port in arduino nano 33 BLE sense and the trained a model in edge impluse and build the arduino library.
How can I use the analog sensor data to make the real time prediction similar to the example using build-in sensors?
Thank you for the reply,
I have done the data collection and forwarding to the edge impluse. I have completed the training of the ml model and created the library. I am stuck at how to use the created library for implementing the project.
When i ran the example code that i got in the library the following error is coming as i have provided the data from a0 and a1 for the training but for running the library code i haven’t called a0 and a1.
“ERR: Sensors don’t match the sensors required in the model
Following sensors are required: a0 + a1”
Any suggestion or tutorials available on how to implement the code for the same.
You could do something like the following in your loop function (again did not test). I used the generated Arduino example for the IMU and replaced the IMU data by AnalogRead:
// Allocate a buffer here for the values we'll read from the IMU
float buffer[EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE] = { 0 };
for (size_t ix = 0; ix < EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE; ix += 2) {
// Determine the next tick (and then sleep later)
uint64_t next_tick = micros() + (EI_CLASSIFIER_INTERVAL_MS * 1000);
buffer[ix] = analogRead(A0);
buffer[ix + 1] = analogRead(A1)
delayMicroseconds(next_tick - micros());
}
// Turn the raw buffer in a signal which we can the classify
signal_t signal;
int err = numpy::signal_from_buffer(buffer, EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE, &signal);
if (err != 0) {
ei_printf("Failed to create signal from buffer (%d)\n", err);
return;
}
// Run the classifier
ei_impulse_result_t result = { 0 };
err = run_classifier(&signal, &result, debug_nn);
if (err != EI_IMPULSE_OK) {
ei_printf("ERR: Failed to run classifier (%d)\n", err);
return;
}
// print the predictions
ei_printf("Predictions ");
ei_printf("(DSP: %d ms., Classification: %d ms., Anomaly: %d ms.)",
result.timing.dsp, result.timing.classification, result.timing.anomaly);
ei_printf(": \n");
for (size_t ix = 0; ix < EI_CLASSIFIER_LABEL_COUNT; ix++) {
ei_printf(" %s: %.5f\n", result.classification[ix].label, result.classification[ix].value);
}
#if EI_CLASSIFIER_HAS_ANOMALY == 1
ei_printf(" anomaly score: %.3f\n", result.anomaly);
#endif
}