Your shopping cart is empty!
Edge Impulse with Raspberry Pi Pico Application Using ADC Light Sensor
- Khor Jia Yong
- 08 Jan 2024
- Project
- Intermediate
- 961
Introduction
Given the Edge Impulse's compatibility with devices featuring the Raspberry Pi RP2040 microcontroller chip, this project centers on the application of Edge Impulse with Raspberry Pi Pico. Data collection relies on measuring light intensity through the ADC light sensor. The objective is for Edge Impulse to understand and identify scenarios involving both light and no-light conditions.
Hardware Components
- Raspberry Pi Pico Microcontroller Board
- Light Sensor Module
Software Requirements
- Visual Studio (Make sure Visual Studio including Desktop development with C++ has been installed on your computer)
- Arduino IDE
Project Development
Early setup
- After the installation of the aforementioned software applications, install the CLI tools on the command prompt via the command:
npm install -g edge-impulse-cli --force
- Attach the Raspberry Pi Pico board to your computer using a micro-USB cable, and simultaneously press the BOOTSEL button to activate the USB Mass Storage Mode on the Raspberry Pi Pico. (Refer to the documentation for more detailed information)
- Download and unzip the latest Edge Impulse firmware. Then, drag the firmware file into the USB Mass Storage device.
- On the command prompt, run:
edge-impulse-daemon
Note: If the command runs without any errors, it indicates that you have successfully installed Edge Impulse CLI on your computer. Otherwise, you can refer to this page for troubleshooting assistance.
Hardware setup
- Connect the light sensor module to the Raspberry Pi Pico.
Software setup
In Edge Impulse, there are seven stages to go through:
1. Device
Connect the Raspberry Pi Pico to the computer using a micro-USB cable.
Enable the USB Mass Storage Mode on the Raspberry Pi Pico and drag the Edge Impulse firmware file into the USB Mass Storage device.
Set up the Raspberry Pi Pico device by typing the command “edge-impulse-daemon” or "edge-impulse-daemon --clean" on the command prompt.
After the command on the terminal, complete the details and select the connected port and desired project. Ensure that the command prompt window remains open during the data-collecting process.
When the icon of Raspberry Pi Pico turns from red colour to green colour, this indicates that the Raspberry Pi Pico device is successfully linked to the Edge Impulse.
2. Data Acquisition
The sensor type of ADC sensor is chosen from the list and the sample length can be adjusted on the same page. (Remember to set up the hardware circuit with the light sensor in advance)
Clicking on "Start sampling" records data for measuring light intensity. The data is collected from the hardware circuit through the light sensor, including parameters like "normal" and "no light" in this instance.
By changing the "label" of the data, the data type can be modified.
3. Impulse Design
To visually represent the data, either through a chart or a table, you first need to create and configure the impulse or feature by choosing them from the suggested list. For instance, you have to set up two block models - the processing block and the learning block. Remember to save the created impulse. (Adjust the number based on your needs)
Each created impulse must be accessed and trained independently.
4. Retrain Model
The impulse or model can be retrained again with known parameters through retrain model.
5. Live Classification
In the live classification stage, also called the test data phase, you can measure light intensity using the light sensor to collect and classify test data by clicking "Start sampling". Be sure to label each test data with its expected outcome.
6. Model Testing
By clicking "Classify all," model testing enables the characterisation of test data through graphical charts.
7. Deployment
Regarding deployment, it enables the construction and exportation of your deployment model based on the building project.
Choose the "Raspberry Pi RP2040" as the deployment option.
By clicking the "build" button, the firmware for the deployment model will be downloaded.
Press and hold the BOOTSEL button of the Raspberry Pi Pico to activate the USB Mass Storage Mode. Then, drag the firmware file (*.uf2) from the archive to the newly displayed USB Mass Storage device.
After completing the transfer, launch the command prompt and enter the command:
edge-impulse-run-impulse
The outcome will be displayed in the command prompt, and the reading can be adjusted in real time according to the detected light intensity by the light sensor.
Real-life Implementation
In fact, the data analysed by Edge Impulse can be implemented in a practical way. The real-life implementation allows the application of the machine learning model on the hardware circuit. It specifically addresses the deployment stage within Edge Impulse.
- Choose the Arduino Library model instead of the Raspberry Pi RP2040 as a deployment option and click "build" to download it.
On Arduino IDE,
- Include or import the Arduino Library you downloaded in zip format by following these steps: Sketch > Include Library > Add ZIP Library.
- Confirm that the library is installed correctly.
- Create the necessary source code for your project, incorporating components like OLED and LED for outputs. Upload the code and choose the Raspberry Pi Pico board, ensuring you select the correct port where the board is connected.
- Monitor the output on the hardware circuit and serial monitor.
Source Code