Why should human have all the fitness trackers? Our pets deserve more to stay active. I am using XIAO BLE Sense which a tiny microcontroller which is equipped with a powerful Nordic nRF52840 MCU, designed in a Bluetooth 5.0 module, built around 32-bit ARM® Cortex™-M4 CPU. It has 6 Axis IMU which is used to predict the activity such as rest, walk and run.
Accompanying mobile app connects to the device over bluetooth and microcontroller sends prediction data every minute. Data is stored on mobile local storage and plotted on graphs to provide meaningful insight.
Before you can start programming with XIAO, you need to install board firmware. The best resource is the wiki which will guide you step by step to set up your Arduino IDE.EI Blue - Data Collection over Bluetooth
For any machine learning project, data collection is a very important part. To capture more accurate data, I had to collect data while my dog is wearing the collar which means I cannot collect data connecting XIAO BLE Sense to computer over USB cable. Hence I created a mobile app called EI Blue using which I collected data wirelessly from XIAO. The app sends accelerometer data directly to Edge Impulse studio.
The app is very easy to use. You need to upload the firmware core to your XIAO, scan the QR code to configure the project on the app and start sampling. Watch the video below.
You can clone my project and build the app on your computer.
You should see data on Edge Impulse Studio as below. I have collected 5s samples. Collect as much data as possible for a robust ML model. I have collected around 6 minutes data to get started and will continue to collect more data over the time.
This is where you define your input data, any digital signal processing and neural network you want to use for your model.
As you know, accelerometer data is basically a time series raw data. I have chosen frequency = 50Hz which means every second there will be 50 readings of accelerometer data with interval of 1000/50=200 milliseconds.
I have chosen Spectral Analysis as my processing block as it works pretty well with accelerometer data to extract meaningful features.
On the Spectral Analysis page, make sure to check "Calculate feature importance" which will indicate which features are important based on your data. For example, as you can see in above image, "accX Spectral Power" has highest importance as I have rest, walk and run data where X axis varies a lot and makes the separation.
I got 90% accuracy during model testing But remember, this is a proof of concept and I collected data from my dog only. Ideally, I am supposed to collect data from different dog breeds and that will add variety in the dataset and make the model robust. But for now, it solves the purpose.
Once you are done, download the Arduino library and add to Arduino IDE. Then upload XIAO_BLE_Pet_Activity.ino program to XIAO BLE Sense.Build The Mobile App for iOS
The mobile app is written in flutter. So you need to have flutter installed. I highly recommend to configure VS Code with flutter which makes it so easy to code in flutter/dart. Follow this link to get started with flutter from installation to writing first flutter app.
Once you have all the softwares installed and configure, clone this repo.
I have built the app for iOS as I don't have any android device in my possession right now. But flutter is a hybrid mobile framework which means, same code should work for Android app as well.
To build for iOS, run below command from the root of the project folder.
This will open Xcode. Sign the app using your provisioning profile and run on your phone.
This project is also published on PCBWay