Skip to main content

A Python library for DLN2 I2C adapters with an SMBus-style API. Originally developed for Pico USB IO Board.

Project description

DLN2 I2C Wrapper

A Python library for interfacing with DLN2 USB-to-I2C adapters with an SMBus-style API. It targets the Pico USB I/O Board firmware and packages the host-side I2C access layer as a standalone Python project.

Features

  • SMBus-style API for common byte, word, and I2C block operations
  • Low-level DLN2 USB client built on pyusb
  • BME280 helper for chip ID, calibration, and measurement reads
  • I2C scan and BME280 example scripts
  • Pure Python, no compiled extension

Important Limitation

The firmware exposes separate DLN2 read and write commands. It does not expose a single combined repeated-start transaction through the USB protocol, so register reads are performed as:

  1. Write register pointer
  2. Start a separate read transaction

That works for many devices, but it is not identical to Linux i2c-dev combined transfers. i2c_rdwr() in this wrapper also executes messages sequentially for the same reason.

Installation

From source:

git clone https://github.com/syabyr/dln2_i2c_wrapper.git
cd dln2_i2c_wrapper
pip install .

For development:

pip install -e ".[dev]"

Quick Start

from dln2_i2c_wrapper import SMBus

with SMBus(1) as bus:
    device_addr = 0x50
    register = 0x00

    value = bus.read_byte_data(device_addr, register)
    print(hex(value))

    bus.write_byte_data(device_addr, register, 0x12)

BME280 Example

from dln2_i2c_wrapper import BME280

with BME280(bus=1, address=0x76) as sensor:
    print(hex(sensor.check_chip_id()))
    sensor.read_calibration()
    sensor.configure()
    print(sensor.read_measurements())

Command-Line Tools

dln2-i2c-test --help
dln2-i2c-scan --help
dln2-bme280-test --help

Use register-based probing when scanning devices that do not ACK a bare read, for example:

dln2-i2c-scan --register 0xD0 --read-len 1

Low-Level API

from dln2_i2c_wrapper import Dln2Usb, find_device

device = find_device()
client = Dln2Usb(device, debug=True)

client.i2c_enable()
client.i2c_write(0x50, b"\x00")
data = client.i2c_read(0x50, 4)
print(data.hex())
client.i2c_disable()
client.close()

Development

make test
make build

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

dln2_i2c_wrapper-0.1.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

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

dln2_i2c_wrapper-0.1.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dln2_i2c_wrapper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a41754db30ce4bf4542280c57dffaf576bb7caea6af30116ee5471477c2455d9
MD5 e4e61101b84021161abd9e566fe50db2
BLAKE2b-256 73aa0ab8043ccaea4e41b9975d43e82d8f6f32fd81ec47bbb5d765fd3e96e389

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dln2_i2c_wrapper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f269b54ed6324a2defad310ce9935ad9a160aada63ac725e29b121eb0075f340
MD5 cfa62fdc11c54e2d29705b5f2df8a560
BLAKE2b-256 c9b65606f28f6c8a59350a79e0d9ca731aecbefc2e72679b7c5c105af3b26690

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