TTL Barcoder
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 onTTLType. TimestampGeneratorquantizes Unix time at the configured precisionRandomGeneratordraws from a numpy RNG. Both share the sameencode_bits/max_valueinterface on theTTLGeneratorbase class.
Examples
examples/dry_simulation.py— full walkthrough, no hardware neededexamples/bpod_loopback.py— Bpod StateMachine with loopback testexamples/pigpio_send.py— Raspberry Pi GPIO transmission
Contributing
- Fork and create a feature branch
- Add tests for new functionality
- Run
pytest - 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-NonCommercial licence: non-commercial research, academic and educational use only.
Metadata
Release files for ttl-barcoder 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ttl_barcoder-0.6.0.tar.gz | 24.5 kB | Without provenance | Details for ttl_barcoder-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ttl_barcoder-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for ttl_barcoder-0.6.0-py3-none-any.whl |
Total release size: 44.6 kB
Release files / ttl_barcoder-0.6.0.tar.gz
| Download URL | ttl_barcoder-0.6.0.tar.gz |
|---|---|
| Size | 24.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
45f0e15c4545d9af18d65d805cd4d5e18a75820bc49cef28d68aafd6d7607591
|
|
BLAKE2b-256 checksum How to use checksums |
d5f2f62456d499924c780b36b80d0670df789649ca007bf8b05b6e342e043999
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / ttl_barcoder-0.6.0-py3-none-any.whl
| Download URL | ttl_barcoder-0.6.0-py3-none-any.whl |
|---|---|
| Size | 20.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
557b65465c7d68d2eef0849543e115228a97316add3d26ff66df6692b00fe66a
|
|
BLAKE2b-256 checksum How to use checksums |
148e1bb304bc6254ed8f57e18c5d28ea20c0a0ef3ac919c016eed8d1932f0a4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for ttl-barcoder 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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.