Deprecated
In November 2022, we updated this tutorial to use Arduino IDE 2.0.X. As Arduino IDE 1.18 is still popular in the community and many of you have not had the chance yet to test Arduino's newest IDE, this page will be kept but won't be updated with the latest integrations.
Impulses can be deployed as an Arduino library. This packages all of your signal processing blocks, configuration and learning blocks up into a single package. You can include this package in your own sketches to run the impulse locally. In this tutorial, you'll export an impulse, and integrate the impulse in a sketch to classify sensor data.
This tutorial should work on most Arm-based Arduino development boards with at least 64K of RAM, like the Arduino Nano 33 BLE Sense, Arduino Portenta H7 + Vision shield and the Arduino Nicla Vision.
In October 2022, we also added support for ESP32 boards. It has been tested with the ESP-EYE and the ESP32-CAM AI Thinker
Knowledge required
This tutorial assumes that you're familiar with the Arduino IDE, and that you're comfortable building Arduino sketches. If you're unfamiliar with these tools you can build binaries directly for your development board from the Deployment page in the studio.
Make sure you followed one of the following tutorials, and have a trained impulse:
Building a continuous motion recognition system (only for boards with built-in IMU sensor).
Also install the following software:
Make sure to install the right development board under Tools->Boards->Boards Manager
. We officially support the Arduino Nano 33 BLE Sense, Arduino Portenta H7 + Vision shield, Arduino Nicla Vision, Arduino Nicla Sense ME and the Espressif ESP-EYE (ESP32).
Arduino Nano 33 BLE Sense
For the Arduino Nano 33 BLE Sense, install the following board:
Arduino Portenta H7
For the Arduino Portenta H7, make sure to install the Arduino Mbed OS Portenta Boards v2.8.0 and to select the Arduino Portenta H7 (M7 core) board and the Flash Split 2 MB M7 + M4 in SDRAM:
Arduino Nicla boards
For the Arduino Nicla Vision and the Arduino Nicla Sense ME, install the following board:
Espressif ESP32
For the ESP32 boards, we officially support the ESP-EYE. Other boards have been tested such as the ESP32-CAM AI Thinker. To install ESP32 boards, go to Arduino->Preferences and add the following link to the additional boards manager URLs: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
. Then install the ESP32 boards from the board manager menu.
And make sure you can compile sketches for your development board.
Head over to your Edge Impulse project, and go to Deployment. From here you can create the full library which contains the impulse and all external required libraries. Select Arduino library and click Build to create the library. Then download and extract the .zip
file.
Then to add the library and open an example, open the Arduino IDE and:
Choose Sketch > Include Library > Add .ZIP library....
Find the folder (do not go inside the folder), and select Choose.
Then, load an example by going to File > Examples > Your project name - Edge Impulse > static_buffer.
Voila. You now have an example application that loads your impulse.
With the project ready it's time to verify that the application works. Head back to the studio and click on Live classification. Then load a validation sample, and click on a row under 'Detailed result'.
To verify that the local application classifies the same, we need the raw features for this timestamp. To do so click on the 'Copy to clipboard' button next to 'Raw features'. This will copy the raw values from this validation file, before any signal processing or inferencing happened.
In the sketch paste the raw features inside the static const float features[]
definition, for example:
Then, select the port that your board is connected to in the Arduino IDE menu: Tools > Port > your Arduino board.
Then click Upload in the Arduino IDE to build and flash the application.
To see the output of the impulse, open the serial monitor from the Arduino IDE via Tools > Serial monitor, and selecting baud rate 115,200.
This will run the signal processing pipeline, and then classify the output:
Which matches the values we just saw in the studio. You now have your impulse running on your Arduino development board!
A demonstration on how to plug sensor values into the classifier can be found here: Data forwarder - classifying data (Arduino).
Exported libraries are automatically versioned, but it's possible that the Arduino IDE gets confused on which version to use leading to an error like: Multiple libraries were found for ...
. You can delete old versions of the libraries to mitigate this. The libraries are located at:
Windows: My Documents > Arduino > libraries
macOS: ~/Documents/Arduino/libraries/
Linux: ~/sketchbook/libraries
This error shows up on the Arduino Nano 33 BLE Sense when using the Arduino Core v1.1.6 for the target. We've filed a bug with Arduino (here) but until that is resolved you can revert the Arduino core version back to v1.1.4 to compile your sketch.
Some users have indicated that this issue can be solved by reinstalling the Arduino IDE.
If you're compiling on a SAMD21-based target, you'll see the above error. This is a known bug in the Arduino core for the SAMD21. If you apply the following patch the issue will go away.
This error can be seen while compiling for a SAMD21-based target. You will need to add the standard library in your sketch:
If the predictions are not properly printed, e.g.:
Then your printing library does not support printing floating point numbers (this happens for example on the Arduino MKR WAN 1300). You can get around this by converting the predictions to integers. E.g.:
Where possible the signal processing code utilizes the vector extensions on your platform, but these are not enabled on all platforms. If these are not enabled we fall back to a software implementation which is slower. We don't enable these on all platforms because the wide variety of platform and core versions Arduino supports, but you can see enable them for your platform by adding the following code on the first line of your sketch, before any includes (only works on Arm cores):
If this still does not work you need to edit the src/edge-impulse-sdk/dsp/config.hpp
file in the library and add, before #ifndef EIDSP_USE_CMSIS_DSP
:
If you have a target that ships on old versions of CMSIS Core (like the SAMD21 targets) you might need to also declare some new macros, e.g.:
This error is usually thrown when the list of object files to compile exceeds Windows max number of characters (32k) in a command line.
Note: This issue is reportedly fixed in Arduino CLI v0.14 and in the Arduino IDE 1.8.15 and above.
If updating your Arduino IDE does not work you can overcome this issue by downloading the platform.local.txt below for your target:
mbed platform.local.txt. Copy this file under the Arduino mbed directory, i.e: C:\Users\MYUSER\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.1.4\
or C:\Users\MYUSER\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\2.1.0\
SAMD21 platform.local.txt. Copy this file under the Arduino SAMD directory, i.e: C:\Users\MYUSER\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.9\
SAMD51 (Adafruit) platform.local.txt. Copy this file under the Arduino Adafruit SAMD directory, i.e: C:\Users\MYUSER\AppData\Local\Arduino15\packages\adafruit\hardware\samd\1.6.3\
ESP32 platform.local.txt. Copy this file under the Arduino ESP32 directory, i.e: C:\Users\MYUSER\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\
STM32 platform.local.txt. Copy this file under the Arduino STM32 directory, i.e: C:\Users\MYUSER\AppData\Local\Arduino15\packages\esp32\hardware\stm32\1.9.0\
Make sure the vision shield is present.
You need to put the board in its bootloader mode. Double press and the RESET button before flashing the board.
Impulses can be deployed as an Arduino library. This packages all of your signal processing blocks, configuration and learning blocks up into a single package. You can include this package in your own sketches to run the impulse locally. In this tutorial, you'll export an impulse, and integrate the impulse in a sketch to classify sensor data.
This tutorial should work on most Arm-based Arduino development boards with at least 64K of RAM, like the Arduino Nano 33 BLE Sense, Arduino Portenta H7 + Vision shield and the Arduino Nicla Vision.
In October 2022, we also added support for ESP32 boards. It has been tested with the ESP-EYE and the ESP32-CAM AI Thinker.
Navigate further down this page, on the Board Manager section to see how to setup Edge Impulse-compatible boards.
Knowledge required
This tutorial assumes that you're familiar with the Arduino IDE, and that you're comfortable building Arduino sketches. If you're unfamiliar with these tools you can build binaries directly for your development board from the Deployment page in the studio.
Make sure you followed one of the following tutorials, and have a trained impulse:
Building a continuous motion recognition system (only for boards with built-in IMU sensor).
Also, install the following software:
Head over to your Edge Impulse project, and go to Deployment.
From here you can create the full library which contains the impulse and all external required libraries. Select Arduino library and click Build to create the library. This will download the arduino-compatible .zip
file:
Before starting to write code with your custom logic, make sure your impulse runs as expected on your board. This will ensure that you can compile the generated Arduino library containing your impulse and that the inference results are correct.
To do so, add the library and open an example, open the Arduino IDE and:
Choose Sketch > Include Library > Add .ZIP library....
Select the ZIP file, and then click the Choose button.
Then, load an example by going to File > Examples > Your project name - Edge Impulse > static_buffer > static_buffer.
In some configurations, it can be needed to restart Arduino IDE to see the examples.
Voila. You now have an example application that loads your impulse.
With the project ready it's time to verify that the application works. Head back to the studio and click on Live classification. Then load a validation sample, and click on a row under 'Detailed result'.
To verify that the local application classifies the same, we need the raw features for this timestamp. To do so click on the 'Copy to clipboard' button next to 'Raw features'. This will copy the raw values from this validation file, before any signal processing or inferencing happened.
In the sketch paste the raw features inside the static const float features[]
definition, for example:
For example:
Then, select the port that your board is connected to in the Arduino IDE menu: Tools > Port > your Arduino board.
Then click Upload in the Arduino IDE to build and flash the application.
To see the output of the impulse, open the serial monitor from the Arduino IDE via Tools > Serial monitor, and selecting baud rate 115,200.
This will run the signal processing pipeline, and then classify the output:
Which matches the values we just saw in the studio. You now have your impulse running on your Arduino development board!
A demonstration on how to plug sensor values into the classifier can be found here: Data forwarder - classifying data (Arduino).
We also provide examples for all the officially supported targets that include sampling the raw features from the onboard sensors.
To use them, make sure to install the right development board under Tools->Boards->Boards Manager
. We officially support:
the Arduino Nicla Vision,
Arduino Nano 33 BLE Sense
For the Arduino Nano 33 BLE Sense, install the following board:
Arduino Portenta H7
For the Arduino Portenta H7, make sure to install the Arduino Mbed OS Portenta Boards v2.8.0 and to select the Arduino Portenta H7 (M7 core) board and the Flash Split 2 MB M7 + M4 in SDRAM:
Arduino Nicla boards
For the Arduino Nicla Vision and the Arduino Nicla Sense ME, install the following board:
Espressif ESP32
For the ESP32 boards, we officially support the ESP-EYE. Other boards have been tested such as the ESP32-CAM AI Thinker. To install ESP32 boards, go to Arduino->Preferences and add the following link to the additional boards manager URLs: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
. Then install the ESP32 boards from the board manager menu.
Make sure to enable PSRAM if you need to run image-based models (image classification or FOMO).
The following settings should work with the ESP-EYE and the ESP32-CAM AI-Thinker:
Board Selection: ESP32 Dev Module
PSRAM: Enabled
Upload Speed: 115200
By default, the esp32-camera sketch is configured to work with the ESP-EYE. To change the camera model replace:
by
You can find other camera model pin definitions here.
Exported libraries are automatically versioned, but it's possible that the Arduino IDE gets confused on which version to use leading to an error like: Multiple libraries were found for ...
. You can delete old versions of the libraries to mitigate this. The libraries are located at:
Windows: My Documents > Arduino > libraries
macOS: ~/Documents/Arduino/libraries/
Linux: ~/sketchbook/libraries
Some users have indicated that this issue can be solved by reinstalling the Arduino IDE.
If you're compiling on a SAMD21-based target, you'll see the above error. This is a known bug in the Arduino core for the SAMD21. If you apply the following patch the issue will go away.
This error can be seen while compiling for a SAMD21-based target. You will need to add the standard library in your sketch:
If the predictions are not properly printed, e.g.:
Then your printing library does not support printing floating point numbers (this happens for example on the Arduino MKR WAN 1300). You can get around this by converting the predictions to integers. E.g.:
Where possible the signal processing code utilizes the vector extensions on your platform, but these are not enabled on all platforms. If these are not enabled we fall back to a software implementation which is slower. We don't enable these on all platforms because the wide variety of platform and core versions Arduino supports, but you can see enable them for your platform by adding the following code on the first line of your sketch, before any includes (only works on Arm cores):
If this still does not work you need to edit the src/edge-impulse-sdk/dsp/config.hpp
file in the library and add, before #ifndef EIDSP_USE_CMSIS_DSP
:
If you have a target that ships on old versions of CMSIS Core (like the SAMD21 targets) you might need to also declare some new macros, e.g.:
This error is usually thrown when the list of object files to compile exceeds Windows max number of characters (32k) in a command line.
Note: This issue is reportedly fixed in Arduino CLI v0.14 and in the Arduino IDE 1.8.15 and above.
If updating your Arduino IDE does not work you can overcome this issue by downloading the platform.local.txt below for your target:
mbed platform.local.txt. Copy this file under the Arduino mbed directory, i.e: C:\Users\MYUSER\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.1.4\
or C:\Users\MYUSER\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\2.1.0\
SAMD21 platform.local.txt. Copy this file under the Arduino SAMD directory, i.e: C:\Users\MYUSER\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.9\
SAMD51 (Adafruit) platform.local.txt. Copy this file under the Arduino Adafruit SAMD directory, i.e: C:\Users\MYUSER\AppData\Local\Arduino15\packages\adafruit\hardware\samd\1.6.3\
ESP32 platform.local.txt. Copy this file under the Arduino ESP32 directory, i.e: C:\Users\MYUSER\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\
STM32 platform.local.txt. Copy this file under the Arduino STM32 directory, i.e: C:\Users\MYUSER\AppData\Local\Arduino15\packages\esp32\hardware\stm32\1.9.0\
Make sure the vision shield is present.
You need to put the board in its bootloader mode. Double-press and the RESET button before flashing the board.
It means that the axis names are different than the ones provided in the default example. To fix it, you can modify the eiSensors nicla_sensors[]
(near line 70) in the sketch example to add your custom names. e.g.: