Testing the Nordic nPM1100 with ECG // Part 2: Software

In the second part of this series with Nordic Semiconductor's nPM1100 Eval Kit, we focus on developing a mobile application.

Edoliver
about 1 year ago Internet of Things

Welcome back to the second installment of our three-part series, which aims to take certain developer kit components — namely the excellent nPM1100 Evaluation Kit — to manage power, an nRF dev kit and some other miscellaneous components, and build a complete IoT device. In this case, we will be creating an electrocardiograph based on a past project, but we will take it as far as we can. In part three, we will be testing several other use cases and coming to a consensus to which kind of usage is better.

The series is divided into:

Part 1 - Hardware for the ECG: Dev kit integration, system architecture, and component development. We will also test it with Nordic Semiconductor's Power Profiler Kit to check on its draw.

Part 2 - Software for the ECG: Mobile app development along with some AI and cloud integration. (You are here.)

Part 3 - Multiple use cases and which is best: We will go ahead and test several other common, mainly IoT use cases, from small solar panels to other gadgets.

This part will focus on developing the application before getting into more usages in part three.

Remembering the settings of the BLE service:

BLE stands for Bluetooth Low Energy. The XIAO nRF52840 was chosen because of the compatibility with the nPM1100 as they work best when combined and it functions as our Bluetooth Low Energy gateway for our mobile application.

Let's review them a little bit before going into the application. All ECG information is sent at a frequency of 100Hz to the device connected to it.

BLE Service:

  • Name: ECG
  • UUID: 0x2a37

BLE Characteristic:

  • UUID: 0x2a37

Properties:

  • Read
  • Notify
  • Properties: Read, Notify
  • Value: 8-bit unsigned int.
  • BLE Characteristic: UUID: 0x2a37 Properties: Read Notify Value: 8-bit unsigned int.
  • BLE Service: Name: ECG UUID: 0x2a37 BLE Characteristic: UUID: 0x2a37 Properties: Read Notify Value: 8-bit unsigned int.

App development

The most important thing about our device is to be able to integrate it with applications or systems based on BLE. In this case, that is a native Android application (which in turn is deployable on iOS).

However, the development of applications based on Java / Kotlin, Swift, Xcode, and Android Studio can be very complicated if you do not have the experience or knowledge of the language, in addition to having to learn both types of development. In this example, however, we will show how make a native Android application from start to finish using the React Native framework developed by Facebook (which is also possible to deploy later on iOS).

NOTE: Since we will be using the bluetooth of a real cell phone, you must have a physical cell phone to be able to follow this tutorial.

Dependencies

In the official React Native documentation comes the complete guide on how to install the entire environment correctly, though we will highlight some details of them later.

ADB

Because it is a framework for Native Android development, we must first install the Android Debug Bridge (ADB), which is a tool that enables us to communicate between the PC and the phone for development purposes.

If the installation was successful, open your CMD and check if you have the CLI installed.

Android Studio

You must install Android Studio since you will use some tools that it provides to connect correctly with the cell phone when developing.

NOTE: Android Studio also provides emulators when you don't need to use cell phone peripherals, such as Bluetooth, NFC, etc.

NodeJS

Now you should install NodeJS, since the framework works on top of JavaScript.

NOTE: I recommend downloading the LTS version in order to avoid compatibility issues between NodeJS and React Native.

Creating a new application

The most recommended thing to start the development of a Native application is to create it from scratch, since this will help avoid compatibility problems with previous developments.

  • Go to the folder where you would like to start your project, open a command console, and enter the following command:
    npx react-native init YOUR_PROJECT_NAME
  • To run the project and see that everything has worked correctly, you must first connect a cell phone in USB debugging mode. Via this URL, you can see how to do this on your cell phone.
  • We open the terminal and place the following command. We will be able to see the devices that we have ready to start developing:
    adb devices
  • With all this configured, we will only have to execute the following command in the project folder to visualize our application running on the cell phone, the debugging console, and the nPM console. (The important ones here are the debugging and the cell phone screen.)

NOTE: Within this repository, I will leave you an application with all the necessary configurations to be able to connect and receive data to the application from our device; however, we will explain step by step how to configure everything from 0.

  • Within the project you will have to configure the AndroidManifest.xml file, since it is in charge of giving the permissions to the application. Therefore, you will have to add the following lines to the file:

File Path: android\app\src\main\AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  • We will need to install the following packages to facilitate development and to access the BLE features of our device.
  • convert-string
  • react-autobind
  • react-native-ble-manager
  • Using BLE services can get tricky without some utilities, so you'll have to add a folder to the project called Utils and put the following module in it to access it.
  • The development of applications in Android is based on event-oriented programming — every time we activate a function, it will generate an event, which we can configure to perform certain actions when they occur. In this case, there are four BLE events that interest us and I will mention them below.

    NOTE: All these functions are already implemented in the following component — BLE Controller.
  • BleManagerDiscoverPeripheral: Update the list of devices detected in scanning.
  • BleManagerStopScan: Detect when Bluetooth device scanning is finished and issue the list of devices to a higher component.
  • BleManagerDidUpdateValueForCharacteristic: Detect when the value of our device is updated.
  • BleManagerDisconnectPeripheral: Detect a disconnection to change device.
  • Finally, if we implement all the functions as they come in the BLE Controller, we can only invoke the component in our main app and place the following props on it.
<BLEcontroller
serviceUUID={'2a37'} // Service UUID
characteristicUUID={'2a37'} // Characteristic UUID
callback={
(data) => {
// This function returns the list of devices found after scanning
}
}
callbackDataNotify={
(data) => {
// This function returns the data from the sensor once it starts to send it.
}
}
/>
  • After configuring all this,you will receive a new data from the sensor every 10ms, since the minimum recommended frequency for ECG devices is 100Hz sampling.
  • In this case, we can save the input data in a state variable and pass it to any component that graphs, send it to the cloud, or any other process that is required in your application.

Demo

This the end of part two, which was primarily focused on what was missing in part one. Next, we will go back heavily into the nPM1100 and test it against several use cases.

______________________

If you're new to Nordic Semiconductor's nPM1100, explore this Getting Started project tutorial that walks you through initial set-up.

For a high level overview, check out Hackster's Spotlight video on all things possible with nPM1100.


Edoliver

Engineer, Scientist, Maker. Entrepreneur and Futurist.

Latest Articles