By navigating our site, you agree to allow us to use cookies, in accordance with our Privacy Policy.

Predictive Maintenance Using Machine Learning on Edge Devices

Getting Started with Sensor Featherwing and Portenta H7

Getting Started with Sensor Featherwing and Portenta H7

Predictive maintenance is a type of condition-based monitoring, like temperature, vibration, and humidity,  that uses sensor devices to monitor the condition of assets such as industrial machines. Any machine failure would cause a high loss of production. To prevent it, predictive maintenance can indicate when machines will require maintenance, allowing this to be scheduled and avoiding unplanned failures. Part of this monitoring process is Machine Learning (ML). ML typically requires high-performance processing, but with the technology getting advanced, it’s now possible to run ML algorithms on embedded devices. This article will show you how to get started with predictive maintenance, from reading the sensor data to developing the ML model that will classify a motor state. This project is a proof of concept and was done using a fan motor.

Project Material and Resources

782-ABX00042: Arduino Portenta H7

710-2501000201291: Würth Elektronik Sensor FeatherWing

485-4482: Adafruit male -male jumper wires

485-4472: Adafruit USB Type-C cable

Software and Tools:

  • Visual Studio Code
  • PlatformIO
  • Edge Impulse
  • PC

Project Technology Overview

The Würth Elektronik Sensor Featherwing development board features four sensors: temperature, humidity, acceleration, and absolute pressure sensors. All four sensors are connected over a shared I2C bus. This development kit is fully compatible with the Adafruit Feather ecosystem, but I’ll show you how to get started using an Arduino Pro board in this article.

Sensor Featherwing development board
Figure 1 Sensor Featherwing development board

The Arduino Portenta H7 is a dual-core processor featuring the STM32H747, including a 480MHz Arm® Cortex®-M7 and a 240MHz Arm Cortex M4. This allows it to run machine learning models on the high-processing M7, and the other processor can run low-level operations like reading sensor data or handling network communication (WiFi® and Bluetooth®).

Figure 2 Arduino Portenta H7
Figure 2 Arduino Portenta H7

Edge Impulse

Edge Impulse is a development environment for machine learning on embedded devices. It enables the collection of real world sensor data, develops a ML algorithm, and easily deploys the model on any edge device.

Figure 3 Edge Impulse Machine Learning flowchart
Figure 3 Edge Impulse Machine Learning flowchart

Hardware Setup

Assembling the hardware is straightforward as we’ll only need to connect four pins. We’ll read the sensor data from the FeatherWing through the I2C interface. So, connect the pins as follows:

PortentaFeatherWing
GNDGND
3V33V3
I2C SCLSCL
I2C SDASDA

Software Setup

The software setup consists of two parts: Setting up Visual Studio and PlatformIO extension to program the Portenta. PlatformIO enables quick and easy prototyping on Visual Studio Code for the Arduino platform. The second part is configuring Edge Impulse CLI on your PC to train your model.

Installing Visual Studio Code and PlatformIO:

  1. Download Visual Studio Code and follow the installation steps here
  2. Open VSCode Extension Manager on the left hand
  3. Search for the official PlatformIO IDE extension
  4. Install PlatformIO IDE (Figure 4)
Figure 4 Installing PlatformIO in Visual Studio Code
Figure 4 Installing PlatformIO in Visual Studio Code

Installing the Edge Impulse CLI:

The following steps are for Windows computers:

  1. Install Python 3
  2. Install Node.js v14 or higher. For Windows users, install the Additional Node.js tools (called Tools for Native Modules on newer versions) when prompted.
  3. Install the Arduino CLI
  4. Open a PowerShell command line and run it as an administrator
  5. Install the Edge Impulse CLI using that command: npm install -g edge-impulse-cli –force
    Note: If you get an error using this command. Then, try using this workaround by running this command instead:Set-ExecutionPolicyBypass-ScopeProcess-Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iwr -Uri “https://raw.githubusercontent.com/edgeimpulse/ei-install-scripts/main/install-windows.ps1” -Outfile install.ps1; iex .\install.ps1; del .\install.ps1

Vibration Monitoring

The first part of this project is to program the Portenta H7 to read the G Force data from the Sensor FeatherWing accelerometer and convert this data to acceleration. Würth Elektronik offers a ready-to-go library that will quickly get you started with this. The files are uploaded on Mouser’s Github repo.

  1. Download the repository on your computer
  2. In Visual Studio Code: Click on File -> Open Folder -> from the downloaded repository, choose the folder Read sensor data, and click Open
  3. Click on the Explorer tab on the left-hand side panel. Then you can see the code project. Under src, you’ll find the main.cpp file. (Figure 5)
Figure 5 Importing the code into
Figure 5 Importing the code into
  1. To run the code, click on the PlatformIO icon on the left-hand side panel. Click Build and after it finishes building the project, click on Upload and Monitor. (Figure 6)
