element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Azure Sphere Starter Kit
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Azure Sphere Starter Kit
  • More
  • Cancel
Azure Sphere Starter Kit
Blog Azure Sphere Medical Measurement Reference Design (Part 1)
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Azure Sphere Starter Kit to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: bwilless
  • Date Created: 7 Jul 2020 5:50 PM Date Created
  • Views 2759 views
  • Likes 4 likes
  • Comments 8 comments
  • iot security
  • avnet azure sphere starter kit
  • azure sphere
  • avnet
  • azure sphere starter kit
  • avnet azure sphere
  • azure sphere example
  • microsoft azure sphere
Related
Recommended

Azure Sphere Medical Measurement Reference Design (Part 1)

bwilless
bwilless
7 Jul 2020

Medical Disclaimer

This example does not provide medical advice or diagnostic data.  It is intended for informational purposes only. It is not a substitute for professional medical diagnostics, measurements, advice, diagnosis or treatment.  If you think you may have a medical emergency, immediately call your doctor or dial 911.

 

Introduction

With COVID-19 dominating the news and our lives, we thought it would be relevant to create an Azure Sphere example application that addressed the Healthcare field.

 

This example demonstrates the following capabilities:

  • Health measurements (the checking of health vital signs)
  • Secure communication, data storage, analytics and AI of this diagnostic data (cloud-based storage and actionable insights)
  • Integration with Smartphone capabilities (local display of measurements and interaction with the user)
  • Calling a Direct Method from IoT Central
  • Using Device Twins to control behavior of the application from IoT Central

 

The example is broken into two different blogs:

  • Part 1: Implement the Heart Rate 4 interface along with the IoT Central application
  • Part 2: Implement sending measured data to the BLE Pmod device where it will be sent to a mobile device

 

image

 

  • Medical Disclaimer
  • Introduction
  • Hardware
    • Soldering Tasks
    • Assemble the Hardware Solution
  • Software
    • Azure Sphere Application
      • Clone the Azure Sphere example repository
      • Decide if you want to use IoT Central
      • Create your IoT Central Application
      • Upload and verify your Azure Sphere Tenant Certificate (Required if using IoT Central)
      • Collect the Azure details our application needs to connect to the IoT Central Application and update the Azure Sphere Application (Required if using IoT Central)
    • Build the Azure Sphere Application
    • Running the Example
      • COVID-19 Precautions:  See CDC guidelines on this topic
    • IoT Central Functionality
      • About (View)
      • Device Twin Control (View)
      • Overview (View)
        • Medical Disclaimer
  • Video Demo
  • Future Improvements
  • Bonus Material

Hardware

I've listed all the hardware you need to replicate this reference design.

 

  • Avnet Azure Sphere Starter KitAvnet Azure Sphere Starter Kit
  • Heart Rate 4 Click Board
  • Avnet BLE-Pmod for Azure Sphere Starter Kit (Not required for Part 1)
  • I2C OLED Display

 

For completeness, I've listed the different Azure Sphere hardware interfaces used by each of the add on boards

  • HR4: I2C interface on ISU2
  • OLED Display: I2C interface on ISU2
  • Avnet BLE board: UART interface on ISU0

 

Soldering Tasks

