Skip to content

Commit 8975fae

Browse files
committed
fix #19 with proper struct unpack
tested with simulation: # 0xE1 / 0xE2 dig_H2 [7:0] / [15:8] signed short # 0xE3 dig_H3 [7:0] unsigned char # 0xE4 / 0xE5[3:0] dig_H4 [11:4] / [3:0] signed short # 0xE5[7:4] / 0xE6 dig_H5 [3:0] / [11:4] signed short # 0xE7 dig_H6 signed char >>> coeff = [ 0x12, 0xFF, 0xAA, 0xEE, 0x46, 0xCC, 0x88 ] >>> coeff = list(struct.unpack('<hBbBbb', bytes(coeff))) >>> float(coeff[0]) # 0xFF12 -> -238.0 -238.0 >>> float(coeff[1]) # 0xAA -> 170.0 170.0 >>> float((coeff[2] << 4) | (coeff[3] & 0xF)) # 0xEE6 -> -282.0 -282.0 >>> float((coeff[4] << 4) | (coeff[3] >> 4)) # 0xCC4 -> -828.0 -828.0 >>> float(coeff[5]) # 0x88 -> -120.0 -120.0 >>>
1 parent a2d13f1 commit 8975fae

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

adafruit_bme280.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def _read_coefficients(self):
414414
self._humidity_calib = [0]*6
415415
self._humidity_calib[0] = self._read_byte(_BME280_REGISTER_DIG_H1)
416416
coeff = self._read_register(_BME280_REGISTER_DIG_H2, 7)
417-
coeff = list(struct.unpack('<hBBBBb', bytes(coeff)))
417+
coeff = list(struct.unpack('<hBbBbb', bytes(coeff)))
418418
self._humidity_calib[1] = float(coeff[0])
419419
self._humidity_calib[2] = float(coeff[1])
420420
self._humidity_calib[3] = float((coeff[2] << 4) | (coeff[3] & 0xF))

0 commit comments

Comments
 (0)