Figure 6 Building and running the code
Figure 6 Building and running the code
  1. You should start seeing the sensor readings printing in the terminal.
  2. To change these G Force readings to acceleration, we multiply each data by 80665f (Figure 7)
Figure 7 Converting the G Force into acceleration
Figure 7 Converting the G Force into acceleration

Machine Learning model training

Edge Impulse makes building a ML model very easy. You only need to collect the sensor data and train the model on the Edge Impulse platform. Since Edge Impulse doesn’t support the sensor we’re using, we’ll use the Data Forwarder option to push data to the Edge Impulse project. The Data Forwarder reads the Serial Monitor output and uploads the readings to the associated Edge Impulse project.

  1. Create an account on the Edge Impulse website
  2. Create a new project
  3. On your computer, open a PowerShell window and run the following command:
    edge-impulse-data-forwarder
  4. Enter your Edge Impulse username and password
  5. Choose the correct COM port that your Arduino board is connected to. (On windows, open device manager and then click on COM ports)
  6. Then, choose the project that you’ve created in Step 2
  7. The data forwarder should detect that data is being printed on your Serial port. It’ll ask you to write your variable’s names. Since we’re reading acceleration data, we’ll name it accX, accY, accZ. (Figure 8)
Figure 8 Configuring the Edge Impulse data forwarder
Figure 8 Configuring the Edge Impulse data forwarder

That’s it in the console, and now we’ll move to the edge impulse website to start collecting the data and train the model.

In your project, click on data acquisition on the left-hand side panel. On the right side, the platform should detect that your device is connected through the data forwarder, so you can start collecting the samples. (Figure 9)

Figure 9 Collecting sensor data in Edge Impulse
Figure 9 Collecting sensor data in Edge Impulse

For this project demonstration, I’ll be creating a ML model that classifies three states of a motor:

  • Idle (the motor is off)
  • Normal (the motor is on)
  • Error (when there are any abnormal vibrations)

For each state, I’ve collected 4 min of data. Make sure to label it correctly.

Creating the impulse

Let’s create the impulse, which takes our raw data, uses signal processing to extract features, and then uses a learning block to classify new data. (Figure 10)

  1. Depending on your application, adjust the time series data
  2. For the processing block, choose Spectral Analysis
  3. For the learning block, choose Classification (Keras)
  4. Save the impulse.
Figure 10 Creating the impulse
Figure 10 Creating the impulse

Spectral Features

Using the Spectral features block, we’ll extract our input signal’s frequency and power characteristics. It can be customized depending on your application, so for this article, I applied a high-pass filter to analyze repetitive patterns in the vibrations from our motor. (Figure 11)

Figure 11 Spectral analysis
Figure 11 Spectral analysis

Neural Network Classifer

The neural network classifier takes some input data and outputs a probability score indicating the likelihood that the input data belongs to a particular class. For this project, I’ve set the training cycles to 100. The training output is shown on the right with its accuracy. (Figure 12)

Figure 12 Neural network training and output
Figure 12 Neural network training and output

Export the impulse as an Arduino library and navigate to Visual studio to integrate the Edge Impulse SDK to your project.

Adding the Edge Impulse SDK to your project code

You’ll get .zip folder that contains those files: (Figure 13)

Figure 13 Edge Impulse SDK
Figure 13 Edge Impulse SDK

Move those files to your src folder where you have the main.cpp file. The main.cpp needs to be extended with code to classify the new data that the sensor will read.

I’ll highlight the main functions of that code. You can find the complete code to this tutorial on Mouser’s GitHub repo under the folder SensorFeatherwing_Portenta_predictive_maintenance.

  • void run_inference_background(): This function runs our ML model continuously and takes our sensor readings as input. These get classified inside this function.
  • Void loop(): Inside our loop function, we read the sensor data and store them in the buffer array passed to the run_inference_background().

Build and run the code and start monitoring your motor. Below you can see my ML output classifying the new sensor data in just 4ms. (Figure 14)

Figure 14 Serial Monitor output of classifying new sensor data
Figure 14 Serial Monitor output of classifying new sensor data

Conclusion

This article showed how to get started with building machine learning models on embedded devices. As this article is a proof of concept, this tutorial is your first step into building a real-world predictive maintenance application.

About the Author

Rafik MitryRafik Mitry joined Mouser Electronics in 2019 after finishing his Master’s degree in Electrical Engineering at the Technical University of Munich, where he also worked in research in the field of energy harvesting for three years. As a Technical Marketing Engineer at Mouser, Rafik creates unique technical content that reflects current and future technology trends in the electronics industry. Besides keeping up with the latest in technology trends, Rafik is an avid lover of aviation and tennis.

To know more, click here

Source: Mouser Electronics

Tags

Nitisha Dubey

I am a Journalist with a post graduate degree in Journalism & Mass Communication. I love reading non-fiction books, exploring different destinations and varieties of cuisines. Biographies and historical movies are few favourites.

Related Articles

Upcoming Events