Skip to main content

PicoPWM

Control and monitor 24 PWM channels from Python or a local web dashboard. Supports Python 3.10+ on Windows, Linux, and macOS.

PyPI · Source · Firmware · Report an issue

The package communicates over USB HID with a Raspberry Pi Pico or Pico 2 running PicoPWM firmware. The included dashboard runs locally; your browser connects to Python, which communicates with the board.

Requirements

Quick Start

Create and activate a virtual environment:

Linux/macOS

python3 -m venv .venv
. .venv/bin/activate

Windows PowerShell

py -m venv .venv
.\.venv\Scripts\Activate.ps1

If activation is blocked, use the activation-free instructions.

Install and launch:

python -m pip install picopwm
picopwm

Connect the board to the computer running Python and open http://127.0.0.1:5000/. Select the board; use Rescan if needed. Stop the service with Ctrl+C. The older picopwm-web command remains an alias. Routine Werkzeug request logs are suppressed; warnings and errors remain visible.

Hatchling and hatch-vcs derive package versions from Git: a clean v1.2.3 tag builds 1.2.3; later commits get development versions, and dirty checkouts include a local version marker. Clone with Git history and tags available. Editable-install metadata updates when reinstalled. Manual CI builds use SETUPTOOLS_SCM_PRETEND_VERSION to select an explicit version.

Before driving outputs: GPIO signals are 3.3 V only. Banks default to monitor-only. Configure the intended bank as a generator and reboot before setting output. Follow the wiring guide.

Use from Python

Read status without changing outputs:

from picopwm.device.client import PicoPwmHid

client = PicoPwmHid()
try:
    state = client.status()
    if not state["connected"]:
        raise RuntimeError(state["error"])
    print(state["identity"])
    for channel in state["channels"]:
        print(channel)
finally:
    client.close()

Alternatively, use with PicoPwmHid() as client: for automatic handle cleanup on normal or exceptional exit. Entering the block does not open USB until the first operation. Closing a client releases its handle; it does not stop generator outputs.

For multiple boards, replace the client initialization, retaining the try/finally block:

from picopwm.hid.transport import open_device

client = PicoPwmHid(lambda: open_device(serial="YOUR_BOARD_SERIAL"))

After checking roles and wiring, use client.set_channel(0, 1000, 50) inside the try block to request 1 kHz / 50% duty, or client.stop() to stop all generators. Read back realized state; it is not an independent electrical measurement. status() returns connection errors in its result; commands can raise DeviceError on rejection or an unconfirmed outcome. Inspect state before retrying an unconfirmed command. Integer arguments reject booleans and non-integers; LED and overclock acknowledgements require booleans. Invalid arguments raise ValueError before device I/O. DeviceError.status contains the firmware result code when a command was rejected, or None for errors without a firmware result. Save & Reboot preserves that status when wrapping failures with a partial-settings warning. Returned status snapshots can be modified without changing the client's cached identity or pin map. Status-returning methods use the DeviceStatus dictionary contract; reboot methods return RebootResult. Nested report types are defined in picopwm.hid.protocol, without changing JSON shapes.

The 3-second command and 15-second save deadlines bound result polling, not blocking hidapi transfers. A stalled OS/USB transfer can delay other calls on the same board, including stop. If output state is uncertain, disconnect board power. Cross-platform transfer-stall behavior has not been hardware-qualified; do not rely on the host as an emergency-stop mechanism.

Dashboard Configuration

Set these before starting picopwm; direct Python clients select boards through open_device() instead.

Variable Purpose Default
PICOPWM_SERIAL Preferred board serial Automatic selection
PICOPWM_DEVICE_PATH Preferred HID path Automatic selection
PICOPWM_HOST Listen address 127.0.0.1
PICOPWM_PORT Listen port 5000
PICOPWM_TOKEN API access token Unset

Keep loopback binding for local use. Remote binding requires a token; the built-in server has no TLS. Do not expose it directly to the internet. See the integration guide for authentication, HTTP APIs, and development.

Troubleshooting

Compatibility depends on HID report layouts and advertised capabilities, not a minimum firmware version. Unsupported identities or layouts produce protocol errors; optional controls require supporting firmware. No minimum hardware-verified firmware release has been established.

  • Board missing or inaccessible: check the cable, firmware, HID permissions, and board selection. Scripts with multiple boards must select a serial number or device path.
  • Control unavailable: check the running bank role and firmware capabilities; monitors cannot be driven.
  • Readings: temperature is an uncalibrated internal estimate; service load is not CPU utilization.

See setup and troubleshooting. For bug reports, include package/firmware versions, OS, and the exact error message.

Source Organization

The package stays under host/python/picopwm/, with functional subpackages:

  • dashboard/: Flask HTTP interface and server entry point.
  • device/: thread-safe device client and board registry.
  • hid/: USB discovery, transport, and report codecs.

Import directly from these subpackages; the former flat module paths have been removed. CLI commands picopwm and picopwm-web are unchanged. No extra src/ layer is needed.

Tests mirror these subpackages under tests/dashboard/, tests/device/, and tests/hid/; shared device doubles live in tests/fakes.py. Run them with python -m pytest -q host/python/tests from the repository root.

Concurrency regressions intentionally replace private _lock and wrap _run to observe contention at validation/readback boundaries. Update those tests with synchronization refactors; they do not define a public locking API or establish native hidapi transfer deadlines. Shared dashboard source/selector checks are likewise implementation-coupled, not browser end-to-end tests.

The shared web client bounds reads (including JSON bodies) to 5 seconds and writes/login to 20 seconds. Changing boards cancels obsolete status reads. Parallel unauthorized requests share one token prompt/login. HTTP errors retain their status even when a proxy returns HTML instead of JSON. After a lost, timed-out, malformed successful, or server-error write response, controls remain unavailable until fresh selected-board status is received. The command may have taken effect; it is never automatically replayed, and canceling HTTP does not cancel USB work on the server. Verify readback before retrying.

Run shared dashboard tests with node --test host/web/tests/*.test.mjs. They include a Chromium flow with a simulated HTTP API for login, board switching, editing, save acknowledgement, and uncertain-write recovery. Set CHROMIUM to the browser executable to require that check; otherwise it explicitly skips when chromium is absent. Linux host CI requires the browser. The browser uses a temporary local-file copy: this does not qualify real Flask/ASP.NET delivery, authentication cookies, or physical USB/PWM.

License

BSD 3-Clause.

Metadata

Release files for picopwm 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for picopwm 0.6.0
File Interpreter ABI Platform Actions
picopwm-0.6.0-py3-none-any.whl Python 3 none any Details for picopwm-0.6.0-py3-none-any.whl

Release files / picopwm-0.6.0-py3-none-any.whl

Download URL picopwm-0.6.0-py3-none-any.whl
Size 46.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0fcf196dbd6192b10954ebd7dcb5a8efe20613f8b70d0c5828e1635b73b2caa3
BLAKE2b-256 checksum
How to use checksums
9aef4f25cf3e5a1fcb6de1da4c5093794a3b3e2d67e00d79535c0112aac2994e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Security for picopwm 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

1 file in this release has been uploaded with provenance metadata.

Attestation for picopwm-0.6.0-py3-none-any.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page