Skip to content

Commit a8a2266

Browse files
committed
Catch IOError when trying to get the chip ID
1 parent da98fca commit a8a2266

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

library/bme680/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ def __init__(self, i2c_addr=constants.I2C_ADDR_PRIMARY, i2c_device=None):
4242
import smbus
4343
self._i2c = smbus.SMBus(1)
4444

45-
self.chip_id = self._get_regs(constants.CHIP_ID_ADDR, 1)
46-
if self.chip_id != constants.CHIP_ID:
47-
raise RuntimeError('BME680 Not Found. Invalid CHIP ID: 0x{0:02x}'.format(self.chip_id))
45+
try:
46+
self.chip_id = self._get_regs(constants.CHIP_ID_ADDR, 1)
47+
if self.chip_id != constants.CHIP_ID:
48+
raise RuntimeError('BME680 Not Found. Invalid CHIP ID: 0x{0:02x}'.format(self.chip_id))
49+
except IOError:
50+
raise RuntimeError("Unable to identify BME680 at 0x{:02x} (IOError)".format(self.i2c_addr))
4851

4952
self.soft_reset()
5053
self.set_power_mode(constants.SLEEP_MODE)

0 commit comments

Comments
 (0)