Skip to main content

Simple library for Pico Technology USB TC-08 thermocouple data logger — direct ctypes bindings, no picosdk required

Project description

pico-tc08

Simple Python library for the Pico Technology USB TC-08 8-channel thermocouple data logger.

Uses direct ctypes bindings to the Pico shared library — bypasses the official picosdk Python wrapper, which has a macOS-specific attribute-naming bug that prevents it from loading the library.

Features

  • All 8 channels with any mix of thermocouple types (B, E, J, K, N, R, S, T)
  • Cold junction compensation temperature included in every reading
  • Averaged readings over a configurable time window
  • Continuous CSV logging (appends, runs until Ctrl+C)
  • Descriptive error messages for all common failure modes (missing library, wrong CPU architecture, device not connected)
  • Context manager support for safe resource cleanup

Important: Apple Silicon (M1/M2/M3/M4)

The Pico TC-08 library ships as an x86_64 binary only. It cannot run natively on Apple Silicon processors.

This library detects this at startup and prints clear instructions. See the Apple Silicon Setup section below.

Installation

pip install pico-tc08

Prerequisites

Install PicoLog for macOS from the Pico Technology website:

https://www.picotech.com/downloads

This installs PicoLog.app which contains the required libusbtc08.dylib library at:

/Applications/PicoLog.app/Contents/Resources/libusbtc08.dylib

Apple Silicon Setup (M1/M2/M3/M4)

The Pico library is an x86_64-only binary — it must run under Rosetta 2 (x86_64 emulation).

Automated Setup (recommended)

Run the provided setup script once:

bash setup_arm_mac.sh

This creates a dedicated tc08x86 conda environment under a Rosetta-compatible Miniconda installation. After setup:

conda activate tc08x86
python your_script.py

Manual Quick Fix

For a one-off run without the setup script:

arch -x86_64 python your_script.py

How the error looks

If you try to import pico_tc08 on Apple Silicon without Rosetta, you get:

======================================================================
  APPLE SILICON DETECTED — Rosetta 2 required
======================================================================

  You are running Python natively on ARM64 (Apple Silicon).
  The Pico library at:
    /Applications/PicoLog.app/Contents/Resources/libusbtc08.dylib
  is an x86_64 binary and CANNOT run on ARM processors.

  FIX OPTION 1 — Quick run under Rosetta 2:
    arch -x86_64 python your_script.py

  FIX OPTION 2 — Create a dedicated x86_64 conda environment:
    bash setup_arm_mac.sh
    conda activate tc08x86
    python your_script.py
======================================================================

Quick Start

1. Check your environment

from pico_tc08 import check_environment
check_environment()  # raises RuntimeError with clear instructions if anything is wrong

2. Single reading

from pico_tc08 import quick_read

sample = quick_read(channel_types={1: "K", 2: "K"})
if sample:
    print(f"Cold junction: {sample.cold_junction:.2f} °C")
    for ch, temp in sample.channels.items():
        print(f"  CH{ch}: {temp:.2f} °C")

3. Continuous CSV logging

from pico_tc08 import log_csv

log_csv(
    out_csv="temperatures.csv",
    channel_types={1: "K", 2: "K", 3: "T"},
    interval_seconds=300.0,       # log every 5 minutes
    sample_window_seconds=5.0,    # average over 5 seconds per log entry
    mains_hz=50,
)

4. Full device control

from pico_tc08 import TC08Device

with TC08Device(channel_types={1: "K", 2: "K", 3: "T", 4: "J"}, mains_hz=50) as dev:
    # Single reading
    sample = dev.read_once()
    print(f"Cold junction: {sample.cold_junction:.2f} °C")
    for ch, temp in sample.channels.items():
        print(f"  CH{ch}: {temp:.2f} °C")

    # Averaged reading over 10 seconds
    last, stats, (cjc_mean, cjc_std) = dev.sample_window(window_seconds=10.0)
    for ch, (mean_c, std_c) in stats.items():
        print(f"  CH{ch}: {mean_c:.2f} ± {std_c:.3f} °C")

API Reference

check_environment(lib_path=None)

Verify that the environment is correctly configured. Raises RuntimeError with instructions if anything is missing or misconfigured.

TC08Device Class

__init__(channel_types=None, mains_hz=50, lib_path=None)

Parameter Default Description
channel_types {1: "K"} Dict mapping channel (1–8) to thermocouple type
mains_hz 50 Mains frequency for noise filtering (50 or 60 Hz)
lib_path platform default Override library path

Thermocouple types: "B", "E", "J", "K", "N", "R", "S", "T"

Methods

Method Returns Description
open() Open USB connection and configure channels
close() Close USB connection
read_once(retries=10) Sample Single temperature reading
sample_window(window_seconds=5.0) (Sample, dict, tuple) Averaged reading over a time window

Context Manager

with TC08Device({1: "K"}) as dev:
    sample = dev.read_once()
# device automatically closed on exit

Sample Dataclass

Attribute Type Description
t_wall float Wall-clock timestamp (time.time())
t_mono float Monotonic timestamp (safe for duration math)
cold_junction float Cold junction compensation temperature (°C)
channels dict {channel_number: temperature_C}

Convenience Functions

log_csv(out_csv, channel_types, interval_seconds=300, sample_window_seconds=5, mains_hz=50)

Run continuous CSV logging until Ctrl+C. Appends to existing file.

quick_read(channel_types=None, mains_hz=50) -> Optional[Sample]

Connect, read once, disconnect. Returns Sample or None on failure.

CSV Output Format

t_wall,cold_mean_C,cold_std_C,ch1_mean_C,ch1_std_C,ch2_mean_C,ch2_std_C
1740000000.123,23.45,0.12,85.23,0.15,82.11,0.13
1740000300.456,23.47,0.11,86.01,0.14,82.98,0.12
  • t_wall: Unix timestamp of the reading
  • cold_mean_C / cold_std_C: Cold junction mean and standard deviation
  • chN_mean_C / chN_std_C: Channel N mean and standard deviation

Notes

  • Always close PicoLog before using this library — it holds the USB device
  • The minimum sampling interval is 200 ms (hardware limitation)
  • Channels not listed in channel_types are disabled
  • On macOS, the library is loaded from inside PicoLog.app — do not uninstall PicoLog

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pico_tc08-0.1.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pico_tc08-0.1.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file pico_tc08-0.1.0.tar.gz.

File metadata

  • Download URL: pico_tc08-0.1.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pico_tc08-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e6c635e3c7a270f32d3da6cc591c476743c03c568d85914a73ccd39e2d2daa96
MD5 66b1b52ea77c4c0fdea480254b343c6e
BLAKE2b-256 51c5df3a651c436599d503bd128c9de23f6280d50492ed9ab1e577316329a232

See more details on using hashes here.

File details

Details for the file pico_tc08-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pico_tc08-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pico_tc08-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e6dd71e4598b65c11138b14f7a1e984771c1be3fecd041905d54dc46d766b8a
MD5 020b1f8bfeb41253ad28142718f02545
BLAKE2b-256 f08c1c864b6a9e0fb3b2a860a0bc63c552add11f688ac2a3bc7a317b5abd9321

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page