This project demonstrates how to run Edge Impulse trained machine learning models for inference directly on a Raspberry Pi Pico (or other RP2040-based board) using the Arduino framework.
- Standalone Inference: Runs inference directly on the RP2040 without needing a host PC.
- IMU Data Input: Utilizes an LSM6DSOX Inertial Measurement Unit (IMU) to collect accelerometer and gyroscope data.
- Continuous Inference: Processes sensor data in real-time and performs classification continuously.
- Configurable IMU Channels: Supports using 3-axis accelerometer data or 6-axis accelerometer + gyroscope data.
- LED Indicator: Blinks an onboard LED during inference to visualize activity.
- Serial Output: Prints inference results (predictions, timings, anomaly scores) to the serial monitor.
- RP2040-based board: Such as a Raspberry Pi Pico, Pico W, or Adafruit Feather RP2040.
- LSM6DSOX IMU: This sketch is configured to work with IMUs compatible with the
Arduino_LSM6DSOXlibrary. Ensure it's correctly wired to your RP2040 board.
- Arduino IDE: Version 1.8.10 or later.
- RP2040 Board Support Package: Installed in your Arduino IDE.
Arduino_LSM6DSOXLibrary: Install via the Arduino Library Manager (Sketch->Include Library->Manage Libraries...and search for "LSM6DSOX").- Edge Impulse Arduino Library: This is typically included when you export your Edge Impulse project as an Arduino library. The provided
edge-impulse-sdkandcontinuos_mpu_inferencing.hare assumed to be present in the sketch's directory or include path.
- Clone/Download Project: Obtain the project files.
- Install Libraries: Ensure the
Arduino_LSM6DSOXlibrary is installed. - Configure Sketch:
- Open the
edge_impulse_workshop.inofile in the Arduino IDE. - IMU Data: If your IMU only provides accelerometer data, ensure
#define USE_6_IMU_VALUES 0is uncommented. If it provides both accelerometer and gyroscope, uncomment#define USE_6_IMU_VALUES 1. - Inference Mode: The sketch defaults to continuous inference (
#define CONTINUOUS_INFERENCE 1). If you wish to perform inference only once per buffer fill, change this to0. - Edge Impulse SDK: Make sure the
edge-impulse-sdkdirectory (containingclassifier/ei_run_classifier.h,dsp/numpy.hpp, etc.) andcontinuos_mpu_inferencing.hare in the same directory as the.inofile, or are otherwise accessible via the Arduino IDE's include paths. If you exported your project from Edge Impulse as an Arduino library, you would typically include<YourProjectName_inferencing.h>instead of these specific headers and ensure the library is in your Arduino libraries folder. This example uses direct includes for simplicity.
- Open the
- Connect Board: Connect your RP2040 board to your computer via USB.
- Select Board and Port: In the Arduino IDE, go to
Tools->Boardand select your RP2040 board. Then go toTools->Portand select the correct serial port. - Upload Sketch: Click the Upload button in the Arduino IDE.
- Monitor Serial Output: After uploading, open the Serial Monitor in the Arduino IDE (set baud rate to 115200).
- Observe Inference: The board will start collecting IMU data. When the inference buffer is full and a classification is performed, the onboard LED will light up briefly, and the results will be printed to the serial monitor.
The serial monitor will display:
- Timing: DSP, inference, and anomaly detection times in milliseconds.
- Predictions: For classification tasks, it lists each class label and its confidence score.
- Object Detection: If configured for object detection, it will show bounding box information.
- Anomaly Score: If your model includes anomaly detection, it will display the anomaly score.
- The
EI_CLASSIFIER_DSP_INPUT_FRAME_SIZEandCONTINUOUS_INFERENCE_STRIDEare defined within the Edge Impulse SDK or specific header files. Ensure these match your Edge Impulse project configuration. - The
ei_printffunction is a custom implementation for Arduino to route Edge Impulse logging to theSerialobject.