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)

Pin Constraints

Pins Capability
0–22, 26–28 Full GPIO (input/output + events)
23, 24, 29 Output-only (reserved for SMPS / VBUS / VSYS)
25 Output-only (on-board LED)
ADC 0–2 Map to GPIO 26, 27, 28 respectively

Firmware Compatibility

dln2 Python Minimum firmware Notes
0.2.1 pico-usb-io-board >= v0.2 SPI bpw validation, ADC pin-sharing fix
0.2.0 any Works with all firmware versions

To flash updated firmware:

  1. Hold the BOOTSEL button while connecting the Pico (or press and release RESET while holding BOOTSEL)
  2. Copy dln2.uf2 to the RPI-RP2 USB drive that appears
  3. The Pico reboots automatically with the new firmware

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.1.tar.gz (18.8 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.1-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dln2-0.2.1.tar.gz
  • Upload date:
  • Size: 18.8 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.1.tar.gz
Algorithm Hash digest
SHA256 bfedbffe224318c30787a06813fea036d737daf0ee2a1b98f326879354a4797b
MD5 c8f9f11343e0a0f967373e81b85161d6
BLAKE2b-256 2e8871a9989bc7199efa76f2f71fff933125580340462d4ac86cc3d0d9692055

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dln2-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 19.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7bb7aaaa5acab378b7d0c2c150a89adf0ce083a1f5d31207fea283814ce2d434
MD5 5767e738becc00b9502cc8a29d0e1ca8
BLAKE2b-256 af5584d0e607cebde17c4d7a921122c0505bca4ab9937ed04349b93359075f43

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.2

2 files

This release

0.2.1 This release

2 files

0.2.0

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