kplindegaard / smbus2

A drop-in replacement for smbus-cffi/smbus-python in pure Python
MIT License
243 stars 68 forks source link

Reading data without defining offset register #84

Closed AntonSuklje closed 2 years ago

AntonSuklje commented 2 years ago

Is it possible to read 4 bytes without defining the offset register? Working example in Micropython: from machine import Pin, I2C i2c = I2C (scl=Pin (18), sda=Pin (19), freq=100000) data = i2c.readfrom (slave_addr, 4)

kplindegaard commented 2 years ago

I would think example 5 in the readme should nail it?

AntonSuklje commented 2 years ago

Yeah, that works. Thanks for the tip Karl-Petter.

from smbus2 import SMBus, i2c_msg bus = SMBus(1)

Read 4 bytes from address 0x70

msg = i2c_msg.read(0x70,4) bus.i2c_rdwr(msg) data = list(msg)