@@ -0,0 +1,1406 @@
+# Distributed with a free-will license.%0A# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.%0A# SI7021%0A# This code is designed to work with the SI7021_I2CS I2C Mini Module available from ControlEverything.com.%0A# https://www.controleverything.com/content/Humidity?sku=SI7021_I2CS#tabs-0-product_tabset-2%0A%0Aimport smbus%0Aimport time%0A%0Aaddr = 0x40 # SI7021 address, 0x40(64)%0Acmd_humi = 0xF5 // no hold master mode%0Acmd_temp = 0xF3 // no hold master mode%0Acmd_reset = 0xFE%0A%0Adef get_bus():%0A    return smbus.SMBus(1)%0A%0Adef read_humi(bus):%0A    bus.write_byte(addr, cmd_humi)%0A    time.sleep(0.3)%0A%0A    # Read data back, 2 bytes, Humidity MSB first%0A    data0 = bus.read_byte(addr)%0A    data1 = bus.read_byte(addr)%0A%0A    # Convert the data%0A    humidity = ((data0 * 256 + data1) * 125 / 65536.0) - 6%0A    return humidity%0A%0Adef read_temp(bus):%0A    bus.write_byte(addr, cmd_temp)%0A    time.sleep(0.3)%0A%0A    # Read data back, 2 bytes, Temperature MSB first%0A    data0 = bus.read_byte(addr)%0A    data1 = bus.read_byte(addr)%0A%0A    # Convert the data%0A    cTemp = ((data0 * 256 + data1) * 175.72 / 65536.0) - 46.85%0A    fTemp = cTemp * 1.8 + 32%0A    return cTemp%0A%0Aif __name__ == '__main__':%0A    bus = get_bus()%0A    humidity = read_humi(bus)%0A    time.sleep(0.3)%0A    cTemp = read_temp(bus)%0A    print %22Relative Humidity is : %25.2f %25%25%22 %25humidity%0A    print %22Temperature in Celsius is : %25.2f C%22 %25cTemp%0A

Create si7021.py