Home > Microcontroller >Microcontroller Production > How to design a pet activity tracker using XIAO BLE Sense

How to design a pet activity tracker using XIAO BLE Sense

Source: InternetPublisher:念念Brown Keywords: Microcontroller Tracker Updated: 2024/12/10

    background

    Our pets deserve more ways to stay active. I am using XIAO BLE Sense, a tiny microcontroller with a powerful Nordic nRF52840 MCU, designed around a 32-bit ARM® Cortex™-M4 CPU with Bluetooth 5.0 module. It has a 6 Axis IMU for predicting activities such as resting, walking, and running. The tinyML model predicts activities based on data from the 3 Axis IMU.

poYBAGJZL8-ALX7aAAFWOe8y5cA322.png

pYYBAGJZL8uAX7L1AAScSKgK-_M343.png

    The accompanying mobile app connects to the device via Bluetooth and the microcontroller sends forecast data every minute. The data is stored on the mobile local storage and plotted on a graph to provide meaningful insights.

    Start building from XIAO

poYBAGJZL8OANAdsAAIEoP9-yEI736.png

    Before you start programming with XIAO, you need to install the board firmware. The best source is the wiki where you can get step-by-step instructions to set up your Arduino IDE.

    EI Blue - Collecting data via Bluetooth

    Data collection is a very important part of any machine learning project. In order to capture more accurate data, I had to collect data while my dog ​​was wearing the collar, which meant I couldn't collect data by connecting the XIAO BLE Sense to a computer via a USB cable. Therefore, I created a mobile app called EI Blue to use it to collect data wirelessly from the XIAO. The app sends the accelerometer data directly to the Edge Impulse studio.

    The app is very easy to use. You need to upload the firmware kernel to your XIAO, scan the QR code to configure the project on the app and start sampling.

    You should see data like the following on Edge Impulse Studio. I collected 5s samples. Collect as much data as possible for a robust ML model. I have collected about 6 minutes of data to get started and will continue to collect more data over time.

poYBAGJZL72APnujAAIxV9cTFPo235.png

    Creativity

    This is where you define your input data, any digital signal processing, and the neural network you want to use for your model.

    As you know, accelerometer data is basically time series raw data. I have chosen frequency = 50Hz, which means there will be 50 accelerometer data readings per second, with an interval of 1000/50=200 milliseconds.

pYYBAGJZL7iAWs4XAAI77B2nn2Q011.png

    I chose spectral analysis as my processing module because it works well with accelerometer data to extract meaningful features.

poYBAGJZL7OAOrKtAAFQTZKG8bo444.png

    On the Spectral Analysis page, make sure "Calculate feature importance" is checked, which will indicate which features are important based on your data. For example, as you can see in the image above, "accX Spectral Power" has the highest importance because I have data for resting, walking, and running where the X-axis varies a lot and is separated.

pYYBAGJZL6-AYdjZAAG-WGrcBGI506.png

    I achieved 90% accuracy during model testing but keep in mind that this is a proof of concept and I only collected data from my dog. Ideally, I should have collected data from different dog breeds which would increase the diversity in the dataset and make the model robust. But for now, it solves the purpose.

    After completion, download the Arduino library and add it to the Arduino IDE. Then upload the XIAO_BLE_Pet_Activity.ino program to the XIAO BLE Sense.

    Building mobile apps for iOS

    The mobile app is written in Flutter. So you need to install Flutter. I highly recommend configuring VS Code with Flutter, which makes it really easy to write code in flutter/dart. Follow this link to get started with Flutter from installation to writing your first Flutter app.

    After all software is installed and configured, clone this repo.

    I have built the app for iOS as I don’t have any Android devices right now. But Flutter is a hybrid mobile framework, which means the same code should work for Android apps as well.

    To build for iOS, run the following command from the root of your project folder.

    open ios/Runner.xcworkspace/

    Xcode will then open and you can sign the app with your provisioning profile and run it on your phone, and you are done.

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号