In the midst of launching our crowd supply campaign for nRF52840 based board Blip, we decided to do a project with it which will show some of its capabilities.

Blip is a development board for Bluetooth Low Energy (BLE) and 802.15.4 based wireless applications, based on the Nordic Semiconductor nRF52840 SoC. It has a Black Magic Probe compatible programmer and debugger on-board,  along with temperature/humidity sensor, ambient light sensor, and a 3-axis accelerometer. It is best for prototyping very low power applications.


Vibration Analysis

Vibration Analysis refers to the process of measuring the vibration levels and frequencies of industrial machinery and electronics, and using that information to determine the “health” of the machine, and its components.

Machinery distress very often observed in its vibration or change in vibration pattern. Vibration analysis is, therefore a powerful diagnostic tool for most of the machinery. Hence, accelerometers are used to measure these vibrations. An accelerometer generates a voltage signal proportional to the amount of of vibration, as well as the frequency of vibration.

Since the Blip has an onboard accelerometer sensor which makes it suitable for measuring vibrations produced by industrial machinery or consumer electronics such as microwave, washing machine, refrigerator, etc. It also comes with an onboard SD card module which makes it a handy data logger. So, exploiting all the features of the Blip design we have made a vibration data logger with the Blip. The data hence obtained is processed and analysed using the FFT algorithm to find the underlying frequencies.


The objective of this project is to analyse the vibrations of a running microwave. We use Blip to collect accelerometer data and save it in the built-in SD card. We observe any underlying or inherent frequencies present in its vibrations using the FFT algorithm. We use Python/Jupyter for this purpose.

Here’s the video of the result.

For privacy reasons YouTube needs your permission to be loaded.
I Accept

This project has two parts, developing firmware for Blip using the Zephyr RTOS and writing the Python program on Jupyter notebook for analysing the data using FFT. We then plot the Fourier transform to show the underlying frequencies present in the vibrations produced by the running microwave.

The firmware design and Implementation

First, we will address the firmware part of the problem. We will develop the firmware on Zephyr RTOS. Blip has ST Microelectronics’s LIS2DH12 accelerometer sensor. Our firmware will configure the accelerometer to high-frequency sampling mode to capture the high-frequency vibrations and store the accelerometer values in a CSV file in the SD card.

The firmware design seems straightforward, but configuring the accelerometer sensor to high-frequency sampling mode will require a thorough reading of datasheet and a lot of trial and error. According to our requirement, we want to read each data sample very fast, and at the same time keep storing the data in the SD Card. LIS2DH12 accelerometer sensor contains FIFO 10 bit, 32 levels FIFO to store buffer of data which help us collect samples at a fast rate. So, the plan is to configure LIS2DH12 in FIFO mode, read the data from the buffer and save it to file. The FIFO data format is shown below.

FIFO buffer representation

FIFO can be accessed in more than one mode, which you can choose according to your application requirement. We are going to use FIFO stream mode for our application. In FIFO stream mode, the FIFO continues filling data from the X, Y, and Z accelerometer channels until the buffer is full (a set of 32 samples stored) at which point the FIFO buffer index restarts from the beginning and older data is replaced by the current data. The oldest values continue to be overwritten until a read operation frees the FIFO slots. We will also attach an interrupt to the INT1 pin for the sensor to receive an interrupt when FIFO is full or FIFO has filled up to the threshold set. We can also set a threshold value for the number of data samples, once the FIFO buffer is filled up to the threshold value it will generate an interrupt, this can be used to ensure fast read of the data. Refer to the snippet below which will set the register with the desired configuration.

register configuration values to put the device in FIFO stream mode with interrupt at FIFO full
   The register configuration is likewise
   CTRL_REG1 = 97, the ODR, sampling rate set to 1.344 Khz and enable all axis
   CTRL_REG2 = 08, enabling high pass filter
   CTRL_REG3 = 42, enable interrupt signal on on int pin 1
   CTRL_REG4 = 90, BDU on, 4g, hr off
   CTRL_REG4 = 9f, enabling fifo-stream mode

Refer to the LIS2H12 datasheet to understand the above registers. The CTRL_REG1 register is responsible for setting the sampling rate for the output. We are setting the sampling rate to 1.344 KHz. We are also configuring interrupt and high pass filter. One thing to be noted is to take care of I2C read speed of FIFO buffer should be greater than sampling rate i.e. 0.74 ms (1.344 kHz) otherwise it will result in loss of samples. Setting the configuration is the most crucial part of the problem which will ensure quality data is collected for Vibration Analysis.

Now, since we are able to receive samples at 0.74ms (1.344 kHz) rate we will wait for FIFO to be full and interrupt to generate to start reading and storing data to the CSV file in the SD card.

Firmware Flow

