Reading data from Si7021 sensor on Linux using Python
17 July 2021
#!/usr/bin/env python3
import smbus
if __name__ == '__main__':
bus = smbus.SMBus(0) # assuming your sensor is /dev/i2c-0
addr = 0x40
# read temperature (in celsius)
b = bus.read_i2c_block_data(addr, 0xE3, 2)
temp = 175.72 * (b[0] << 8 | b[1]) / 65536.0 - 46.85
# read humidity (percentage)
b = bus.read_i2c_block_data(addr, 0xE5, 2)
humidity = 125.0 * (b[0] << 8 | b[1]) / 65536.0 - 6.0
print("humidity: " + str(humidity))
print("temp: " + str(temp))
If you have any comments, contact me by email.