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.
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
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.
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.
I chose spectral analysis as my processing module because it works well with accelerometer data to extract meaningful features.
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.
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.
- How to Make a PIC Programmer
- Temperature and clock display
- Interface circuit between intelligent temperature sensor TCN75 with two-wire serial interface and 89C51 single-chip microcomputer
- Interface circuit between MMA1220D and microcontroller
- How to make a numeric keyboard using XIAO RP2040
- Improvement of microcontroller-driven piezoelectric buzzer
- Microcomputer motherboard reset part circuit diagram
- 815e motherboard
- usb to 232 circuit
- Computer remote control circuit
- Cypress CYW20719 SoC supports Bluetooth mesh networking, did you know?
- Renesas Synergy™ low-power S1JA microcontroller, did you know?
- Circuit design and structure of universal card reader based on NFC
- Circuit connection diagram between TC35I and microcontroller
- USB communication circuit
- Intelligent hydrological monitoring system module
- Circuit connection diagram between TC35I and microcontroller
- KTY87 temperature sensor microcontroller interface circuit
- RS232 transmission circuit between PC serial port and MC68HC70-5K1 microcontroller
- A little summary of the operating principles of single-chip microcomputer