How to Integrate Edge Impulse Neural Network on Raspberry Pi Pico

How To Integrate Edge Impulse Neural Network On Raspberry Pi Pico

Raspberry Pi Pico features a powerful RP2040 chip that supports a wide range of use cases. Machine learning is one such use case, as the board comes with a higher clock and SRAM compared to its previously-released competing boards. This tutorial guides you through integrating the neural network trained with Edge Impulse on your Raspberry Pi Pico.

You will need three components to build the use cases explained in this tutorial: Raspberry Pi Pico, Seeed’s Grove Shield for Pi Pico v1.0, and Seeed’s Grove – Light Sensor v1.2 – LS06-S phototransistor. You will also need an Edge Impulse account for deploying purposes.

Setting up the Environment for Raspberry Pi Pico and Edge Impulse

Dimitry has already made a machine learning model for the rock-paper-scissor classifier. The model is publicly available on the Edge Impulse platform; you can visit this link to access the project. Once you open the link, you will be able to see a page similar to the below image. 

Edge Impulse Platform
Edge Impulse Platform

Once you access the project, look for the “Deployment” option on the left navigation bar. Open it to explore the available deployment options. There will be different libraries available for optimizing the source code so that it is compatible with all devices.

The library options available are: 

  • C++ library
  • Arduino library
  • WebAssembly

Out of these, select the C++ library option, as Raspberry Pi Pico does not support the Arduino library. The C++ library does not need external dependencies and can run on any generic C++ compiler. After choosing this option, select the build option at the bottom of the page. After the end of the building process, download the zip folder and extract all the files for deploying on Raspberry Pi Pico.

Download C++ Library
Download C++ Library

Next, you need to clone the GitHub repository for getting started with pico sdk. It is advised to create a separate folder for this project, but you can always work on any folder provided you are well versed with it.

Open the Linux terminal and go to the path of your project folder for cloning the GitHub repository. Execute the following commands.

git clone -b master
cd pico-sdk
git submodule update --init
export PICO_SDK_PATH=[path-to-your-pico-sdk]

Now install the toolchain dependencies by executing the following command in the terminal.

sudo apt-get install gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential

Note: on Ubuntu 18.04, the cmake version installed from apt-get is outdated, so you will need to install the latest one from snap.

Performing Inference on Sample Data

Dimitry has made an example inference template, which is available on this GitHub repository. Visit the GitHub repository to copy the clone command on your clipboard. Now clone this repository from your Linux terminal to create a folder for this standalone inference template. You can also directly execute the below command on your terminal.

git clone

Now you need to copy all the files (except the CMakeLists.text file) from the C++ library folder you downloaded from the Edge Impulse platform in one of the previous steps. You have to make a directory named “build” for the building process and change the path of the terminal to make the build directory the current location of your terminal. You can do this by executing the following command:

mkdir build && cd build

Execute the cmake command to complete the build process. You will get an error If your CMake is not updated to the appropriate version. Install the latest version to solve this error. Execute the following cmake command so that it performs the build process in the upper-level folders. After the completion of the compilation and build process, you will see the Makefile file in the build folder. After the execution of the make command, you will see the “firmware.uf2” file in the build folder.

cmake ..

Connect your Raspberry Pi Pico to your computer/laptop, copy the “firmware.uf2” file to the storage device, and simultaneously press the BOOT button of your Pico board. You can now interface a serial tool to your Raspberry Pi Pico to check if the inference is working properly with the sample data. In this tutorial, Arduino IDE acts as the serial monitor to see the output. So if you observe an output similar to the below image, this means your inference is running perfectly.

Performing Inference on Your Own Data

Working with sample data is just to get started with the main concept of the project. The main objective of the project is to work with different datasets to deploy machine learning models. The GitHub repository of example inference template has another example with the branch name “light_sensor.” This example helps you use your own dataset, as it reads the analog data points from the light sensor connected on pin0 of the Raspberry Pi Pico and performs inference on it. You can compile and build this example by executing the following commands.

git checkout light_sensor
cd build
rm -rf *
cmake ..

Again repeat the same process. Connect your Raspberry Pi Pico to your computer/laptop, copy the “firmware.uf2” file to the storage device, and simultaneously press the BOOT button of your Pico board. The light sensor connected to pin0 will collect data that will be used for the inference. You can check the output on the serial monitor of Arduino IDE. Hence, the continuous data displaying on the screen is the real-time data sensing and inference to predict rock, paper, or scissors using the trained machine learning model. You can also check out the demonstration video made by Dimitry.

The project requires the data collected from the sensors. Hence, there is also a GitHub repository for data forwarding. It can be implemented in the same way as the above two instances. The data forwarder enables the transmission of data to the Edge Impulse platform provided the format of the data is compatible with it. Dimitry has also explained how he created this inference from Pico using the Edge Impulse platform. He has also given more details on how porting is done. Dimitry has also written a summarized article of the project on Hackster.

Using the Edge Impulse platform for integrating neural networks on Raspberry Pi Pico shows us the capacity of the RP20240-based board. You may want to read on for more information about Raspberry Pi Pico.

Saumitra Jagdale Saumitra Jagdale

Saumitra Jagdale is a Backend Developer, Freelance Technical Author, Global AI Ambassador (SwissCognitive), Open-source Contributor in Python projects, Leader of Tensorflow Community India, and Passionate AI/ML Enthusiast. You can find him at open mics performing stand-up comedy and spoken word poetry during weekends.

More Posts