#!/usr/bin/python
# -*- coding: UTF-8 -*-
import time, smbus
SHT31_I2CADDR = 0x44
bus = smbus.SMBus(0)
# SHT31D Registers

SHT31_MEAS_HIGHREP_STRETCH = 0x2C06
SHT31_MEAS_MEDREP_STRETCH = 0x2C0D
SHT31_MEAS_LOWREP_STRETCH = 0x2C10
SHT31_MEAS_HIGHREP = 0x2400
SHT31_MEAS_MEDREP = 0x240B
SHT31_MEAS_LOWREP = 0x2416
SHT31_READSTATUS = 0xF32D
SHT31_CLEARSTATUS = 0x3041
SHT31_SOFTRESET = 0x30A2
SHT31_HEATER_ON = 0x306D
SHT31_HEATER_OFF = 0x3066


def _crc8(buffer):
        """ Polynomial 0x31 (x8 + x5 +x4 +1) """

        polynomial = 0x31;
        crc = 0xFF;

        index = 0
        for index in range(0, len(buffer)):
            crc ^= buffer[index]
            for i in range(8, 0, -1):
                if crc & 0x80:
                    crc = (crc << 1) ^ polynomial
                else:
                    crc = (crc << 1)
        return crc & 0xFF


def readTempHum():
        bus.write_byte_data(SHT31_I2CADDR,SHT31_MEAS_HIGHREP >> 8, SHT31_MEAS_HIGHREP & 0xFF)
        time.sleep(0.015)
        buffer = bus.read_i2c_block_data(SHT31_I2CADDR, 0, 6)

        if buffer[2] != _crc8(buffer[0:2]):
            return (float("nan"), float("nan"))

        rawTemperature = buffer[0] << 8 | buffer[1]
        temperature = 175.0 * rawTemperature / 0xFFFF - 45.0

        if buffer[5] != _crc8(buffer[3:5]):
            return (float("nan"), float("nan"))

        rawHumidity = buffer[3] << 8 | buffer[4]
        humidity = 100.0 * rawHumidity / 0xFFFF

        return (temperature, humidity)

d39471b4a07c18a2710121c1a3b53642f4afd1d8
<mask token>


def readTempHum():
    bus.write_byte_data(SHT31_I2CADDR, SHT31_MEAS_HIGHREP >> 8, 
        SHT31_MEAS_HIGHREP & 255)
    time.sleep(0.015)
    buffer = bus.read_i2c_block_data(SHT31_I2CADDR, 0, 6)
    if buffer[2] != _crc8(buffer[0:2]):
        return float('nan'), float('nan')
    rawTemperature = buffer[0] << 8 | buffer[1]
    temperature = 175.0 * rawTemperature / 65535 - 45.0
    if buffer[5] != _crc8(buffer[3:5]):
        return float('nan'), float('nan')
    rawHumidity = buffer[3] << 8 | buffer[4]
    humidity = 100.0 * rawHumidity / 65535
    return temperature, humidity

<mask token>


def _crc8(buffer):
    """ Polynomial 0x31 (x8 + x5 +x4 +1) """
    polynomial = 49
    crc = 255
    index = 0
    for index in range(0, len(buffer)):
        crc ^= buffer[index]
        for i in range(8, 0, -1):
            if crc & 128:
                crc = crc << 1 ^ polynomial
            else:
                crc = crc << 1
    return crc & 255


def readTempHum():
    bus.write_byte_data(SHT31_I2CADDR, SHT31_MEAS_HIGHREP >> 8, 
        SHT31_MEAS_HIGHREP & 255)
    time.sleep(0.015)
    buffer = bus.read_i2c_block_data(SHT31_I2CADDR, 0, 6)
    if buffer[2] != _crc8(buffer[0:2]):
        return float('nan'), float('nan')
    rawTemperature = buffer[0] << 8 | buffer[1]
    temperature = 175.0 * rawTemperature / 65535 - 45.0
    if buffer[5] != _crc8(buffer[3:5]):
        return float('nan'), float('nan')
    rawHumidity = buffer[3] << 8 | buffer[4]
    humidity = 100.0 * rawHumidity / 65535
    return temperature, humidity

<mask token>
SHT31_I2CADDR = 68
bus = smbus.SMBus(0)
SHT31_MEAS_HIGHREP_STRETCH = 11270
SHT31_MEAS_MEDREP_STRETCH = 11277
SHT31_MEAS_LOWREP_STRETCH = 11280
SHT31_MEAS_HIGHREP = 9216
SHT31_MEAS_MEDREP = 9227
SHT31_MEAS_LOWREP = 9238
SHT31_READSTATUS = 62253
SHT31_CLEARSTATUS = 12353
SHT31_SOFTRESET = 12450
SHT31_HEATER_ON = 12397
SHT31_HEATER_OFF = 12390


