Power consumption for Machine Learning applications have dropped to the point where they can run off batteries and relatively small solar panels. We show you how to run a simple audio recognition project offgrid using an Arduino PROTM Portenta H7, Edge Impulse, and a Voltaic Systems solar panel and IoT battery pack. All data is sent over LoRaWAN to a publicly available dashboard.

Project Details

  • Collecting a dataset of traffic, background, and siren sounds
  • Using Edge Impulse to train a machine learning model to recognize the sound of sirens
  • Exporting the trained model and incorporating that model into an Arduino program
  • Characterizing the power consumption of the Portenta H7
  • Selecting an appropriate solar panel and battery
  • Sending data to the The Things Network (TTN) and displaying data in a Qubitro dashboard

This is not intended to be a detailed tutorial on machine learning. We’re more interested in the power requirements of a real world machine learning IoT device.

The Qubitro dashboard below shows the number of seconds the Portenta records and identifies a sound as a siren during a 4 minute interval. When testing the device inside with sound files, the model is very accurate.

The device is currently deployed pretty close to the BQE and Brooklyn Bridge in the Dumbo neighborhood of Brooklyn and is recording and processing quite a few sounds. I suspect the accuracy is less than perfect, but probably not too far off. As anyone who has heard the sounds of the BQE can attest, it’s a noisy place and sirens from ambulances, police, and firetrucks are common. But even with all the activity, a firehouse nearby, I suspect that the device is registering some truck horns as sirens.

I do think it is interesting that between 1 am and 9:16 am on May 21, the device did not detect anything similar to a siren as that section of the BQE is relatively quiet during those hours.

Portenta/Qubitro dashboard

 

Parts

Hardware

Software

The Board

Portenta H7 Board Portenta H7 is a dual-core microcontroller board. While the board follows the Arduino MKR form factor, it comes equipped with two 80-pin high-density connectors for additional functionality, like incorporating machine learning.

Portenta H7 Pinout

https://docs.arduino.cc/resources/pinouts/ABX00042-full-pinout.pdf

The board also includes a Murata 1DX module that provides dual WiFi 802.11b/g/n up to 65 Mbps and Bluetooth® connectivity. Portenta Vision Shield

The Portenta Vision Shield is an add-on module that provides two MP34DT05 MEMS digital microphones and a camera to support data capture and analysis. It is designed to complement the Portenta H7 board and is targeted at industrial automation, surveillance, and IoT applications.

Getting Started

To get started with machine learning, you’ll need to follow these steps to setup your board and test your connection :

  1. Connect the Vision Shield with LoRa Connectivity to the Portenta H7 board.
  2. Attach the antenna.
  3. Open the Arduino IDE.
  4. Add the Arduino Mbed OS Portenta Boards.

    Arduino IDE

    Arduino IDE

  5. Connect the board to the computer through a USBC-USBC cable.
  6. Open the File > Examples > MKRWAN > MKRWANFWUpdate_standalone sketch. Upload and open the Serial Monitor and wait for the update to be confirmed.
  7. When the update finishes running, open File > Examples > MKRWAN > FirstConfiguration.
  8. In the code, change the regional band to the appropriate code. I’m in the US, so I’m using US915.
  9. Run the sketch.
  10. Open The Things Network and log into your account.
  11. Create an Application or add this device to an application.
    • To add the device, select Register End Device.
    • For Input Method, select Enter end device specifics manually.
    • Select your Frequency plan.
    • Select the LoRaWAN version. I selected 1.0.3.
    • Navigate to this page: https://descartes.co.uk/CreateEUIKey.html to select a random EUI and use the returned value for the Join EUI field.
    • You’ll find the DevEUI in your FirstConfiguration Arduino program. Copy and paste it into the field.
    • Click Generate to create an AppKey.
    • Click on Register end device.

     

  12. Back in the Arduino program, enter 1 and press return.
  13. Enter the AppEUI and AppKeys when prompted.
  14. If all goes well, try sending uplink and downlink messages between the Portenta H7 and your TTN application with the LoraSendAndReceive sketch from the MKRWAN library.

 


Machine Learning with Arduino Portenta H7

