def __init__(self, input_dev, testing=False): super(BME280Sensor, self).__init__() self.logger = logging.getLogger("mycodo.inputs.bme280") self._altitude = None self._dew_point = None self._humidity = None self._pressure = None self._temperature = None if not testing: from Adafruit_BME280 import BME280 self.logger = logging.getLogger( "mycodo.inputs.bme280_{id}".format(id=input_dev.id)) self.i2c_address = int(str(input_dev.location), 16) self.i2c_bus = input_dev.i2c_bus self.convert_to_unit = input_dev.convert_to_unit self.sensor = BME280(address=self.i2c_address, busnum=self.i2c_bus)
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__(input_dev, testing=testing, name=__name__) self.timer = 0 # Initialize custom options self.serial_device = None # Set custom options self.setup_custom_options( INPUT_INFORMATION['custom_options'], input_dev) if not testing: from Adafruit_BME280 import BME280 import serial self.i2c_address = int(str(input_dev.i2c_location), 16) self.i2c_bus = input_dev.i2c_bus self.sensor = BME280(address=self.i2c_address, busnum=self.i2c_bus) self.serial = serial self.serial_send = None self.lock_file = "/var/lock/mycodo_ttn.lock" self.ttn_serial_error = False
def __init__(self, input_dev, testing=False): super(InputModule, self).__init__(input_dev, testing=testing, name=__name__) self.timer = 0 if not testing: from Adafruit_BME280 import BME280 import serial if input_dev.custom_options: for each_option in input_dev.custom_options.split(';'): option = each_option.split(',')[0] value = each_option.split(',')[1] if option == 'serial_device': self.serial_device = value self.i2c_address = int(str(input_dev.i2c_location), 16) self.i2c_bus = input_dev.i2c_bus self.sensor = BME280(address=self.i2c_address, busnum=self.i2c_bus) self.serial = serial self.serial_send = None self.lock_file = "/var/lock/mycodo_ttn.lock" self.ttn_serial_error = False
from Adafruit_BME280 import BME280_STANDBY_500, BME280_STANDBY_1000, BME280_STANDBY_10, BME280_STANDBY_20 import RaspiOled.oled as oled from PIL import Image from PIL import ImageDraw from PIL import ImageFont image = Image.new('1',oled.size) # make 128x64 bitmap image draw = ImageDraw.Draw(image) f = ImageFont.truetype( font='/usr/share/fonts/truetype/GenShinGothic/GenShinGothic-Monospace-Bold.ttf', size=14) oled.begin() sensor = BME280(t_mode=BME280_OSAMPLE_2, p_mode=BME280_OSAMPLE_16, h_mode=BME280_OSAMPLE_1, filter=BME280_FILTER_16, standby=BME280_STANDBY_125) #sensor = BME280() while True: temperature = sensor.read_temperature() pascals = sensor.read_pressure() hectopascals = pascals / 100 humidity = sensor.read_humidity() #print('Temp = {0:0.3f} deg C'.format(temperature)) #print('Pressure = {0:0.2f} hPa'.format(hectopascals)) #print('Humidity = {0:0.2f} %'.format(humidity)) print(temperature, humidity, hectopascals)
def initialize_input(self): from Adafruit_BME280 import BME280 self.sensor = BME280(address=int(str(self.input_dev.i2c_location), 16), busnum=self.input_dev.i2c_bus)
from Adafruit_BME280 import BME280 #I2C ADDRESSES FOR SENSORS IR_ADDRESS = 0x5B BNO_ADDRESS_A = 0x28 BNO_ADDRESS_B = 0x29 BME280_ADDRESS_A = 0x77 BME280_ADDRESS_B = 0x76 PASC2PSI = 6894.757 #TO CONVERT PASCALS TO PSI #INITIALIZE SENSORS IR_Therm = MLX90614(IR_ADDRESS) IMU_Nose = BNO055.BNO055(None, BNO_ADDRESS_A) IMU_Tail = BNO055.BNO055(None, BNO_ADDRESS_B) # PV1 = BME280(address=BME280_ADDRESS_A) PV2 = BME280(address=BME280_ADDRESS_B) #For some brilliant reason the BME280 python library requires that #temp be read before pressure can be read as the read_raw_temp function #initializes an attribut required for all other readings""" t1 = PV1.read_temperature() t2 = PV2.read_temperature() #BNO055 LIBRARY REQUIRES self.begin IMU_Nose.begin() IMU_Tail.begin() if __name__ == '__main__': while True: pressure_1 = PV1.read_pressure() / PASC2PSI pressure_2 = PV2.read_pressure() / PASC2PSI
#!/usr/bin/env python from Adafruit_BME280 import BME280 from time import sleep DELAY_BETWEEN_SENSORS = 1 SPI_BUS = 0 for j in range(20): for i in [1, 2, 3, 4, 5]: bme280SensorInstance = BME280(spi_bus=SPI_BUS, spi_dev=i, speed_hz=13) #, delay_usec = 10000) if bme280SensorInstance.sample_ok: print(f'sensor {SPI_BUS}.{i}') print(f't = {round(bme280SensorInstance.temperature,1)}') print(f'h = {round(bme280SensorInstance.humidity,1)}') print(f'p = {round(bme280SensorInstance.pressure,1)}') sleep(DELAY_BETWEEN_SENSORS) print('-' * 30) print('+' * 30)
from time import sleep from random import uniform import Adafruit_BME280.Adafruit_BME280 as BME280 # BME280 default address. BME280_I2CADDR = 0x76 # Operating Modes BME280_OSAMPLE_1 = 1 BME280_OSAMPLE_2 = 2 BME280_OSAMPLE_8 = 4 BME280_FILTER_16 = 4 try: BME280_INIT = BME280(p_mode=BME280_OSAMPLE_8, t_mode=BME280_OSAMPLE_2, h_mode=BME280_OSAMPLE_1, filter=BME280_FILTER_16, address=BME280_I2CADDR) except Exception: BME280_INIT = None logger = logging.getLogger(__name__) class Temperature: def __init__(self, unit='metric', round_to=2, init=BME280_INIT): self.unit = unit self.round_to = round_to self.temperature_last = None self.sensor = init if self.sensor is None: raise RuntimeError("BME280 does not exist.")
def initializeSensors(self): try: for x in range(0, self.connectAttempt): self.openBus(self.tcaNOSE) #OPEN CHANNEL ON TCA if (self.currentBus == self.tcaNOSE): break sleep(0.5) except IOError: print("Connection error with TCA Multiplexer") self.TCA_status = False try: self.Lidar = Lidar.Lidar_Lite() #CREATE OBJECT FOR LIDAR LITE V3 self.bus.write_quick( self.LID_ADDR) #QUICK WRITE TO TEST CONNECTION TO I2C BUS print("Lidar Ready") self.LID_status = True except IOError: print("Connection error with Lidar" ) #PRINT ERROR IF UNABLE TO CONNECT try: for x in range(0, self.connectAttempt): self.BMP = BMP280( address=self.BMP_ADDR) #CREATE OBJECT FOR BMP280 if (self.BMP.read_raw_temp()): #ATTEMPT READING FROM BMP print("BMP Ready") self.BMP_status = True break sleep(0.5) except IOError: print("Connection Error with BMP") #return 0 try: for x in range(0, self.connectAttempt): self.bus.read_byte(self.MICRO_ADDR) print("Arduino Micro Ready") self.MICRO_status = True break except IOError: print("Connection Error with Arduino Micro") try: for x in range(0, self.connectAttempt): self.openBus(self.tcaPVL) #OPEN CHANNEL ON TCA if (self.currentBus == self.tcaPVL): break sleep(0.5) except IOError: print("Connection error wit TCA Multiplexer") self.TCA_status = 0 return 0 try: for x in range(0, self.connectAttempt): self.BMEL = BME280(address=self.BME_ADDR2 ) #CREATE OBJECT FOR BME280 AT ADDRESS 2 if (self.BMEL.read_raw_temp()): print("BME LPV Ready") self.BME2_status = True break sleep(0.5) except IOError: print("Connection Error with BME2 LPV") #return 0 try: for x in range(0, self.connectAttempt): self.openBus(self.tcaPVR) #OPEN TCA CHANNEL if (self.currentBus == self.tcaPVR): break sleep(0.5) except IOError: print("Connection error with TCA Multiplexer") self.TCA_status = False return 0 try: for x in range(0, self.connectAttempt): self.Therm = MLX90614( address=self.IR_ADDR ) #CREATE OBJECT FOR MLX90614 IR THERMOMETER if (self.Therm.check_connect): #CHECK CONNECTION print("MLX90614 Ready") self.MLX_status = True break sleep(0.5) except IOError: print("Connection Error with Therm") #return 0 try: self.ADC = Adafruit_ADS1x15.ADS1115( address=self.ADC_ADDR, busnum=1) #CREATE OBJECT FOR ADS1115 ADC print("ADC Ready") self.ADC_status = True except IOError: print("Connection error with ADS ADC") #return 0 try: for x in range(0, self.connectAttempt): self.openBus(self.tcaPVR2) #OPEN CHANNEL ON TCA if (self.currentBus == self.tcaPVR2): break sleep(0.5) except IOError: print("Connection error with TCA Multiplexer") self.TCA_status = False return 0 try: for x in range(0, self.connectAttempt): self.BMER = BME280(address=self.BME_ADDR1 ) #CREATE OBJECT FOR BME280 AT ADDRESS 2 if (self.BMER.read_raw_temp()): print("BME RPV Ready") self.BME1_status = True break sleep(0.5) except IOError: print("Connection Error with BME RPV") #return 0 try: for x in range(0, self.connectAttempt): self.IMU1 = BNO055(address=self.IMU_ADDR1 ) #CREATE OBJECT FOR BNO055 AT ADDRESS 1 if ( self.IMU1.begin(mode=0x08) ): #CHECK FOR CONNECTION TO I2C BUS AND SET IMU OPR MODE (MAG DISABLED) while (self.IMU1.get_calibration_status()[1] != 3): pass #WAIT FOR GYRO CALIBRATION COMPLETE print("IMU1 Ready") self.BNO1_status = True break sleep(0.5) except IOError: print("Connection error with IMU1") #return 0 try: self.X1OFFSET = self.getOrientation(1)[1] print("IMU1 Y offset angle set") except IOError: print("IMU1 Y offset angle not set") try: self.Z1OFFSET = self.getOrientation(1)[2] print("IMU1 Z offset angle set") except IOError: print("IMU1 Z offset angle not set") try: for x in range(0, self.connectAttempt): self.IMU2 = BNO055(address=self.IMU_ADDR2 ) #CREATE OBJECT FOR BNO055 AT ADDRESS 2 if ( self.IMU2.begin(mode=0x08) ): #CHECK FOR CONNECTION TO I2C BUS AND SET IMU OPR MODE (MAG DISABLED) while (self.IMU2.get_calibration_status()[1] != 3): pass #WAIT FOR GYRO CALIBRATION COMPLETE print("IMU2 Ready") self.BNO2_status = True break sleep(0.5) except IOError: print("Connection Error with IMU2") #return 0 try: self.X2OFFSET = self.getOrientation(2)[1] print("IMU2 Y offset angle set") except IOError: print("IMU2 Y offset angle not set") try: self.Z2OFFSET = self.getOrientation(2)[2] print("IMU2 Z offset angle set") except IOError: print("IMU2 Z offset angle not set") return 1