def _crc8(buffer):
    """ Polynomial 0x31 (x8 + x5 +x4 +1) """
    polynomial = 49
    crc = 255
    index = 0
    for index in range(0, len(buffer)):
        crc ^= buffer[index]
        for i in range(8, 0, -1):
            if crc & 128:
                crc = crc << 1 ^ polynomial
            else:
                crc = crc << 1
    return crc & 255


def readTempHum():
    bus.write_byte_data(SHT31_I2CADDR, SHT31_MEAS_HIGHREP >> 8, 
        SHT31_MEAS_HIGHREP & 255)
    time.sleep(0.015)
    buffer = bus.read_i2c_block_data(SHT31_I2CADDR, 0, 6)
    if buffer[2] != _crc8(buffer[0:2]):
        return float('nan'), float('nan')
    rawTemperature = buffer[0] << 8 | buffer[1]
    temperature = 175.0 * rawTemperature / 65535 - 45.0
    if buffer[5] != _crc8(buffer[3:5]):
        return float('nan'), float('nan')
    rawHumidity = buffer[3] << 8 | buffer[4]
    humidity = 100.0 * rawHumidity / 65535
    return temperature, humidity

import time, smbus
SHT31_I2CADDR = 68
bus = smbus.SMBus(0)
SHT31_MEAS_HIGHREP_STRETCH = 11270
SHT31_MEAS_MEDREP_STRETCH = 11277
SHT31_MEAS_LOWREP_STRETCH = 11280
SHT31_MEAS_HIGHREP = 9216
SHT31_MEAS_MEDREP = 9227
SHT31_MEAS_LOWREP = 9238
SHT31_READSTATUS = 62253
SHT31_CLEARSTATUS = 12353
SHT31_SOFTRESET = 12450
SHT31_HEATER_ON = 12397
SHT31_HEATER_OFF = 12390


def _crc8(buffer):
    """ Polynomial 0x31 (x8 + x5 +x4 +1) """
    polynomial = 49
    crc = 255
    index = 0
    for index in range(0, len(buffer)):
        crc ^= buffer[index]
        for i in range(8, 0, -1):
            if crc & 128:
                crc = crc << 1 ^ polynomial
            else:
                crc = crc << 1
    return crc & 255


def readTempHum():
    bus.write_byte_data(SHT31_I2CADDR, SHT31_MEAS_HIGHREP >> 8, 
        SHT31_MEAS_HIGHREP & 255)
    time.sleep(0.015)
    buffer = bus.read_i2c_block_data(SHT31_I2CADDR, 0, 6)
    if buffer[2] != _crc8(buffer[0:2]):
        return float('nan'), float('nan')
    rawTemperature = buffer[0] << 8 | buffer[1]
    temperature = 175.0 * rawTemperature / 65535 - 45.0
    if buffer[5] != _crc8(buffer[3:5]):
        return float('nan'), float('nan')
    rawHumidity = buffer[3] << 8 | buffer[4]
    humidity = 100.0 * rawHumidity / 65535
    return temperature, humidity

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import time, smbus
SHT31_I2CADDR = 0x44
bus = smbus.SMBus(0)
# SHT31D Registers

SHT31_MEAS_HIGHREP_STRETCH = 0x2C06
SHT31_MEAS_MEDREP_STRETCH = 0x2C0D
SHT31_MEAS_LOWREP_STRETCH = 0x2C10
SHT31_MEAS_HIGHREP = 0x2400
SHT31_MEAS_MEDREP = 0x240B
SHT31_MEAS_LOWREP = 0x2416
SHT31_READSTATUS = 0xF32D
SHT31_CLEARSTATUS = 0x3041
SHT31_SOFTRESET = 0x30A2
SHT31_HEATER_ON = 0x306D
SHT31_HEATER_OFF = 0x3066


def _crc8(buffer):
        """ Polynomial 0x31 (x8 + x5 +x4 +1) """

        polynomial = 0x31;
        crc = 0xFF;

        index = 0
        for index in range(0, len(buffer)):
            crc ^= buffer[index]
            for i in range(8, 0, -1):
                if crc & 0x80:
                    crc = (crc << 1) ^ polynomial
                else:
                    crc = (crc << 1)
        return crc & 0xFF


def readTempHum():
        bus.write_byte_data(SHT31_I2CADDR,SHT31_MEAS_HIGHREP >> 8, SHT31_MEAS_HIGHREP & 0xFF)
        time.sleep(0.015)
        buffer = bus.read_i2c_block_data(SHT31_I2CADDR, 0, 6)

        if buffer[2] != _crc8(buffer[0:2]):
            return (float("nan"), float("nan"))

        rawTemperature = buffer[0] << 8 | buffer[1]
        temperature = 175.0 * rawTemperature / 0xFFFF - 45.0

        if buffer[5] != _crc8(buffer[3:5]):
            return (float("nan"), float("nan"))

        rawHumidity = buffer[3] << 8 | buffer[4]
        humidity = 100.0 * rawHumidity / 0xFFFF

        return (temperature, humidity)
