Skip to main content

Modular barcode generation for TTL synchronization with clean hardware separation

Project description

TTL Barcoder

PyPI

Generate and decode binary barcodes over TTL signals to synchronize multiple data acquisition systems.

→ Full documentation Barcodes encode a timestamp or random value as a sequence of timed HIGH/LOW pulses, transmittable over any digital output.

Quick Start

from ttl_barcoder.core import BarcodeTTL, BarcodeConfig, TTLType, TimestampPrecision

# Timestamp barcode (default) — encodes current time at ms precision
barcoder = BarcodeTTL()
sequence = barcoder.get_sequence()   # [(level: bool, duration_ms: float), ...]

# Random barcode
config = BarcodeConfig(ttl_type=TTLType.random, barcode_bits=32)
barcoder = BarcodeTTL(config)
sequence = barcoder.get_sequence()

Bpod

from ttl_barcoder.core import BarcodeTTL
from ttl_barcoder.hardware.bpod import inject_barcode_states

barcoder = BarcodeTTL()
sequence = barcoder.get_sequence()
inject_barcode_states(sma, sequence, bnc_channel='BNC1', first_state_name='send_sync', last_state_name='next')

Raspberry Pi GPIO

from ttl_barcoder.hardware.pigpio import send_barcode_sequence

send_barcode_sequence(barcoder.get_sequence(), pin=18)

Installation

pip install ttl-barcoder          # core only
pip install ttl-barcoder[bpod]    # + Bpod
pip install ttl-barcoder[pigpio]  # + Raspberry Pi GPIO

Configuration

BarcodeConfig is a Pydantic model — all fields are validated on construction.

from ttl_barcoder.core import BarcodeConfig, TTLType, TimestampPrecision

config = BarcodeConfig(
    ttl_type=TTLType.timestamp,            # or TTLType.random
    barcode_bits=37,                        # 16–64 bits
    timestamp_precision=TimestampPrecision.milliseconds,  # s / ms / us
    bit_duration_ms=35.0,
    init_duration_ms=10.0,
    tolerance=0.25,
)

Presets: default, high_speed, conservative, high_precision, random

from ttl_barcoder.core import get_preset
config = get_preset("conservative")
Preset Bits Precision Bit duration TX duration Coverage
default 37 ms 35 ms 1355 ms 4.4 yr
high_speed 32 ms 25 ms 848 ms 49 days
conservative 37 ms 50 ms 1940 ms 4.4 yr
high_precision 42 us 50 ms 2190 ms 51 days

Architecture

ttl_barcoder/
├── core/
│   ├── config.py        # BarcodeConfig (Pydantic), TTLType, TimestampPrecision
│   ├── generator.py     # TTLGenerator ABC → TimestampGenerator / RandomGenerator
│   ├── encoder.py       # bits → (level, duration_ms) timing sequence
│   ├── decoder.py       # edge timestamps → barcode value
│   └── barcode_ttl.py   # BarcodeTTL — main interface combining the above
└── hardware/
    ├── bpod/            # Bpod StateMachine integration
    └── pigpio/          # Raspberry Pi GPIO via pigpio
  • The generator is selected via a factory (create_generator(config)) based on TTLType.
  • TimestampGenerator quantizes Unix time at the configured precision
  • RandomGenerator draws from a numpy RNG. Both share the same encode_bits / max_value interface on the TTLGenerator base class.

Examples

  • examples/dry_simulation.py — full walkthrough, no hardware needed
  • examples/bpod_loopback.py — Bpod StateMachine with loopback test
  • examples/pigpio_send.py — Raspberry Pi GPIO transmission

Contributing

  1. Fork and create a feature branch
  2. Add tests for new functionality
  3. Run pytest
  4. Submit a pull request

Acknowledgments

  • Based on barcode synchronization from University of Colorado ONE Core
  • Inspired by Open Ephys protocols
  • Built for the neuroscience and scientific DAQ community

License & sources

This software is released under the BSD 3-Clause 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

ttl_barcoder-0.4.3.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

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

ttl_barcoder-0.4.3-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file ttl_barcoder-0.4.3.tar.gz.

File metadata

  • Download URL: ttl_barcoder-0.4.3.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ttl_barcoder-0.4.3.tar.gz
Algorithm Hash digest
SHA256 0757811fa1b0c34a97dca602a2fa870758d56aff032f6e65dc050e917239bbca
MD5 6f7c34682a6560ed55e2206f43dec128
BLAKE2b-256 db36574684079bfded9d01fa60d97d7e3f14731c46fc05209c1307296ca4bad9

See more details on using hashes here.

File details

Details for the file ttl_barcoder-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: ttl_barcoder-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ttl_barcoder-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 aea4270632ad8a1bd2db9185c55fc793b40b8d05b29fc3f9689b5869aae0e1e6
MD5 7178d78bfca3ec0f585e9ef0cd0370e3
BLAKE2b-256 4669ce1a051dc7d33b556752c148261ff60b330345df0911fb74eb4644bf6f95

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