Introduction

 

In this blog, I'll demonstrate how to turn your Avnet Azure Sphere Starter Kit into a Power Monitor with data logging capabilities.  We'll use a Starter Kit and a MikroE Power Meter Click board.

 

Required Hardware

To complete this exercise you'll need the following hardware . . .

  • 1 Avnet  Azure  Sphere Starter Kit
  • 1 MikroE Power Meter Click  Board
  • Something to measure
    • The  Power Meter Click requires positive and negative voltage, plus the load side voltage connection.  I'll be measuring a second Avnet Azure Sphere Starter Kit powered by an external power source.

 

Table of Contents

 

Hardware Configuration

Since we're using the Avnet Azure Sphere Starter Kit, putting the hardware together for the Power Monitor is as easy as plugging your MIKROE-3169 PWR METER CLICK into your Starter Kit.  The software application expects the board to be in Click Socket #2.

 

The specifics for  Click Socket #2

  • The UART TX and RX are connected to the MT3620 ISU0
  • The Enable (EN) signal on the Click Board is connected to the MT3620 GPIO35

 

Note: If you wanted to relocate this board to Click Socket #1, you would need to use GPIO34 instead of GPIO35 for the EN signalISU0 is common between both Click Sockets.  See the pinout tables below.  The signals used by our click board are identified with red boxes.

 

 

Test Configuration

Since a power meter /  data logger is not very useful without something to measure, I've created a test configuration to measure the voltage and current drawn by another Avnet Azure Sphere Starter Kit.

 

You can use the table and diagram below to reproduce my test configuration.   Note that you could substitute just about any equipment for your device under test (DUT) as long as you provide the correct supply voltage and don't exceed the voltage limitations of the PWR METER click board.  The PWR METER click board has a limit of 60V (AC or DC), so don't exceed 60V on your specific test configuration.  If you need to measure line voltages (120V AC), I'll provide some details at the end of the blog to show how you can use the same Azure Sphere Application with a different MCP39F511 test device.

 

SignalFromTo
+5VPower Supply+5V rail on breadboard
+5V+5V rail on  breadboardV+ terminal on PWR METER click board
GroundPower SupplyGround rail on breadboard
GroundGround rail on breadboardV- terminal on PWR METER click board
GroundGround rail on breadboard5V- terminal on DUT Starter Kit
+5V LoadL on PWR METER click board5V+ terminal on DUT Starter Kit

 

Clone the GitHub Project

I've created an example Azure Sphere application that reads the voltage and current from the PWR METER click board.  You can clone my project from https://github.com/Avnet/AzureSpherePowerMeter.git

 

Application Information

Just a little background on this application.  With this exercise I also wanted to demonstrate how you can start with an existing Azure Sphere example application and modify it for your specific application.  So that's exactly what I did.  I'm not going to review the code changes, but when I developed the application, I executed git commits at different key development milestones.  If you're interested in seeing these changes you can just look at the history of the master branch.  The bullets below describe each commit and provide links to view the specific changes on github.com.

 

  • Starting Point: Start with the Microsoft UART_HiguLevelApp example: Link
  • Commit #2: Change the target hardware to the Avnet Starter Kit and add logic to read the MCP39F511 power data over the UART: Link
  • Commit #3: Add timer to automatically poll the power monitor device 4 times/second: Link
  • Commit #4: Modify the button handler to toggle between human friendly output and CSV formatted data: Link
  • Commit #5: Added commented out code to use with an alternative MCP39F511 device:  Link

 

Application Features

This application is pretty basic.  It will request and receive Voltage and Current reading every 250 ms then output the formatted data to the Visual Studio debug window.  If you press the A button, the output will toggle between human friendly output and CSV formatted data.  This application does not include any Azure connectivity logic.   See an example debug capture below:

 

Remote debugging from host 192.168.35.1, port 62844

UART application starting.

Opening GPIO 35 as output.

Opening BUTTON_A as input.

voltage 5.130 V, current 0.019 mA

voltage 5.130 V, current 0.017 mA

voltage 5.130 V, current 0.019 mA

voltage 5.130 V, current 0.017 mA

voltage 5.130 V, current 0.017 mA

voltage 5.130 V, current 0.019 mA

voltage 5.130 V, current 0.019 mA

voltage 5.130 V, current 0.019 mA

voltage 5.130 V, current 0.019 mA

voltage 5.130 V, current 0.021 mA

voltage 5.130 V, current 0.021 mA

voltage 5.130 V, current 0.019 mA

