def __init__(self): # First, check to see if there is a BME680 on the I2C bus try: self.bus.write_byte(0x76, 0) except IOError: print('BME680 not found on 0x76, trying 0x77') else: self.readfrom = 'bme680primary' # If we didn't find it on 0x76, look on 0x77 if self.readfrom == 'unset': try: self.bus.write_byte(0x77, 0) except IOError: print('BME680 not found on 0x77') else: self.readfrom = 'bme680secondary' # If no BME680, is there a Sense HAT? if self.readfrom == 'unset': try: self.bus.write_byte(0x5F, 0) except: print('Sense HAT not found') else: self.readfrom = 'sense-hat' print('Using Sense HAT for readings (no gas measurements)') # Import the sense hat methods import sense_hat_air_quality from hts221 import HTS221 self.sense_hat_reading = lambda: sense_hat_air_quality.get_readings(HTS221()) else: print('Using BME680 for readings') # Import the BME680 methods self.sensor = BME680(self.readfrom) # Next, check if there is a 1-wire temperature sensor (e.g. DS18B20) if self.readfrom == 'unset': if os.environ.get('BALENASENSE_1WIRE_SENSOR_ID') != None: sensor_id = os.environ['BALENASENSE_1WIRE_SENSOR_ID'] else: sensor_id = None try: self.sensor = W1THERM(sensor_id) except: print('1-wire sensor not found') else: self.readfrom = '1-wire' print('Using 1-wire for readings (temperature only)') # If this is still unset, no sensors were found; quit! if self.readfrom == 'unset': print('No suitable sensors found! Exiting.') sys.exit()
def sample(self): if self.readfrom == 'sense-hat': return self.apply_offsets( sense_hat_air_quality.get_readings(self.sensor)) else: return self.apply_offsets(self.sensor.get_readings(self.sensor))
def __init__(self): # First, check for enviro plus hat (since it also has BME on 0x76) try: self.bus.write_byte(0x23, 0) # test if we can connect to ADS1015 except IOError: print('Enviro Plus hat not found') # Fix issue of LTR559 not found print('SUPSPECT USING CHEAP CHINESE BME680 :)') else: try: self.sensor = ENVIROPLUS() print('Found Enviro+ Hat') self.readfrom = 'enviroplus' except RuntimeError: # Fix issue of LTR559 not found print('SUPSPECT USING CHEAP CHINESE BME680 :)') # Next, check to see if there is a BME680 on the I2C bus if self.readfrom == 'unset': try: self.bus.write_byte(0x76, 0) except IOError: print('BME680 not found on 0x76, trying 0x77') else: print('BME680 found on 0x76') self.readfrom = 'bme680primary' self.sensor = BME680(self.readfrom) # If we didn't find it on 0x76, look on 0x77 if self.readfrom == 'unset': try: self.bus.write_byte(0x77, 0) except IOError: print('BME680 not found on 0x77') else: print('BME680 found on 0x77') self.readfrom = 'bme680secondary' self.sensor = BME680(self.readfrom) # If no BME680, is there a Sense HAT? if self.readfrom == 'unset': try: self.bus.write_byte(0x5F, 0) except: print('Sense HAT not found') else: self.readfrom = 'sense-hat' print('Using Sense HAT for readings (no gas measurements)') # Import the sense hat methods import sense_hat_air_quality from hts221 import HTS221 self.sense_hat_reading = lambda: sense_hat_air_quality.get_readings( HTS221()) # Next, check if there is a 1-wire temperature sensor (e.g. DS18B20) if self.readfrom == 'unset': if os.environ.get('BALENASENSE_1WIRE_SENSOR_ID') != None: sensor_id = os.environ['BALENASENSE_1WIRE_SENSOR_ID'] else: sensor_id = None try: self.sensor = W1THERM(sensor_id) except: print('1-wire sensor not found') else: self.readfrom = '1-wire' print('Using 1-wire for readings (temperature only)') # If this is still unset, no sensors were found; quit! if self.readfrom == 'unset': print('No suitable sensors found! Exiting.') sys.exit()