@@ -23,22 +23,22 @@ def __init__(self):
23
23
self .i2c = Adafruit_I2C (self .address )
24
24
25
25
def readUserRegister (self ):
26
- # Read a byte
27
- value = self .i2c .readU8 (self .READ_USER_REG )
28
-
29
- return value
26
+ "Read the user register byte"
27
+ return self .i2c .readU8 (self .READ_USER_REG )
30
28
31
29
def readTemperatureData (self ):
30
+ "Read 3 temperature bytes from the sensor"
32
31
# value[0], value[1]: Raw temperature data
33
32
# value[2]: CRC
34
33
value = self .i2c .readList (self .TRIGGER_TEMP_MEASURE_HOLD , 3 )
35
34
35
+ # CRC Check
36
36
if not self .crc8check (value ):
37
37
return - 255
38
38
39
39
rawTempData = ( value [0 ] << 8 ) + value [1 ]
40
40
41
- # Zero out the status bits but keep them in place
41
+ # Clear the status bits
42
42
rawTempData = rawTempData & 0xFFFC ;
43
43
44
44
# Calculate the actual temperature
@@ -47,16 +47,18 @@ def readTemperatureData(self):
47
47
return actualTemp
48
48
49
49
def readHumidityData (self ):
50
+ "Read 3 humidity bytes from the sensor"
50
51
# value[0], value[1]: Raw relative humidity data
51
52
# value[2]: CRC
52
53
value = self .i2c .readList (self .TRIGGER_HUMD_MEASURE_HOLD , 3 )
53
54
55
+ # CRC Check
54
56
if not self .crc8check (value ):
55
57
return - 255
56
58
57
59
rawRHData = ( value [0 ] << 8 ) + value [1 ]
58
60
59
- # Zero out the status bits but keep them in place
61
+ # Clear the status bits
60
62
rawRHData = rawRHData & 0xFFFC ;
61
63
62
64
# Calculate the actual RH
@@ -65,6 +67,8 @@ def readHumidityData(self):
65
67
return actualRH
66
68
67
69
def crc8check (self , value ):
70
+ "Calulate the CRC8 for the data received"
71
+ # Ported from Sparkfun Arduino HTU21D Library: https://github.com/sparkfun/HTU21D_Breakout
68
72
remainder = ( ( value [0 ] << 8 ) + value [1 ] ) << 8
69
73
remainder |= value [2 ]
70
74
0 commit comments