voltage 5.130 V, current 0.021 mA

voltage 5.130 V, current 0.021 mA

voltage 5.130 V, current 0.019 mA

voltage 5.130 V, current 0.021 mA

<BW PRESS Button A here>

voltage, current

5.130, 0.012

5.130, 0.012

5.130, 0.012

5.130, 0.012

5.130, 0.015

5.130, 0.012

5.130, 0.012

5.130, 0.015

5.130, 0.015

5.130, 0.015

5.130, 0.015

5.130, 0.012

5.130, 0.015

5.130, 0.015

5.130, 0.015

5.130, 0.015

 

The idea with the CSV formatting is that you can copy and paste the CSV data into a text document, then open the text document in Excel to graph your data.  This is the data logger feature, not fancy, but it works.

 

Clone the project from Visual Studio 2019

 

  • Launch Visual Studio 2019
  • When the application opens, select the "Clone or check out code" option

  • The project is cloned
  • CMake generates the build artifacts

 

Build and Run the Project

Run the application

  • To run the application, first select "GDB Debugger (HLCore)" from the pull down menu.

  • Next click on the "GDB Debugger (HLCore)" link

  • Your application builds, loads on the target, and runs

 

That's it!  The application should be running.

 

Plot Data from the Application

I captured a ~4 minutes of data from my DUT.  My DUT was running the Microsoft PowerDown example application.  This application periodically puts the MT3620 into a power down state with instructions for the device to wake up after a 10 second period.  The current data should show this behavior.

 

Save the data to a *.csv text file

  • As mentioned above, I ran my application for ~4 minutes
    • I pressed the A button when the application started to output CSV formatted data
  • Copy the debug data from Visual Studio and paste it into an empty text file
  • Save the file with a *.csv file extension

 

Import the Data into Excel

I'm using Excel 2013, your Excel implementation may be different.  You'll get the idea.

 

  • Open Microsoft Excel
  • From the "Get External Data" grouping  select the "From Text" option
  • Browse to your data file
  • Click "Open"

  • The "Text Import Wizard" opens
    • Select the "Delimited" option
    • Select the "My data  has headers." option
    • Select the  "Next" button

  • Deselect the "Tab" option
  • Select the "Comma" option
  • Select the "Finish" button

  • Select where you want to put the data in your workbook
  • Click on the "OK" button
  • Your data is imported into Excel

Graph the Current Data

  • Using your mouse, or keyboard, select all the data in the "current" column
  • In the "Charts" grouping, select "Line Chart"

  • A line chart is inserted into your workbook

MCP39F511 Accuracy

I did some minimum validation on the accuracy of the measured data.  I used a multi-meter to validate the MCP39F511 readings.  MCP39F511 readings were pretty close, but not exact.  My data is shown below.

 

Measuring Line Voltage with the Power Monitor / Data Logger

This power monitor is great for measuring devices that require under 60V, but what if you want to measure the current on a Blender, Heat Gun, or any other 120V AC appliance/device?  Well you're in luck!  Microchip sells a MCP39F511A development kit shown below.

This device comes with a 120V cord you plug into a standard 120V wall outlet and a second "load" cord that you can plug any 120V device with a standard wall plug.  Furthermore, you can use your Avnet Azure Sphere Starter Kit and the example software application detailed in this Blog to read voltage and current data from the device.  There are a couple of minor changes you'll need to make to the software application.  See the details below for using this kit instead of the PWR METER click board.

 

Software Changes

  • Serial Port Speed
    • If your kit uses the MCP39F511 device, set the serial port baud rate to 115200
    • The baud rate is defined in main.c around line #422

  • Data divisors
    • The two kits also return data differently
    • The data divisors are defined in main.c around line #231

Hardware Changes

Use the table below and the pictures to correctly wire the Avnet Starter Kit to  the Microchip demo board

 

That's all there is to it.  After making the two software changes and correctly wiring your hardware run the app and turn on your connected device. 

 

List of Potential Improvements

As I put this Blog together I thought of ways to improve this tool.  This section captures these ideas.

 

  • Add timestamps to the output data
  • Perform a comprehensive study of MCP39F511 accuracy over a range of different voltages and currents
  • Add functionality to stream measurement data to a database or blob storage in Azure
  • Your idea here!

 

Conclusion

Thanks for reading through this Blog.  I hope you took the time and effort to build the solution for yourself.  Measuring power data can be useful for lots of different application from debugging hardware issues to preventive maintenance and more.  I look forward to your comments and will do what I can to help you if you run into any issues.

 

Brian