kplindegaard / smbus2

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

SHT30 communication through i2c #70

Open g3d12 opened 3 years ago

g3d12 commented 3 years ago

Hi can you help me how should I compose a write_i2c_block_data in order to execute a commands shown here: https://ibb.co/GWZjSqq The problem I find is the array of data I want to send. For example with high alert clear I wrote: bus.write_i2c_block_data(0x44, 0x61,[0x16,0xC9,0x2D,0x93]) - that unfortunately throws an error: IOError: [Errno 121] Remote I/O error

I based my code on https://github.com/ControlEverythingCommunity/SHT30/blob/master/Python/SHT30.py where command header for reading temerpature is "0x2C06" and the whole command looks like this: bus.write_i2c_block_data(0x44, 0x2C, [0x06]) But as shwn it does not work. The paper on the commands you fill find here: https://www.mouser.com/pdfDocs/Sensirion_Humidity_Sensors_SHT3x_Application_Note_Alert_Mode_DIS.pdf (table.2)

kplindegaard commented 3 years ago

A shot in the dark, but have you tried two separate i2c commands like this for a READ command?

from smbus2 import SMBus, i2c_msg

addr = 0x44  # You have checked that this is available with i2cdetect, I presume?

# Prepare write payload for high alert limit read msb+lsb command
write = i2c_msg.write(addr, [0xE1, 0x1F])
read = i2c_msg.read(addr, 3)  # You should always receive 3 bytes

with SMBus(1) as bus:
    # Perform operation as one transaction
    bus.i2c_rdwr(write, read)

data = list(read)
print(data)