Using the power measurement board under windows

This walk-through details the packages that need to be installed under Windows to support execution of the Python scripts that are detailed in the workshop for use with the power measurement board.

NOTE: You must first have obtained a board with appropriate firmware installed, or followed the procedure outlined in the workshop to build and download firmware to the board. It may be possible to achieve this under Windows but currently the available instructions require the use of a Linux host.

There are four main steps to follow to support execution of the supplied Python scripts under Windows. It is assumed that you are using Windows 8 or 8.1, although these steps should be similar for older versions of Windows.

Contents

Obtain the Python scripts

Sources to the firmware and scripts for the stm32f4 energy metering board can be found here

https://github.com/jpallister/stm32f4-energy-monitor/tree/pyusb

(NB. the branch to use is 'pyusb' not the default 'master')

Use your Windows Git client of choice to clone the repository, or download a zipped copy of the source archive here

You will find the Python scripts in src/python.

  • read.py is a basic script that supports reading of values from the stm32f4 when the blue button is pressed
  • interactive_graph.py is a more comprehensive script that will show a real-time graph of voltage, current and/or power measurements

Connect the Hardware

Ensure that appropriate firmware has been downloaded and that PA9 is connected to power the measurement board as detailed in the workshop. Then connect the micro-USB adaptor to your Windows host you will see a new device in your 'Device Manager' window. It will be in 'Other Devices' as there is currently no driver available for the USB device.

Device Manager Unknown Device

If you see an ST-Link device appear then you have incorrectly connected the mini-USB adaptor. You should disconnect and use the micro-USB adaptor. See the workshop for details.

Ensure Windows allows installation of unsigned drivers

Prior to Windows 8 the system will ask if you wish to install unsigned drivers.

Under Windows 8 and 8.1 the operating system by default disallows installation of unsigned drivers. In order to enable installation of unsigned drivers the user must reboot Windows into the "Disable Driver Signature Enforcement" mode

To do this follow the instructions here. You will need to reboot Windows twice during this procedure and will then have a running copy of Windows that will allow you to install unsigned drivers.

Install USB Drivers

We will be using Python pyusb bindings which uses a libusb-win32 backend to communicate with USB devices.

As such the first thing to do is to download and extract the libusb-win32 package from here

You will see in the 'bin' folder there is a file called inf-wizard.exe which you should execute. This will allow you to create a device driver description corresponding to the attached energy metering board, which will allow us to install the libusb-win32 driver we need.

The inf-wizard will show you a list of attached USB devices, one of which should be the "Medium speed energy monitor". This currently has a vendor ID of 0xF539 and a product ID of 0x5F39.

INF wizard

Select this device, and click next twice to save the .INF file.

Then click 'Install Now' to use that .INF file to install the driver.

If installation fails on Windows 8.x, ensure that you have followed the instructions above to disable device driver signature enforcement.

You should now see in Device Manager that you have a new libusb-win32 device, Medium speed energy monitor.

Device Manager libUSB-win32 Device

Install Python and Python Support Packages

It is important that the support packages installed match the CPU architecture for the build of Python you are running. For example if you are running an x64 build of Windows then you should install x64 Python and x64 copies of all packages. This is the installation setup that has been tested.

If you mix and match x86 and x64 Python/packages then you are likely to see a cryptic message about %1 invalid DLL format. If you see this then you should uninstall Python and Python support packages and start again.

Install Python

Download and install Python 2.7.6 from here.

Other versions of Python make work but we have tested with 2.7.6.

Ensure that you use the appropriate x86 or x86-64 installer.

Install Support Packages

Ensure for all of the following packages that you are installing the appropriate x86 or x64 architecture package for the appropriate version of Python (e.g. 2.7)

  • Download and install PIP installer from here. This will also install setuptools
  • Download and install PyQt4 from here
  • Download and install MatPlotLib from here
  • Download and install NumPy from here
  • Download and install SciPy from here

Run the scripts

At this point you should be able to open up a Python command line, change directory to the stm32f4-energy-monitor\src\python folder and execute

python read.py

or

python interactive_graph.py

Feedback / Issues

Please report any issues with the above to the MAGEEC mailing list and/or Alex Lennon