There are a couple of items that need to be added to the Avnet Starter Kit for this example . . .

 

  • Soldering for beginners (If you're new to the solder iron)
  • The BLE-Pmod will come with a right angle 2x6 pin connector.  You need to solder this connector onto the Pmod footprint with the connector facing the outside edge of the board.
  • The OLED board will need to be connected to the board with either a new 4-pin header, or by soldering the OLED display directly to the board, I recommend using the header.

image

 

Assemble the Hardware Solution

Since we're using the Avnet Azure Sphere Starter Kit, we don't require any wiring.  We just need to plug in the HeartRate2 Click board into Click Socket #1, plug the BLE Pmod into the new 2x6 right angle header (not needed until the second blog), and plug in the OLED if you installed the 4-pin header.

 

image

 

Software

There are three pieces of software required for this example.

  • Azure Sphere Application: Reads the HR4 Click board and sends telemetry data to IoT Central and to the BLE device
  • BLE Application: Interfaces with the Azure Sphere application over one of the UARTs and sends/receives data to/from the mobile application (not needed until blog #2)
  • Mobile Application: Displays telemetry data and interacts with the user (not needed until blog #2)

 

Azure Sphere Application

The Azure Sphere application runs on the MT3620 A7 core, so it's a high level application.  Tasks that we need to complete in this section . . .

  • Clone the GitHub repository
  • Decide if you want to use IoT Central
  • If you want to use IoT Central
    • Create an IoT Central Application from a template
    • Upload and verify your Azure Sphere Tenant Certificate
    • Collect the Azure details our application needs to connect to the IoT Central Application and update the Azure Sphere Application
  • Build the Azure Sphere Application
  • Run the application
  • Migrate our device in IoT Central to the new template

 

Clone the Azure Sphere example repository

  • Open Visual Studio 2019
  • Select the "Clone a repository" option
  • Enter "https://github.com/Avnet/AzureSphereMedicalRefDesign.git" for the Repository location
  • Change the Local path if you want to
  • Click on the "Clone" button

image

 

  • Visual Studio will download the project
  • Select the CMakeList.txt file, right click and select "Generate Cache for HeartRateApp"
    • CMake will generate all the required build scripts

image

 

Decide if you want to use IoT Central

The Azure Sphere Application is written to connect to an IoT Central Application, but that's not a requirement for the example.  By default the application will attempt to connect to Azure IoT Central.

 

  • If you don't want the application to connect to the cloud make the following change in the build_options.h file
    • Comment out line #5

image

To continue without using IoT Central skip down to the section titled "Build the Azure Sphere Application".

 

Create your IoT Central Application

We've created an IoT Central Application Template that can be used to stand-up your own IoT Central application in just a couple of minutes.

 

  • Follow this link to access the template
    • Modify the Application name if you wish
    • Select your Pricing plan
    • Provide the contact information for the Free plan
    • Or provide your Billing information for one of the Standard plans
    • Click on the "Create" button at the bottom of the page

image

  • Your Azure IoT Central Application is generated and opens
  • Make a note or bookmark the IoT Central web page URL

Upload and verify your Azure Sphere Tenant Certificate (Required if using IoT Central)

By default the IoT Central application will use a Device Provisioning Service (DPS) to automatically provision Azure Sphere devices that connect to the application.  We need to create a new enrollment group and provide the Azure Sphere Tenant CA Certificate to the application so that it knows to allow any device from our Azure Sphere Tenant to connect and provision into the application.

  • Open the "Azure Sphere Developer Command Prompt Preview" application
    • Start > Azure Sphere > Azure Sphere Developer Command Prompt Preview
  • Login to your Azure Sphere Tenant
    • azsphere login
  • Download the Azure Sphere Tenant CA Certificate
    • azsphere tenant download-ca-certificate -o <path to store certificate>\<filename>.cer
      • If you receive an error verify that you're saving the file to a directory where you have write privileges

image

  • Go back to the Azure IoT Central Application
  • From the left hand menu navigate to: Administration > Device Connection > "+ Create enrollment group"

 

image

  • The "Create new enrollment group" dialog opens
    • Type in the name for your new enrollment group.
      • I typically name this after the Azure Sphere Tenant that I'm using
    • Select Group type "IoT devices"
    • Select Attestation type "Certificates (X.509)"
  • Select "+ Manage primary" under the Certificates (X.509)" header

image

  • The Primary certificate dialog opens
    • Use the folder button next to "Primary" to browse to and select the certificate file we downloaded from the Azure Sphere Tenant
    • Copy the verification code using the copy button next to the circle with an arrow

image

  • Now go back to the "Azure Sphere Developer Command Prompt Preview" application to generate and download a verification certificate
  • Enter the following command
    • azsphere tenant download-validation-certificate --verificationcode <verification code from IoT Central application> -o  <path to store validation certificate>\<filename>.cer
      • This command sends the validation code to the Azure Sphere Tenant where it will generate a certificate with the validation code embedded into the certificate.

image

  • Upload the verification certificate
    • Back in the Azure IoT Central Application, click on the "Verify" button
    • A file browser window opens, select the validation certificate we just downloaded
    • The certificate is uploaded where it's decrypted using the original CA certificate we uploaded and the verification code is matched against the supplied code
    • The Primary certificate dialog is updated to show the the certificate is "Verified"
    • Click the "Close" button to exit the dialog

image

  • Click the "Save" button at the top of the form

Collect the Azure details our application needs to connect to the IoT Central Application and update the Azure Sphere Application (Required if using IoT Central)

 

We're going to use a tool called "ShowIoTCentralConfig.exe" to pull all the bits we need to populate our app_manifest.json file.  This utility is included in the repo along with the Avnet example code.

  • There are 4 pieces of information we need to provide for our application to connect to our IoT Central application
    • DPS Scope ID (This is case sensitive)
    • DPS Global Endpoint FQDN (This is case sensitive)
    • IoT Hub FQDN(s) (These are case sensitive)
    • Azure Sphere Tenant GUID
  • We can find three of the four easily, however the IoT Hub FQDNs are buried deep in the IoT Central implementation.  Remember that for our Azure Sphere application to be able to talk to any external server, we need to provide the FQDN or IP address in the app_manifest.json file.
  • Open a command line window, or use the Azure Sphere Command Prompt Preview CLI
  • Change directories to your repo/HeartRate_HighLevelApp/Tools/win-x64 directory
  • Run the "ShowIoTCentralConfig.exe" utility
    • The application will run and ask for different pieces of information.  The utility will use this information to identify your specific IoT Central Application across all of Azure and to confirm that you have admin access to the IoT Central Application.
    • Are you using a legacy (2018) IoT Central application (Y/N):
      • > N, Respond N for no and press the enter key
    • Enter the IoT Central App URL (e.g. https://myapp.azureiotcentral.com)
      • > Enter the URL for your IoT Central Application
    • Enter your Azure IoT Central application API Token
      • To generate a API Token go back to your IoT Central Application
      • From the left menu navigate to Administration > API tokens > "+ Generate token"

image

 

      • Give your token any name you want
      • Keep the Role as "Administrator"
      • Click on the "Generate" button

image

      • A token is generated and displayed

image

      • Note that this is the only time you'll be able to see or copy the token!
      • Copy the token
      • Paste the token into the command prompt window in response to the "Enter your Azure IoT Central application API Token" request
      • Enter the ID Scope from the IoT Central App
        • Back in the IoT Central Application from the left menu Administration > Device connection ID scope
        • Copy the ID scope and paste it into your command window

image

      • The utility gathers data we need for the app_manifest.json file and presents it to the user
      • The graphic below shows all my responses in red boxes and the information we need to copy/paste into our app_manifest.json file in yellow boxes

image

  • The last piece of information we need is our Azure Sphere Tenant GUID, enter the command below to get the GUID
    • azsphere tenant show-selected

image

        • Use the information from these two commands and update your app_manifest.json file in your Azure Sphere project
        • My updated app_manifest.json file is shown below
        • The interface will identify any JSON data formatting errors with red squiggly lines

image

Build the Azure Sphere Application

  • From the Visual Studio Pull Down Menus Build > Build All
  • Make sure your device is connected to WiFi
    • azsphere device wifi show-status
    • To add a wifi network to your device
      • azsphere device wifi add -s <new SSID> -p <new SSID password> -t
  • Run the application
    • Select the GDB Debugger (HLCore) Target

image

  • Sideload and run the application by clicking on the "GDB Debugger (HLCore) button:
    • image
  • The application sideloads onto the device and runs
  • The application will connect to the IoT Connect application and be configured into the application
    • If you see a device provisioning error . . .
      • Double check your scope ID and DeviceAuthentication app_manifest.json entries
      • Verify that the CA certificate was correctly uploaded and verified
    • If you see a IOTHUB connection error
      • Verify that you entered the IoT Hub host names in the app_manifest.json file
      • Review Azure Sphere network requirements here.
      • Try using a different WiFi network like the hotspot on your mobile device

image

 

At this point the application is running and is connected to our Azure IoT Central application.  However, we need to associated the device with a device template in IoT Central so that the application knows how to manage the device.

  • Go back to your IoT Central Application
  • From the left menu, navigate to Devices > All devices
  • You'll see an entry in the list that has your device ID listed as the Device name and Device Id
  • Migrate the device into the AvnetMedicalDevice template by selecting  your device, then the ellipses "..." or "Migrate" if you can see that option
    • Select "Migrate" from the fly out menu

image

 

  • Select the AvnetMedicalDevice template
  • Click on the "Migrate" button

image

  • The device is migrated into the new template

image

 

Running the Example

 

COVID-19 Precautions:  See CDC guidelines on this topic

For your safety , Wash hands before and after touching equipment used in this test!  It's recommended that you also sanitize the HR4 sensor and other contact areas prior to use.

 

To run the example you need to start the test and place a finger onto the HR4 sensor . . .

 

  • Start the test by either . . .
    • Pressing button A, (the center button)
    • Running the "Start HR Test" direct method call from IoT Central
      • Devices > <your device> > Overview > "Start HR Test" > Run
    • You know that the test is running when the Red LED on the HR4 click is ON and the OLED displays "Place a finger on sensor"
  • Place a finger on the sensor
    • You may need to play with finger placement to get a good reading
      • The test works better for me when I use one of my smaller fingers
      • Press the finger firmly on the sensor and keep it still
  • The application will detect the finger and transition to the "calibrate" step
  • If the calibration fails, you'll be prompted to reposition your finger
  • If the calibration passes, the application will take 5 - 30 data samples
    • If any one data sample is bad, the test will restart
    • If a stable HR is determined across 5 samples the average of the 5 samples is calculated and displayed (and sent to Azure if configured)
    • If 30 samples are taken and no stable reading is found the median HR value from all the readings is reported
  • The results are displayed on the OLED for 30 seconds
  • The test will either automatically restart or wait for the user to restart the test using the "Auto Restart HR Test" device twin control

 

Note: If you elected to run the non-connected application, I encourage you to go back and setup the IoT Central Application.  IoT is all about collecting data from IoT Things and doing something meaningful with the data in the cloud.  This example is easy to setup.  You'll be able to exercise and learn about some fundamental Cloud to Device (C2D) controls, Device Twins and Direct Methods.  Additionally, as long as you don't add more than two devices it's 100% free!

 

IoT Central Functionality

  • You can access the device dashboards (views) by selecting Devices > All devices > < your device's ID>
  • There are 4 views implemented in the "AvnetMedicalDevice" template
    • About
    • Device Twin Control
    • Overview
    • Command

 

About (View)

This view shows static information about the IoT Device.  All this information is provided by the device when it connects to the IoT Hub.  The {key:value} pairs are sent up as Device Twin "reported" properties

image

 

Device Twin Control (View)

There is only one device twin control in this application, "Auto Restart HR Test."  If this is selected (set to true), then the Azure Sphere application will perform a HR test, display the results for 30 seconds, then start a new test.  If this item is set to false or not selected, then the application will go into an idle state after displaying the test results for 30 seconds.  The user would need to initiate a new test process at that time by either pressing button A or executing the "Start HR Test" command from the cloud.

 

To change the value, select/un-select the box then click on the save link at the top of the form.

image

Overview (View)

Medical Disclaimer

This example does not provide medical advice or diagnostic data.  It is intended for informational purposes only. It is not a substitute for professional medical diagnostics, measurements, advice, diagnosis or treatment.  If you think you may have a medical emergency, immediately call your doctor or dial 911.

 

The Overview view shows the telemetry data from our device.

  • The three boxes at the top show the last reported values
  • The Graph shows the HR and SP02 readings as well as the number of samples used to determine the measured values
  • The Start HR Test will take you to the command view where you can send the Start HR Test direct method to the device

image

 

Video Demo

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Future Improvements

 

We plan on expanding this application in the near future.  Here are some ideas . . .

 

  • Enhance the OLED interactions during testing
  • Add BLE connectivity to a mobile device (planned in blog #2)
  • Add user authenticating from mobile device before transmitting data to IoT Central
  • Add contactless temperature measurements
  • Add a thermal display to capture temperature

Bonus Material

  • Link to the files for my 3D printed Azure Sphere Starter Kit case: Link
  • Sign in to reply

Top Comments

  • bwilless
    bwilless over 5 years ago in reply to skruglewicz +1
    Thanks for the comment Stephen! Let me know if you have any questions, Brian
  • bwilless
    bwilless over 5 years ago in reply to skruglewicz +1
    Both ways will work. GPIO is so simple, I've always just used code similar to the Microsoft examples. The engineer who wrote the Click Board Blog, Jim Flynn, recently retired so it will be difficult to…
  • bwilless
    bwilless over 4 years ago in reply to mhummel +1
    Hi Marty, I apologize that I included the wrong link for the click board, I've corrected the link. The Azure Sphere application will not work without the Heart Rate 4 Board. Looking at the two different…
  • bwilless
    bwilless over 4 years ago in reply to mhummel

    Hi Marty,

     

    I apologize that I included the wrong link for the click board, I've corrected the link.  The Azure Sphere application will not work without the Heart Rate 4 Board. 

     

    Looking at the two different click boards, it looks like they are both using Maxium parts, they both use the I2C interface, and the parts appear to be in the same Maxium family. 

     

    To get the Heart Rate Click board working would require . . . .

     

    • Porting the Mikroe Heart Rate drivers into the project
    • Updating the I2C address to address the new device
    • Reviewing the code that configures the old device and update any registers and register values that are different
    • Reviewing the code that reads the measurement data from the old device and updating any registers and register values that are different

     

    That's not a trivial list of tasks.

     

    I've sent a E14 request to follow you so we can have a private chat.  I may have another option for you.  Please accept my follow request and send me a private message.

     

    Brian

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mhummel
    mhummel over 4 years ago

    Hi bwilless,

     

    First of all, Thank you for the very instructive blog post!

     

    I've run into an issue, however.  I've been scratching my head wondering why my attempt at replicating this project did not work.  This process seems to fall down when I run the example program.  In the output window, I get successful status messages for 1) device authenticating and receiving the tenant CA cert from AS3, 2)  AZURE_SPHERE_PROV_RESULT_OK, and 3) IOT_HUB_CLIENT_CONENCTION_OK.  This is followed by two lines of the Device Twin reporting an HTTP Status of 204.

     

    Once I click on User Button A, the output console keeps reporting "State: DETECT_FINGER" every few seconds.  There is no Red LED flashing on the Heart Rate Click board, and the OLED keeps showing the message "HealthCare Place finger on sensor".  I also checked the Dashboard for my example app in Azure IoT Central.  In the Overview tab, the first three tiles keep spinning, and the larger tile on the bottom just says "Waiting for Data".

     

    I went and purchased the MikroElectronicHerat Rate Click Board from the link that was provided at the beginning of this blog post.  Upon closer inspection, this Click Board is the Heart Rate Click.  It does not look exactly like the Heart Rate 4 Click that is seen in the screenshots you provided with this blog.

     

     

    Heart Rate Click    Heart Rate 4 Click

     

               Heart Rate Click                           Heart Rate 4 Click

     

    Could this difference account for the reason why my example app is not working?  Are the two boards that much different?  Is it easy to make the changes needed to get the Heart Rate Click to work in the same manner as the Click Rate 4 does in your demo?  If not, it appears that I bought the wrong model.  That would be very frustrating, since I followed the link that was provided in your blog to make the purchase!

     

    Please advise on steps I should take next, and correct the link in the beginning of your blog post so others do not make the same mistake. Thank you.

     

    - Marty Hummel (mhummel)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • bwilless
    bwilless over 5 years ago in reply to skruglewicz

    Both ways will work.  GPIO is so simple, I've always just used code similar to the Microsoft examples.  The engineer who wrote the Click Board Blog, Jim Flynn, recently retired so it will be difficult to get support for these libraries until we can find time to dig into them. 

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • skruglewicz
    skruglewicz over 5 years ago in reply to bwilless

    so I don't need to use a click library as prescribed in Using MikroE Click BoardsTm with Microsoft Sphere ?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • bwilless
    bwilless over 5 years ago in reply to skruglewicz

    GPIO is a pretty straight forward HW interface.  I recommend that you review the Microsoft Sample Repo here.

     

    • Download the repo
    • Open the GPIO/GPIO_HighLevelApp example
    • Search for one of the GPIO file descriptors to see how they are used/implemented
    • For writing to a GPIO look at the blinkingLedBpioFd variable
    • For reading a GPIO look at the ledBlinkRateButtonGpioFd variable

     

    It's pretty easy to follow,

     

    Good luck,

     

    Brian

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube