Skip to main content

dln2 — Unified DLN2 USB I/O Board Wrapper

Drop-in replacement for the four independent dln2_*_wrapper packages.
All modules share a single USB connection — no echo-counter conflicts, no USB contention.

Originally developed for the Pico USB I/O Board.

Installation

pip install git+https://github.com/syabyr/dln2_wrapper

Requires: pyusb

Quick Start

from dln2 import Dln2Connection, SpiDev, GPIO, SMBus, ADC

conn = Dln2Connection()          # one USB connection

# ── SPI ─────────────────────────────────────────────────
spi = SpiDev(conn)
spi.mode = 3
spi.max_speed_hz = 16_000_000
rx = spi.xfer2([0x9F, 0x00, 0x00, 0x00])  # JEDEC ID

# ── GPIO ────────────────────────────────────────────────
gpio = GPIO(conn)
gpio.enable_pin(25)
gpio.set_direction(25, "out")
gpio.write(25, 1)                 # set pin HIGH
val = gpio.read(25)               # read pin level

# ── I2C ─────────────────────────────────────────────────
i2c = SMBus(conn)
i2c.open()
devices = []
for addr in range(1, 128):
    try:
        i2c.write_byte(addr, 0)
        devices.append(addr)
    except: pass

# ── ADC ─────────────────────────────────────────────────
adc = ADC(conn, vref=3.3)
volts = adc.read_volts(0)         # read channel 0 voltage

conn.close()

Multi-Device Support

from dln2 import list_devices, Dln2Connection

for d in list_devices():
    print(f"[{d.index}] serial={d.serial}")

lcd_conn = Dln2Connection(index=0)     # first board — ST7789 display
nfc_conn = Dln2Connection(index=1)     # second board — NFC reader
# or by exact serial:
# conn = Dln2Connection(serial="4250304B38353817")

Module API

SpiDev

spidev-compatible API: xfer(), xfer2(), writebytes(), readbytes(),
mode, max_speed_hz, bits_per_word, cshigh, lsbfirst, host_hold_cs

GPIO

set_direction(pin, "in"|"out"), write(pin, value), read(pin),
toggle(pin), get_direction(pin), set_event(pin, type), poll_event()

SMBus

smbus-compatible API: write_byte(), read_byte_data(),
write_word_data(), read_word_data(), read_block_data(),
write_block_data(), write_i2c_block_data(), read_i2c_block_data()

ADC

read_channel(channel), read_all(), read_volts(channel),
set_resolution(bits), enable_channel(ch), disable_channel(ch)

BME280

read_chip_id(), get_temperature(), get_humidity(), get_pressure(),
get_altitude(), get_all()

CLI Commands

After installation, the following commands are available:

Command Description
dln2-gpio-info Read GPIO pin state (JSON output)
dln2-gpio-toggle Toggle a GPIO pin (default: Pico LED)
dln2-gpio-watch Watch GPIO pin events
dln2-adc-info Read all ADC channels (JSON output)
dln2-adc-watch Stream one ADC channel
dln2-i2c-scan Scan I2C bus for devices
dln2-i2c-test Read/write I2C register
dln2-bme280 Read BME280 sensor measurements
dln2-spi-test Send SPI JEDEC ID probe
dln2-bpw-test Cycle SPI bits-per-word 4..16
# GPIO
dln2-gpio-info --pin 2
dln2-gpio-toggle --pin 25 --count 5 --interval 0.2
dln2-gpio-watch --pin 2 --timeout-ms 500

# ADC
dln2-adc-info
dln2-adc-watch --channel 0 --interval 0.5

# I2C
dln2-i2c-scan
dln2-i2c-test --address 0x76 --register 0xD0 --read 1

# BME280
dln2-bme280 --address 0x76 --pretty

# SPI
dln2-spi-test
dln2-bpw-test

Examples (as scripts)

# SPI JEDEC ID read
python3 examples/spidev_test.py

# GPIO pin toggle (default: Pico LED)
python3 examples/gpio_toggle.py --pin 25

# I2C bus scan
python3 examples/i2c_scan.py

# ADC monitor
python3 examples/adc_info.py

Why Unified?

Old (4 packages) New (dln2)
USB connections 4 separate (echo conflicts) 1 shared
Code duplication ~800 lines (4× Dln2Usb) 0 lines
GPIO events steal SPI responses Yes No (proper event queue)
Multi-device Manual USB enumeration list_devices()
Cross-module data flow Impossible (4 echo counters) Trivial (same counter)

Related

License

MIT

Download files

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

Source Distribution

dln2-0.2.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

dln2-0.2.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file dln2-0.2.0.tar.gz.

File metadata

  • Download URL: dln2-0.2.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for dln2-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d63a03cb3646883bf1333553ca33c2316da62f896a3398b2d4237509ea902183
MD5 f91d3337c9e1445a6a3a90963010e1f8
BLAKE2b-256 f3d5fcd29855b878c8d9e4c9c81ba925f0d172ab664e006faf9ae1f194ad4dda

See more details on using hashes here.

File details

Details for the file dln2-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dln2-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for dln2-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1186f095bcdffefc8f11b7b0f676f1020d8ea836fd55a3d9dd56ab44b644f902
MD5 56725f6b6662d28b3f35d6f1866f4593
BLAKE2b-256 519b5d4f4b7eb9e4ad92974cff0c7ab76078ccb3a2219859add56f26c7df7d8e

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.2

2 files

0.2.1

2 files

This release

0.2.0 This release

2 files

0.1.0

2 files

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