Next task is to design the firmware flow. Blip also has a user button on board which we are going to use to start/stop logging of data. Since we are using Zephyr for our firmware, we will take advantage of its IPC (Inter-Process Communication) mechanisms. We will have two threads, lis2dh12_fifo_read_thread will be responsible for reading the FIFO buffer when an interrupt occurs and setting the DATA_READY_FLAG. The other thread, the main thread will be responsible for logging data to the SD card when EVT_BUTTON_ENABLE_LOG flag and DATA_READY flag are true. We will use a message queue, logging_q to transfer data buffer between these thread processes.

Main Thread

  • wait for message queue(containing data) from FIFO thread.
  • If message queue is received and button flag is true mount the SD card and create the file to store data and write to the file.
  • If button flag is disabled, unmount the SD card and close the file.

LIS2DH12 FIFO read thread

  • The interrupt callback of the sensor will give the semaphore.
  • Wait on semaphore, if received read the FIFO buffer and set the DATA_READY_FLAG.
  • If DATA_READY_FLAG is true, put the message queue.

The code is available in Vibration Analysis folder inside the Blip repository, link is given below code repository section.

Analyzing data using Python and Jupyter

The most common form signal processing is FFT, or the Fast Fourier Transform. FFT is a method of taking a real-time varying signal and splitting it into components each with an amplitude, a phase and a frequency. By associating the frequencies with machine characteristics, and looking at the amplitudes, it is possible to pin point troubles very accurately.

Here we are going to perform FFT on the data collected with the Blip. We will create a Jupyter notebook for this task. We have obtained vibration data from SD card on the Blip, as shown above, now we can perform FFT on the data. The aim of this part would be to create a python script which will read the vibration data from the CSV file and will perform window FFT on each component, X, Y, and Z of acceleration.

FFT calculation will require us you the sampling rate and the window size. So, the sampling rate is twice of sampling frequency set while collecting data i.e. 2 * 1344 (1.344 kHz) and we will keep the window size equal to the sampling frequency. Refer to the FFT formula below N = 1344 and ax is X component of vibration data.

# FFT of ax
fft_x = np.abs(np.fft.rfft(ax))*2.0/N
#freqs = range(len(fft))
freqs_x = np.fft.rfftfreq(len(ax), 1.0/N)

Likewise, we will calculate set for Y and Z and plot it using Matplotlib library. In addition to that we will also generate a moving window plot which will create an effect of animation, this will help us to observe variation minutely across frequencies. The python file is available in the repository.

Moving Window FFT

The vibration data we obtained can be huge (several GBs) and performing Fourier transform of whole data will not be possible. In that case, we can use moving window FFT. We will perform FFT on chunks of data, and plot it each time chunk is updated with the next set of data. This will create an animation plot with a sliding window, which will show the variations in terms of frequency over a period of time.

Refer to the code below to understand how to implement this in the python program. WS is the Window size which is equal to the sampling rate N. We will iterate over WS by increasing the window size by 50. The iteration will stop when the whole data is traversed i.e. (cur_ptr + WS) > NUM_SAMPLES .

# window size of the FFT is N, number of samples
frame_count = 0
cur_ptr = 0

while True:
    if (cur_ptr + WS) > NUM_SAMPLES:
    chunk = az[cur_ptr:cur_ptr+WS]
    cur_ptr = cur_ptr + 50

    fft = np.abs(np.fft.rfft(chunk))*2.0/N
    freqs = np.fft.rfftfreq(len(chunk), 1.0/N)
    # plot FFT

    # update figure canvas
        frame_count += 1
#         print(frame_count)

    except TclError:

        # calculate average frame rate
        frame_rate = frame_count / (time.time() - start_time)

        print('stream stopped')
        print('average frame rate = {:.0f} FPS'.format(frame_rate))

Here are the two graphs we obtained.

Moving window FFT plot(left), real-time signal with its FFT(right)

Analysing the output

The above graph for real-time vibration data and its FFT. We can observe the concentration of frequencies around 200 Hz which tells us something about the vibrations produced by running Microwave. The Microwave oven we used to collect data or most of the microwave ovens in general, often produce certain vibration and sounds when they run, which is what we can observe in our plots.

Practical prospects of using Blip for Vibration Analysis

In this project, we have only used onboard accelerometer and SD card present on the Blip, but the Blip also has temperature/humidity sensor and BLE(Bluetooth low energy) module which makes it a very powerful device to transmit vibration or temperature anomaly in any machinery. We can also create a BLE mesh network with multiple Blip device which can be used in any industrial scenario for the preventive measure as well diagnostics.


I would like to conclude that Blip is a great device which can be used in various application and the Vibration Analysis of machinery is one of the efficient use of the Blip device. This project is only a demonstration of its capability, however, you can enhance accelerometer function even more, to make it a complete product.

Code repository

The code repository for this project is here, it contains the firmware build instructions as well as the Jupyter notebook.


I would like to thank Tavish and all my collegues at Electronut Labs for helping me fix the nuances of acclerometer and helping me complete the project.


LIS2DH12 datasheet

Blip datasheet