Skip to main content

A Simple USB to I2C Adapter that works.

The I2C Adapter allows python programs to connect to I2C/QUIIC/STEMMA-QT devices using off the shelf low cost boards such the Raspberry Pico or SparkFun Pro Micro - RP2040. The I2C adapter appears on the computer as a serial port (no device installation required) and acts as a USB to I2C bridge, and this Python package provides an easy to use API to interact with it using high level commands.

For example, the schematic below shows the wiring for the oled_demo.py example which drive an I2C OLED display using an I2C Adapter and the luma.oled python package.



Highlights

  • Provides USB to I2C-master bridge.
  • Supports Windows/Mac/Linux.
  • Uses low cost low cost off-the-shelf boards as adapters.
  • Does not require driver installation (it appears on the computer as standard a serial port).
  • Comes with an easy to use Python API.
  • Easy to modify/extend and to adapt to new hardware.
  • Permissive open source license. Comercial use OK, sharing and attribution not required.

Python API Example

Package installation

pip install i2c-adapter --upgrade

In the example below, we use an I2C Adapter that appears as serial port "COM7" to access an I2C device at address 0x08. First we write a single byte 0x00 and then read 20 bytes. Upon completion, the 'data' variable contains a bytearray with 20 bytes.

from i2c_adapter import I2cAdapter

i2c = I2cAdapter(port="COM7")
i2c_addr = 0x08
assert i2c.write(i2c_addr, bytearray([0]))
data = i2c.read(i2c_addr,  20)
print(data)

In the example below we scan the I2C bus address range 0x00 to 0x7f and look for devices that response to an empty write.

from i2c_adapter import I2cAdapter

i2c = I2cAdapter(port="COM18")
print(f"Scanning I2C bus 0x00 to 0x7f:")
for adr in range(0, 127):
    if i2c.write(adr, bytearray([0]), silent=True):
      print(f"  - Device at 0x{adr:02x}")

Documentation

Full documentation is available at https://i2c-adapter.readthedocs.io/

Metadata

Release files for i2c-adapter 0.2.21

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for i2c-adapter 0.2.21
File Size Uploaded
i2c_adapter-0.2.21.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for i2c-adapter 0.2.21
File Interpreter ABI Platform
i2c_adapter-0.2.21-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / i2c_adapter-0.2.21.tar.gz

Download URL i2c_adapter-0.2.21.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
226c26af93b3a56cdab8f4829bdb0667ebb44fa3fdffc99226c16017131bfc9c
BLAKE2b-256 checksum
How to use checksums
1c8e207ba40f77d733b94a363a5f65c763ad3f50a258be05f2b962fa64932e90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.1

Release files / i2c_adapter-0.2.21-py3-none-any.whl

Download URL i2c_adapter-0.2.21-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c41d3c3e28ab8631523d4347d109b7e830f8ad831064ad38741295cf0a24310b
BLAKE2b-256 checksum
How to use checksums
40cef7adc08e48a2d98db9086d1902fc14a06b0a0ec484ca9bcaaf73acee3e08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.1

Release history Release notifications | RSS feed

This release

0.2.21 This release

2 release files

0.2.20

2 release files

0.2.19

2 release files

0.2.18

2 release files

0.2.17

2 release files

0.2.16

2 release files

0.2.15

2 release files

0.2.9

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release 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