Skip to content

Noridc PowerProfilerKit2 Codec

The PowerProfilerKit2 codec is designed to streamline communication with the power profile kit 2 from Nordic. It simplifies the interactions with the device and wraps them into set/get signal objects.

Quick Start

The PowerProfilerKit2 operates by utilizing a set of predefined signals and a background worker thread that polls the device at a user-defined rate for the latest device data.

This snippet demonstrates initializing the PPK2 device, setting its mode, voltage, turning it on, and reading the maximum current.

from zeloscloud.codecs.ppk2 import PowerProfilerKit2

with PowerProfilerKit2("ppk2", "/dev/ttyACM0") as ppk2:
    ppk2.device_mode.set("source")
    ppk2.source_mV.set(3300)
    ppk2.device_state.set("on")

    print(f"Max Current: {ppk2.max_current_uA.get()} µA")

Basic Pytest Setup

Here's a quick example on how to set up the device as a fixture for use in tests:

conftest.py

import pytest
from zeloscloud.codecs.ppk2 import PowerProfilerKit2

@pytest.fixture(scope="session")
def ppk2():
    """Create a PPK2 Codec."""
    with PowerProfilerKit2("ppk2", "/dev/ttyACM0", poll_rate_s=0.1) as ppk2:
        # Optionally turn it on here instead of at the test level
        ppk2.device_mode.set("source")
        ppk2.source_mV.set(3300)
        ppk2.device_state.set("on")
        yield ppk2

Usage

Parameters and Initialization

  • name: A string representing the name of your PowerProfilerKit2 instance.
  • port: The serial port to which the PPK2 is connected, e.g., /dev/ttyACM0.
  • poll_rate_s: The polling rate in seconds for reading data from the PPK2 device.

Signals

The module provides various signals that represent different measurements and states of the PPK2 device:

Warning

The measurement signals are set based on the data in the worker thread. Do not set them, you should only call .get() on them. Control signals can be both .set()/.get().

Measurement Signals

  • max_current_uA: Maximum current measured in microamps within the polling window.
  • min_current_uA: Minimum current measured in microamps within the polling window.
  • avg_current_uA: Average current calculated as the mean of all samples within the polling window, measured in microamps.
  • max_current_mA: Maximum current, converted from microamps to milliamps.
  • min_current_mA: Minimum current, converted from microamps to milliamps.
  • avg_current_mA: Average current, converted from microamps to milliamps.
  • avg_power_mW: Average power calculated by multiplying the average current in milliamps by the source voltage in millivolts, resulting in milliwatts.
  • avg_charge_mC: Average charge calculated by multiplying the average current in microamps by the polling rate in seconds, giving a value in millicoulombs.

Control Signals

  • device_mode: The mode of the device - either 'ampere' or 'source'.
  • device_state: The state of the device - either 'on' or 'off'.
  • source_mV: The voltage output of the device in millivolts.

Windowed Samples

During each user defined polling interval, the data is gathered from the PPK2 device, and then the calculations are made in software.

Plotting

In addition to using the codec and it's signals at test time, plotting support is built-in for device. If you don't already have the flag enabled in the pytest.ini, you can pass --zplot-io in the command line to start plotting and visualizing the signal data!

In your terminal

pytest --zplot-io

In your pytest.ini

addopts = -sv --local-artifacts-dir="artifacts" --zplot-io
PPK2

Troubleshooting

Device Connection Issues

If the module cannot find your PPK2 device:

  • Ensure the device is correctly connected and turned on.
  • Verify that you are using the correct serial port.

Permission Issues

On Linux systems, you might face permission issues accessing the serial port:

sudo chmod 666 /dev/ttyACM0

Replace /dev/ttyACM0 with your actual device port.

Additional Resources

For more comprehensive information and deeper insights into the Power Profiler Kit 2 (PPK2) and its capabilities, please refer to the following external resources:

PPK2 Device.

PPK2 Github.

API Reference

See zeloscloud.codecs.ppk2.PowerProfilerKit2 in the API Reference.