Closed Kampi closed 4 years ago
Are you sure the value you're getting (15) isn't meant to be the gas range? Also, why do you think that it should be -1?
Are you sure the value you're getting (15) isn't meant to be the gas range? Also, why do you think that it should be -1?
Because it is a signed value and signed values use the highest bit for the sign.
Oh yeah, you're totally right.
@Kampi _read_byte
returns the raw untyped, unsigned byte from the register so you will need to either use unpack
to make it signed or do the conversion from two's complement to a signed type yourself
I checked out the Adafruit Circuit Python Module for the BME680 sensor from
https://pypi.org/project/adafruit-circuitpython-bme680/#files
to compare the results with my C driver for the BME680. I add some code to the Adafruit library to print the calibration value for the range switching error in the Adafruit library and I got the result15.0
When I read the whole register at address 0x04, I got the result 243 which is 1111 0011. Bosch writes the following in the device datasheet (Page 22):
So I take the upper nibble of the byte 243, which is 1111, and handle this as a signed 4-bit value which should be -1 and not 15.