Tremor Health Analytics with nRF5340 DK for DSP Processing!
Tremors are symptoms of certain diseases or disorders. There is difficulty controlling muscle movement which results in continuous shaking. It includes people with Parkinson’s disease (PD), multiple sclerosis (MS), or essential tremor (ET). It is important to observe these tremors as it will indicate the severity of the condition.
In this project page, I will build a wearable device to analyse bodily vibrations or tremor activities in real-time. I will monitor the frequency and amplitude of the vibrations with the DSP support libraries on the nRF5340 Development Kit. By using a vibration sensor, these tiny tremors can be detected.
The data will provide key insights on the progression of the disease over time. For example, the general frequency of the tremors experienced in Parkinson's disease is in the range of 3-8 Hertz, should the frequency deviate, it could indicate that the condition is worsening.
Things used in this project
Software apps and online services
For sensing of vibration, the Kemet VS-BV203 vibration sensor unit will be used. It is an analog sensor which outputs a varying voltage based on the amplitude of the vibration it senses.
Using the ADC on the microcontroller, the data is connected and it goes through a the Fast Fourier Transform algorithm to obtain the fundamental frequency of the signal. Here we understand that the frequency of the vibration is the one we want to analyse for our Tremor Health Analytics.
Here I also soldered the necessary hardware onto a prototype board shield. The OLED display is connected onto the I2C pins and the vibration sensor has a connector to the analog pin.
Setup nRF Connect Desktop Tool
First download and install nRF Connect for Desktop from this page
Choose the latest version for your operating system
This is how the setup looks like
After installing, the program should look like this. Here you can manage the different apps related to the nRF system.
In my case, click "Install" for the Toolchain Manager app first, which is the IDE to program the sample code to test the board.
Later on, install the Power Profiler app too as we will make use of the Power Profiler Kit 2 (PPK2) to do some measurements.
Setup Toolchain and IDE
Open the Toolchain Manager. Here we install the latest SDK which comes with the SEGGER Embedded Studio IDE
After done, read through the instructions "First steps to build" and click on "Open IDE".
Compile the Blinky sample code
We will test the nRF5340 DK board by downloading the Blinky sample code onto the board. These samples are a part of nRF Connect SDK.
To import the sample:
File → Open nRF Connect SDK Project…
Choose "blinky" as the project and "nrf5430dk_nrf5430_cpuapp" as the board.
Build the project hex file
Build → Build zephyr/zephyr.elf (F7)
Connect the board to the PC and connect it to the IDE:
Target → Connect J-Link (Ctrl+T, C)
Download the hex file onto the board:
Target → Download zephyr/zephyr.elf (Ctrl+T, L)
Check that the LED on the top-right of the board blinks
You can play around with the sample to get familiar with the environment.
Modifying examples for our application
To make our own application, we will modify from the example and build up from there. Copy the
blinky project from this location:
You can name the project however you like. For me, I copied
Now we shall modify the project to include some libraries for our application.
These projects use the Zephyr RTOS which has a very powerful build system. It has many configurations which you can add in the
From here, it is important to think through the project needs. In this project, I decided to use the GPIO, ADC and I2C device peripherals. In addition, I will make use of the CMSIS-DSP library (this library requires floating point support also)
With this, I edited my file to be something like this:
Refer to this page is the full list of configuration options:- Zephyr Configuration Options (Nordic Semiconductor)
Go back to Open nRF Connect SDK Project again, this time you will see your project folder.
Choose the board name to be nrf5430dk_nrf5430_cpuapp. Also change the build directory to a shorter path (I put it in the root of the C:/ drive)
You may face compiling issues if the build directory path is too long. That is why we have to shorten it (I simply deleted the folders in-between and the folder is at the root of the C:/ drive)
See this forum thread for information of this bug:- https://devzone.nordicsemi.com/f/nordic-q-a/50935/http-application-update-problem-compiling
After importing the project, you can test if you can compile and download it to the board.
Note: that if you do further modifications to the
prj.conf file, you need to reimport the project again in order to update the dependencies.
Installing the CMSIS-DSP package
As the CMSIS-DSP library is provided by ARM, it is not bundled together in the project by default.
To install it, go to Tools > Package Manager
Right-click and install the CMSIS 5 CMSIS-DSP Support Package.
After installation, it looks something like this
We are now ready to start our application!
Code for GPIO
The board has 4 LEDs which are labeled LED1 to LED4 on the circuit board. However, in the code, they are labeled led0 to led3. Please take note of this difference!
- LED1 = P0.28 (led0)
- LED2 = P0.29 (led1)
- LED3 = P0.30 (led2)
- LED4 = P0.31 (led3)
This is the portion of the code to setup the LED
Code for I2C
An I2C OLED display will be used to display information
Connect the OLED display to the dedicated pins for I2C.
- SDA = D14 (P1.02)
- SCL = D15 (P1.03)
This is the portion of the code to setup the I2C.
Code for Timer
The timer is used to trigger the ADC at regular intervals, this is so that we have a consistent readings for the FFT analysis. Here the code is setup to have a frequency of 512Hz. This is because later on I will use an FFT size of 1024 samples, meaning that it will take 2 seconds to update each result.
To confirm that the timer was working properly, I used the logic analyser from the PPK2 kit. I connected it to the LED pin and here we confirm that the frequency is 512Hz (approx 1.95ms). I will explain more in detail how to set up the PPK2 later on.
Code for CMSIS DSP FFT
Now to code the FFT analysis process... Ensure the CMSIS DSP package is installed.
Code for UART
This portion of the code is responsible for sending the FFT results in the array over to the PC using printk() function.
It is sent each time the FFT has been processed as such in the while-loop.
Final Build Product
Putting it all together, I have my final code uploaded on my Github account.
These are the key components in the final build
I attached the vibration sensor firmly onto the wrist under a rubber band.
And the display updates accordingly with the tremor frequency analysis.
Close up of the OLED display
Plotting the Data
The sensor data can be extracted from the nRF5340 using UART. On the nRF5340, the JLink handles the UART communication between the microcontroller and the PC.
We can receive it using a serial software like TeraTerm or PuTTY. Under Device manager, take note of the JLink CDC UART Port.
Connect to the device in TeraTerm:
- File > Create new connection > Serial > (Choose the COM Port).
The default serial port settings for the nRF5340 SDK samples are as follows:
- Speed: 115200
- Data: 8 bit
- Parity: none
- Stop bits: 1 bit
In TeraTerm, go to the serial port settings settings and set it accordingly
It should look like this.
The data will start flowing in the terminal. You can copy it out from here to analyse.
For me, I decided to use Google Sheets to plot a graph, we can split the comma separated data into 2 columns
- Data > Split text into columns > Separator: Comma.
Created an area chart to visualise the results.
- Insert > Chart > Area Chart
The peak of the graph here is the result of the 5 Hz hand tremors.
Zoom in by changing the data range to the first 50 values. And we confirm the amplitude peak is at 5Hz.
I was unable to get the BLE function up in time for the contest due to the steep learning curve. In the future, the data can be sent over BLE to make a live data analysis dashboard
Setup the Power Profiler Kit 2 (PPK2)
Launch the Power Profiler tool using nRF Connect
Connect the PPK2 device to the PC and click on "Select Device".
Here, you will see the devices available, choose your PPK2 device.
You can choose between Source meter and Ampere meter. It depends how you would like the power to be for the Device Under Test (DUT).
In Ampere meter, the PPK2 will will simply measure the current. The PPK2 will light up Blue. The supply is provided by the DUT itself.
In Source meter, the PPK2 will supply voltage to the DUT and measure current from there. The PPK2 will light up Red.
You have to choose the supply voltage ranging from 0.8V to 5.0V. Be careful not to choose the wrong voltage and damage the DUT.
I will source 3.3V and put some resistance across to measure the current as a test case. This is my selection in the software
I simply connected a resistor and a potentiometer across the supply voltages of the PPK2. (The values chosen are arbitrary)
Click "Start" to begin recording the data. The graph will update as I sweep the potentiometer from the maximum resistance, to the minimum, and back to the maximum. The live current waveform reacts accordingly on the PC.
Here we see the results as the maximum of 2.88mA and minimum of 2.00mA. We can verify this with some calculations (note that the resistors have about 5% tolerance)
As you see, the results tally with our calculations (note that the resistors have about 5% tolerance).
Logic Analyzer with PPK2
You can also use the logic analyser function. In this photo, I was probing P0.29 to find the frequency of LED2.
- Red Wire = Logic 5V
- Black Wire = Logic GND
- Blue Wire = Logic D0
This is the measurement of the square wave (flashing LED) on channel 0.
As mentioned earlier in this post, I set the timer frequency to 512Hz. And on each timer interrupt, the LED is toggled. We see that the time between 2 toggles is approx 1.95ms (512Hz)
Prepare nRF5340 DK for use with PPK2
Refer to the official hardware guide to prepare the nRF5340 DK board to measure current- Preparing the DK (Nordic Semiconductor)
We will have to cut a jumper SB40. It is located beside the header pins with the label "nRF Current Measurement".
Carefully score it with a penknife. Take your time as the area has a tight space constrain! After cutting it shall look like this.
We will use the PPK2 in current source mode, hence connect the PPK2 like this.Only VOUT goes to the board's power supply along with GND.
Measurements with the PPK2
After measurement, this is the result of the current draw.
From the results, the average current draw is 3.83mA. Note that the majority of the current is due to the OLED display. (Unfortunately due to time constraints of the contest, I couldn't measure the microcontroller alone as I had trouble to isolate the power going to each component. It is noted that the microcontroller should be in the 100uA range.)
The current spikes of 4.69mA is seen every time the FFT result is calculated. It is a very short process due to the efficiency of the DSP hardware function in the nRF5430.
These are some guides on optimising current usage for the nRF:
This is a bonus 1-min video to demonstrate the product in action
In conclusion, the nRF5340 is a very powerful tool to do live analysis on signals using its built in DSP capabilities. It is also low-powered which opens up the doors for long-lasting wearable device applications. Especially in the medical and healthcare fields, battery life is important to reduce inconveniences to the patients and caretakers.
Program zst123 / nordic-tremor-health-analytics
Wearable device to analyse bodily vibrations activities in real-time and give health insights of developing tremor — Read More
Latest commit to the master branch on 5-23-2021 - Download as zip
An infocomm and electronics enthusiasts. Love playing with new tech. I'm about to enroll in university for a EE degree! Wish me all the best
This content is provided by our content partner Hackster.io, an Avnet developer community for learning, programming, and building hardware. Visit them online for more great content like this.