Smart vibration sensor (Arduino)¶
I. Objectives of the tutorial¶
This project’s goal is to create a device that can be placed directly on a vibrating machine, that will learn its vibration patterns, and detect potential anomalies in its behavior.
This device will integrate and use Cartesiam’s NanoEdge AI Library, which will be selected via NanoEdge AI Studio.
The device will be able to:
- register the user’s instructions (learn, detect, reset, etc.)
- detect vibrations
- learn vibration patterns
- alert the user when an anomaly is detected
The required hardware for this project are:
Arduino Nano 33 IoTAn IoT connected IMU sensor in the Nano form factor, featuring a low power ARM Cortex-M0 32-bit SAMD21. You can choose another Arduino board but make sure to select an ARM based board.
Adafruit LIS3DHA very popular low power triple-axis accelerometer. It’s low-cost, but has just about every ‘extra’ you’d want in an accelerometer.
USB FanupHere U120 Silent Dual 120mm USB PC Fan, rotation speed: 1600rpm ± 10%
Post-itA small piece of paper can go a long way! Use it to block your fan.
The required software for this project are:
Arduino IDEVersion used in the tutorial: 1.8.12
GitGit is a free and open source distributed version control system.
NanoEdge AI StudioDownload NanoEdge AI Studio for free by filling out the following form:
III. Making a data logger¶
This section’s goal is to create a data logger that can acquire vibrational data and log it via serial port (USB).
2. Putting the hardware together¶
Here is the hardware setup to reproduce, to connect the development board to the accelerometer via I2C:
3. Data logging¶
i. Getting started with Arduino¶
Create your project.
Download and Import Adafruit LIS3DH library:
ii. Collecting accelerometer data¶
Clone the repository
$ git clone https://github.com/cartesiam/neai_arduino_vibration.git
Connect the Arduino Nano 33 IoT board using the programming USB port and your fan to your computer.
Put the accelerometer on your fan.
Uncomment the line:
Deploy your code. Make sure to choose the correct board and port in the sketch Tools.
Detect COM port, find port number and use the listed port as serial port.
If you are on Linux:
If you need to open a serial / COM port on Linux, check the FAQ (Section II. 9) for instructions.
Open a terminal and use the following command:
$ ls /dev/ttyACM*
Copy the device name given by the command above (in our case
/dev/ttyACM0) and use it in the following command:
$ stty -F /dev/ttyACM0 115200 raw -clocal -echo icrnl
If you are on Windows:
- Open Device Manager > Ports (COM and LPT)
- Copy the serial port used by your electronic board; here we will use
Collect regular signals datasets:
If you are on Linux:
$ cat /dev/ttyACM0 > regular.csv
If you are on Windows:
- Download and install PuTTy.
Use the serial port that you copied from the previous step (here
COM7) and use it in the following command:
plink -serial COM7 -sercfg 115200 > regular.csv
Data logging is in an infinite loop. Stop it when you want. You will need at least 100 lines.
Collect abnormal signals datasets:
- Put a Post-It on the fan’s grid (to partly obstruct it).
- Repeat step 5 for abnormal signals collection, to obtain the abnormal.csv file.
IV. Using NanoEdge AI Studio to find the best library¶
The goal of this section is to use NanoEdge AI Studio to find the static library that is most relevant to our embedded application.
2. Getting started with NanoEdge AI Studio¶
- Click this link and fill the form to receive instructions on how to download NanoEdge AI Studio.
3. NanoEdge AI Studio step-by-step guide¶
i. Creating a new project¶
In the main window, create a new project.
Select microcontroller type: ARM Cortex M0+
Choose the maximum amount of RAM, in kB: here 32kB
Select the sensor type: 3-axis accelerometer
ii. Importing signal files¶
In these two next steps (step 2 and step 3), you will import your two signal files:
- The Regular signals file, corresponding to nominal fan behavior, i.e. data acquired by sensors during normal use, when everything is functioning as expected: regular.csv.
- The Abnormal signals file, corresponding to abnormal fan behavior, i.e. data acquired by sensors during a phase of anomaly: abnormal.csv.
For each .csv file, you will consecutively:
Import the file.
Select the correct delimiter (space) and file path, and then validate import.
Make sure that your file is correctly formatted.
iii. Benchmarking the library¶
In this 4th step, you will start and monitor the library benchmark. NanoEdge AI Studio will search for the best possible library given the signal files provided in steps 2 and 3 (see previous section).
a. Starting the benchmark:¶
Click START to open the signal selection window.
Then, select the number of microprocessor cores from your computer that you wish to use (see below). When you are ready to start the benchmark, click Validate.
b. Monitoring the benchmark:¶
NanoEdge AI Studio uses 3 indicators to translate the performance and relevance of candidate libraries, in the following order of priority:
- Balanced accuracy
You can monitor in real time the performance of the candidate libraries, and the evolution of the 3 performance indicators.
See Studio docs: graphs and performance indicators for more information.
NoteThe benchmark process may take some time.Please be patient; have a break, grab a drink.
Only interrupt the benchmark for testing purposes, and don’t expect good results unless all performance markers are at 90% minimum.
A summary screen will appear as soon as the benchmark is complete. It shows the minimum number of learning iterations needed to obtain optimal performances from the library, when it is embedded in your final hardware application. In this particular example, NanoEdge AI Studio recommended that the learn() should be called 80 times, at the very minimum.
- Never use fewer iterations than the recommended number, but feel free to use more (e.g. 3 to 10 times more).
- This iteration number corresponds to the number of lines to use in your input file, as a bare minimum.
- These iterations must include the whole range of all kinds of nominal behaviors that you want to consider on your machine.
iv. Downloading the NanoEdge AI Emulator¶
In the Studio: Step 5, you have you can download the NanoEdge AI Emulator associated to the library that was selected during the benchmark process (Step 4).
NanoEdge AI Emulator is a command-line tool that emulates the behavior of the associated library. It is a clone of the library (same behavior, performances) that can run locally on Windows or Linux, without being embedded in a microcontroller.
You can download the Emulator and use it via the command line, or via the interface provided in the Studio.
v. [PRO] Compiling and downloading the NanoEdge AI Library¶
In this last step (number 6), the library will be compiled and downloaded, ready to be used in your embedded application.
This is only available in the Full version of NanoEdge AI Studio. In this tutorial, you will be able to use the Emulator, and test the performances of the library “live”. You won’t be able to use the library directly and make a fully autonomous device (Section VI), unless you have the Full version.
Before compiling the library, several compilation flags are available, both checked by default (in our example and the hardware used int this tutorial, keep default settings).
If you ran the selection process several times, make sure that the correct benchmark is selected. Then, when you are ready to download the NanoEdge AI Library, click Compile.
After carefully reading the license contract terms, click Accept and compile. After a short delay, a
.zip file will be downloaded to your computer.
It contains all relevant documentation, the NanoEdge AI Emulator (both Win32 and Unix versions), the NanoEdge AI header file
NanoEdgeAI.h, and a
.json file containing some library details.
Congratulations; you can now use your NanoEdge AI Library and Emulator!
V. Using NanoEdge AI Emulator to test your library¶
With NanoEdge AI Emulator, you can emulate the behavior of your NanoEdge AI Library from the command line, or the interface provided through NanoEdge AI Studio or your development board via serial port and a python script to display the results on the screen.
The Emulator comes with each library created by the Studio (step 5). It has been compiled using the same algorithm. This means that for one library, there is one emulator. Using this tool, you can learn and detect as you would do in your embedded application.
You may learn using the regular signals used in the Studio, or any other dataset you consider as “nominal”. You may detect using the abnormal signals used in the Studio, or any other dataset you consider as “abnormal”.
In this section we explain how to test the library generated via NanoEdge AI Studio using NanoEdge AI Emulator.
2. Testing the library with NanoEdge AI Emulator¶
i. Via the interface provided in NanoEdge AI Studio¶
In the 5th step of the NanoEdge AI Studio step-by-step guide, you can test the library that was selected during the benchmark process (step 4). This step provides an interface to test the main NanoEdge AI Library functions via the NanoEdge AI Emulator.
To emulate the behavior of your NanoEdgeAI Library generated from Studio, using NanoEdge AI Studio interface, please refer the following section: using the Emulator within the Studio.
VI. [PRO] Using your NanoEdge AI Library to build your final product¶
In this section we will compile our static library and use its functions to build the desired features on our device.
Take some time to read the code we provide in the file
3. Playing around with your smart sensor¶
- Connect the fan to your computer, put the accelerometer on your fan.
- Set fan speed controller on the speed you want to learn (“Low”, “Medium” or “High”).
- Now you can easily check that the behavior of the NanoEdge AI Library conforms to your expectations, by switching speed controller position and creating anomalies (e.g. obstruct the grid of the fan and/or lightly tap the fan).