ML with Edge Impulse

  1. You need to start with a collection of sound files. In this case we will use sirens, background,and traffic noise (non-siren sounds) sound files. You can find the collections at kaggle.
  2. Login to my Arduino Cloud account and click on Integrations.Arduino Integrations
  3. Select the Machine Learning Tool Base and click on the Sign in with Arduino button:Arduino Log In Screen
  4. Create an ML account:Edge Impulse Signup
  5. After signing up, return to the cloud, click on integrations and machine learning, and then click on the button:Edge Impulse success screen
  6. Go to your profile and check settings. If necessary, add your password, which will be necessary in a few minutes.
  7. Rename project by clicking on the pencil/edit button:Rename project nameSet new project name
  8. Click on the Add Existing Data button:Renamed Project
  9. Then clicked on Upload data:Upload sound files
  10. Select your siren folder and complete the information. Make sure you add the label:Label sound files
  11. Do the same for your non-siren files:Label sound files
  12. Click on Devices:
  13. Connect the Portenta H7 board to your computer through a USBC – USBC cable.
  14. Download the latest Edge Impulse firmware and unzip the file.
  15. Double press the RESET button on the board to put it in bootloader mode.
  16. Open the flash script for your operating system. In my case, the flash_mac.command. Double-click on it to flash the firmware.
  17. Wait until the flashing is complete and then press the RESET button on the board once to launch the new firmware.
  18. Install edge-impulse-cli. For mac users, this is easier to do on an Intel mac than on a M1. I found that the key to the error command not found was actually to restart my device. Another solution I found on a different computer was to switch to a zsh shell:
    [code] chsh -s /bin/zsh[/code]
  19. Install the Arduino CLI. Here are the instructions. For my installation, I used Homebrew.
  20. If you are on a Mac, open Terminal and type: [code]edge-impulse-daemon[/code]
  21. Provide your credentials and name your device:In terminal add your credentials
  22. Once the daemon finishes, return to the Arduino cloud to see that your device had been added:In terminal name deviceEdge Impulse connected device
  23. Click on Create Impulse. Reduce your window size and click on Add a processing block:Time series screen
  24. Select MFE:Set audio to MFE
  25. Click on Add a learning block:Audio set to MFE
  26. Select Classifier:Classification screen
  27. Click on Save Impulse:Save Impulse Screen
  28. If the final program does not quite classify the sounds correctly, return here and adjust the frequency. You can also adjust the window size to ~100ms:Set window size screen
  29. Click on MFE, adjust your parameters, and save them:Set parameters screen
    Upon revisiting the setup after faulty classification, I lowered my FFT to 256:FFT screen

     

  30. Click on Generate features:Generate Features screen
  31. Click on Classifier:Classifier screen
  32. In the top right, click on the Target button and select your Target device:Target Device popup
  33. Click on Start Training/Save & Train:Start training screen
  34. Click on Model Testing and Classify all:Model Testing screenTest Data Screen
  35. Switch to Deployment and select the Arduino library option:Deployment screen
  36. Click Build:Build button
  37. Open the Arduino IDE and add the zipped file by selecting Sketch>Include library>Add .ZIP library.
  38. Open the Portenta H7 microphone example from the siren-detector library and compile the program. It will take much longer than usual to compile, but only the first time.
  39. Add your LoRa code and connect TTN to a dashboard.

Machine Learning in Action

I added a threshold of .994 to my Arduino code:
[code lang=”arduino”]if (!captureFlag) {
for (uint16_t i = 0; i < EI_CLASSIFIER_LABEL_COUNT; i++) {
ei_printf(" %s: ", ei_classifier_inferencing_categories[i]);
ei_printf("%.5f\r\n", result.classification[i].value);
if (result.classification[1].value > .994) {
sirenCounter++;
ei_printf("counter ");
ei_printf(" %d: ", sirenCounter);
ei_printf(" %s: ", ei_classifier_inferencing_categories[1]);
ei_printf("%.5f\r\n", result.classification[1].value);
}
}
captureFlag = 1;
}[/code]
Once you set your threshold, you can test your model by running the Arduino program and playing some sound files:

Fire Truck Sound file

Fire truck siren US passes test

Ambulance sound file

Ambulance siren passing by passes test

Silence sound file

Silence does not pass test

Urban Park and Traffic sounds

Urban park and traffic does not pass test

Dishwasher sound

Dishwasher does not pass test


Power Consumption of Solar-powered Machine Learning System

Characterize your power consumption with a USB Digital Multimeter:

Based on my readings, my board consumes around 0.106Ah or a little under 13Wh daily.1 minute reading for Wh2 minute reading for Wh [code]15mWh * 30 minutes =.045Wh per hour * 24 =10.8Wh[/code]Amp measurement [code]0.105Ah * 5V= 0.53Wh *24 =12.72Wh per day [/code]

Based on the power consumption, I chose the following battery:


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.