adafruit / Adafruit_CircuitPython_BME280

CircuitPython driver for the BME280
MIT License
63 stars 42 forks source link

Potential sign problem with the calibration values for humidity #19

Closed robert-hh closed 5 years ago

robert-hh commented 5 years ago

In line 197 of the driver, the calibration constants are unpacked with

        coeff = list(struct.unpack('<hBBBBb', bytes(coeff)))

This goes into humidity_calib[3] and humidity_calib[4], which in the Bosch data sheet are told as signed quantities. Unpacking like above results in decoding them as unsigned quantities. So this line should be:

        coeff = list(struct.unpack('<hBbBbb', bytes(coeff)))

From the data sheet:

0xE4 / 0xE5[3:0] dig_H4 [11:4] / [3:0] signed short
0xE5[7:4] / 0xE6 dig_H5 [3:0] / [11:4] signed short

I have no device where the sign bit is set, so I can only simulate the behavior.

Note: I came along these lines when considering to carry over the very elegant conversion of similar data from the BME680 driver. There, the sign is considered.