示例#1
0
    def init(self):
        i2c_bus = board.I2C()

        if hasattr(self, "I2CADDR"):
            self.sensor = Adafruit_BMP280_I2C(i2c_bus, addr=self.I2CADDR)
        else:
            self.sensor = Adafruit_BMP280_I2C(i2c_bus)

        if hasattr(self, "SeaLevelPressure"):
            self.sensor.sea_level_pressure = self.SeaLevelPressure
示例#2
0
 def get_available_sensors(self):
     for ch in self.mux:
         try:
             baro = Adafruit_BMP280_I2C(i2c=ch, address=0x76)
             print(baro.pressure)
         except:
             print(f"No device at {ch}.")
示例#3
0
 def __init__(self, address=0x77):
     self.bus = busio.I2C(board.SCL, board.SDA)
     try:
         self.sensor = Adafruit_BMP280_I2C(self.bus, address=address)
     except:
         print("BME280 sensor could not initiated")
         self.sensor = None
示例#4
0
    def __init__(self):
        self.i2c_bus = busio.I2C(scl=board.SCL, sda=board.SDA)
        self.i2c_mux = TCA9548A(i2c=self.i2c_bus, address=0x70)
        self.wired_sensors = dict()

        self.bmp280_1 = Adafruit_BMP280_I2C(i2c=self.i2c_mux[0], address=0x76)
        self.bmp388 = BMP3XX_I2C(i2c=self.i2c_mux[1], address=0x77)
        self.bmp280_2 = Adafruit_BMP280_I2C(i2c=self.i2c_mux[2], address=0x76)

        self.bmp280_1.sea_level_pressure = 1013.25
        self.bmp388.sea_level_pressure = 1013.25
        self.bmp280_2.sea_level_pressure = 1013.25

        self.air_density = 1.204  # kg/m2
        self.dynamic_pressure = 0  # Pa (!)
        self.tek_pressure = 1013.25  # hPa
        self.IAS = 0  # kph
        self.QNH = 1013.25  # hPa
        self.altitude = 0  # MSL
        self.temperature = 21  # °C
示例#5
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the sensor platform."""
    try:
        # initializing I2C bus using the auto-detected pins
        i2c = I2C(board.SCL, board.SDA)
        # initializing the sensor
        bmp280 = Adafruit_BMP280_I2C(i2c, address=config[CONF_I2C_ADDRESS])
    except ValueError as error:
        # this usually happens when the board is I2C capable, but the device can't be found at the configured address
        if str(error.args[0]).startswith("No I2C device at address"):
            _LOGGER.error(
                "%s. Hint: Check wiring and make sure that the SDO pin is tied to either ground (0x76) or VCC (0x77)",
                error.args[0],
            )
            raise PlatformNotReady() from error
        _LOGGER.error(error)
        return
    # use custom name if there's any
    name = config[CONF_NAME]
    # BMP280 has both temperature and pressure sensing capability
    add_entities(
        [Bmp280TemperatureSensor(bmp280, name), Bmp280PressureSensor(bmp280, name)]
    )
示例#6
0
文件: sensor.py 项目: 2Fake/core
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the sensor platform."""
    _LOGGER.warning(
        "The Bosch BMP280 Environmental Sensor integration is deprecated and "
        "will be removed in Home Assistant Core 2022.4; "
        "this integration is removed under Architectural Decision Record 0019, "
        "more information can be found here: "
        "https://github.com/home-assistant/architecture/blob/master/adr/0019-GPIO.md"
    )

    try:
        # initializing I2C bus using the auto-detected pins
        i2c = I2C(board.SCL, board.SDA)
        # initializing the sensor
        bmp280 = Adafruit_BMP280_I2C(i2c, address=config[CONF_I2C_ADDRESS])
    except ValueError as error:
        # this usually happens when the board is I2C capable, but the device can't be found at the configured address
        if str(error.args[0]).startswith("No I2C device at address"):
            _LOGGER.error(
                "%s. Hint: Check wiring and make sure that the SDO pin is tied to either ground (0x76) or VCC (0x77)",
                error.args[0],
            )
            raise PlatformNotReady() from error
        _LOGGER.error(error)
        return
    # use custom name if there's any
    name = config[CONF_NAME]
    # BMP280 has both temperature and pressure sensing capability
    add_entities([
        Bmp280TemperatureSensor(bmp280, name),
        Bmp280PressureSensor(bmp280, name)
    ])