@@ -0,0 +1,1756 @@
+    def _get_humidity_from_buffer(data):%0A        %22%22%22This function reads the first two bytes of data and returns%0A        the relative humidity in percent by using the following function:%0A        RH = -6 + (125 * (SRH / 2 %5E16))%0A        where SRH is the value read from the sensor%0A        %22%22%22%0A        unadjusted = (ord(data%5B0%5D) %3C%3C 8) + ord(data%5B1%5D)%0A        unadjusted &= SHT21._STATUS_BITS_MASK  # zero the status bits%0A        unadjusted *= 125.0%0A        unadjusted /= 1 %3C%3C 16  # divide by 2%5E16%0A        unadjusted -= 6%0A        return unadjusted%0A%0A%0Aclass SHT21Test(unittest.TestCase):%0A    %22%22%22simple sanity test.  Run from the command line with%0A    python -m unittest sht21 to check they are still good%22%22%22%0A%0A    def test_temperature(self):%0A        %22%22%22Unit test to check the checksum method%22%22%22%0A        calc_temp = SHT21._get_temperature_from_buffer(%5Bchr(99), chr(172)%5D)%0A        self.failUnless(abs(calc_temp - 21.5653979492) %3C 0.1)%0A%0A    def test_humidity(self):%0A        %22%22%22Unit test to check the humidity computation using example%0A        from the v4 datasheet%22%22%22%0A        calc_temp = SHT21._get_humidity_from_buffer(%5Bchr(99), chr(82)%5D)%0A        self.failUnless(abs(calc_temp - 42.4924) %3C 0.001)%0A%0A    def test_checksum(self):%0A        %22%22%22Unit test to check the checksum method.  Uses values read%22%22%22%0A        self.failUnless(SHT21._calculate_checksum(%5Bchr(99), chr(172)%5D, 2) == 249)%0A        self.failUnless(SHT21._calculate_checksum(%5Bchr(99), chr(160)%5D, 2) == 132)%0A%0Aif __name__ == %22__main__%22:%0A    try:%0A        with SHT21(0) as sht21:%0A            print %22Temperature: %25s%22 %25 sht21.read_temperature()%0A            print %22Humidity: %25s%22 %25 sht21.read_humidity()%0A    except IOError, e:%0A        print e%0A        print %22Error creating connection to i2c.  This must be run as root%22%0A

Create sht.py