Skip to content

pnaat/edge_impulse_workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

RP2040 Edge Impulse Inference Example

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.

Features

  • 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.

Hardware Requirements

  • 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_LSM6DSOX library. Ensure it's correctly wired to your RP2040 board.

Software Requirements

  • Arduino IDE: Version 1.8.10 or later.
  • RP2040 Board Support Package: Installed in your Arduino IDE.
  • Arduino_LSM6DSOX Library: 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-sdk and continuos_mpu_inferencing.h are assumed to be present in the sketch's directory or include path.

Setup and Upload

  1. Clone/Download Project: Obtain the project files.
  2. Install Libraries: Ensure the Arduino_LSM6DSOX library is installed.
  3. Configure Sketch:
    • Open the edge_impulse_workshop.ino file in the Arduino IDE.
    • IMU Data: If your IMU only provides accelerometer data, ensure #define USE_6_IMU_VALUES 0 is 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 to 0.
    • Edge Impulse SDK: Make sure the edge-impulse-sdk directory (containing classifier/ei_run_classifier.h, dsp/numpy.hpp, etc.) and continuos_mpu_inferencing.h are in the same directory as the .ino file, 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.
  4. Connect Board: Connect your RP2040 board to your computer via USB.
  5. Select Board and Port: In the Arduino IDE, go to Tools -> Board and select your RP2040 board. Then go to Tools -> Port and select the correct serial port.
  6. Upload Sketch: Click the Upload button in the Arduino IDE.

Usage

  1. Monitor Serial Output: After uploading, open the Serial Monitor in the Arduino IDE (set baud rate to 115200).
  2. 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.

Output Format

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.

Notes

  • The EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE and CONTINUOUS_INFERENCE_STRIDE are defined within the Edge Impulse SDK or specific header files. Ensure these match your Edge Impulse project configuration.
  • The ei_printf function is a custom implementation for Arduino to route Edge Impulse logging to the Serial object.

About

Código para teste de modelo embarcado da EdgeImpulse - Versão Arduino

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages