示例#1
0
    def __init__(self, name="dome", config={}):
        # Initialise the bme280
        from adafruit_bme280 import basic as adafruit_bme280
        i2c = board.I2C()  # uses board.SCL and board.SDA
        self.active = False
        decAddress = int(config['address'], 16)
        try:
            self.bme280 = adafruit_bme280.Adafruit_BME280_I2C(
                i2c, address=decAddress)
        except ValueError:
            print("Sensor BME280 failed!", flush=True)
            self.active = False

        self.fan = False
        self.attachedFans = []
        self.temperature = -999
        self.humidity = -999
        self.pressure = -999
        self.name = name
        print(config, flush=True)
        try:
            self.monitorCadence = config['cadence']
        except KeyError:
            self.monitorCadence = 20
        self.exit = False
        self.logData = {}
示例#2
0
    def __init__(self):
        self._str_i2c_address = env.str("BME280_I2C_ADDRESS", default=None)
        self._i2c_address = None
        if self._str_i2c_address is None:
            raise ValueError("BME280: Necessary to inform sensor i2c address!")
        else:
            # Since environs lib can not handle hexadecimal numbers,
            # it is necessary to convert the hexadecimal string to int
            self._i2c_address = int(self._str_i2c_address, 16)
            print(
                "BME280: Setting sensor i2c address as 0x{:02x}".format(
                    self._i2c_address
                )
            )

        self._local_sea_level = env.float(
            "BME280_LOCAL_SEA_LEVEL", default=None
        )
        if self._local_sea_level is None:
            raise ValueError(
                "BME280: Necessary to inform location sea level pressure!"
            )

        self._i2c = board.I2C()
        self._bme280 = adafruit_bme280.Adafruit_BME280_I2C(
            i2c=self._i2c, address=self._i2c_address
        )
        self._bme280.sea_level_pressure = self._local_sea_level
        print(
            "BME280: Setting sea-level pressure as {0} hPa.".format(
                self._local_sea_level
            )
        )
示例#3
0
文件: sensors.py 项目: majuss/wladio
def init_sensors():
    import board
    from adafruit_bme280 import basic as adafruit_bme280

    from busio import I2C

    i2c = I2C(board.SCL, board.SDA)
    bme280 = None

    try:
        bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x77)
    except Exception as e:
        logger.debug('Couldnt init BME280: {}'.format(e))
        bme280 = DummySensor()

    bme280.sea_level_pressure = 1013.25

    return bme280
示例#4
0
    def __init__(self, interval=0, temp_in_f=False, pressure_in_inches=False):
        """
        ```
        interval
                    How long in seconds to sleep between returning records.
        temp_in_f
                    Return temperature in Farenheit
        pressure_in_inches
                    Return pressure in inches of mercury
        ```
        """
        self.interval = interval  # seconds between records
        self.temp_in_f = temp_in_f
        self.pressure_in_inches = pressure_in_inches
        self.last_record = 0  # timestamp at our last record

        # Create sensor object, communicating over the board's default I2C bus
        self.i2c = board.I2C()  # uses board.SCL and board.SDA
        self.bme280 = adafruit_bme280.Adafruit_BME280_I2C(self.i2c)
示例#5
0
# Update to match the mAh of your battery for more accurate readings.
# Can be MAH100, MAH200, MAH400, MAH500, MAH1000, MAH2000, MAH3000.
# Choose the closest match. Include "PackSize." before it, as shown.
battery_pack_size = PackSize.MAH400

# Setup the little red LED
led = digitalio.DigitalInOut(board.LED)
led.switch_to_output()

# Pull the I2C power pin low
i2c_power = digitalio.DigitalInOut(board.I2C_POWER_INVERTED)
i2c_power.switch_to_output()
i2c_power.value = False

# Set up the BME280 and LC709203 sensors
bme280 = adafruit_bme280.Adafruit_BME280_I2C(board.I2C())
battery_monitor = LC709203F(board.I2C())
battery_monitor.pack_size = battery_pack_size

# Collect the sensor data values and format the data
temperature = "{:.2f}".format(bme280.temperature)
temperature_f = "{:.2f}".format((bme280.temperature * (9 / 5) + 32))  # Convert C to F
humidity = "{:.2f}".format(bme280.relative_humidity)
pressure = "{:.2f}".format(bme280.pressure)
battery_voltage = "{:.2f}".format(battery_monitor.cell_voltage)
battery_percent = "{:.1f}".format(battery_monitor.cell_percent)


def go_to_sleep(sleep_period):
    # Create a an alarm that will trigger sleep_period number of seconds from now.
    time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + sleep_period)
示例#6
0
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board
from adafruit_bme280 import basic as adafruit_bme280

# Create sensor object, using the board's default I2C bus.
i2c = board.I2C()  # uses board.SCL and board.SDA
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)

# OR create sensor object, using the board's default SPI bus.
# spi = board.SPI()
# bme_cs = digitalio.DigitalInOut(board.D10)
# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs)

# change this to match the location's pressure (hPa) at sea level
bme280.sea_level_pressure = 1013.25

while True:
    print("\nTemperature: %0.1f C" % bme280.temperature)
    print("Humidity: %0.1f %%" % bme280.relative_humidity)
    print("Pressure: %0.1f hPa" % bme280.pressure)
    print("Altitude = %0.2f meters" % bme280.altitude)
    time.sleep(2)
示例#7
0
# Setting some variables for our reset pin etc.
RESET_PIN = digitalio.DigitalInOut(board.D4)

# Using extended I2C library because I created two I2C buses for my Pi
# First one is for the OLED and second (number 11) is for the temp sensor

# Modify the numbers here to match your setup

# Here take into account that your screen could be 128x32, so change that '64' with '32'
# Also some models like mine have address 0x3C in I2C, but others use 0x3D. Please check it with command like 'i2cdetect' if this value doesn't work.
i2c = I2C(1)
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3C, reset=RESET_PIN)

# My BME280 model has 0x76 address, but some others have 0x77. Check it with 'i2cdetect' if this value is not working.
i2c11 = I2C(11)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c11, address=0x76)

# This is not even needed as we don't need to calculate altitude, but
# if you need it, just adjust this parameter to your daily sea level pressure
bme280.sea_level_pressure = 1013.25

# Clear display.
oled.fill(0)
oled.show()

# Create blank image for drawing.
image = Image.new("1", (oled.width, oled.height))
draw = ImageDraw.Draw(image)

# Load a font in 2 different sizes.
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
示例#8
0
def get_voltage(pin):
    return (pin.value * 3.3) / 65536 * 2


battery_voltage = get_voltage(vbat_voltage)
print("Starting up the sensor and the battery voltage is: {:.2f}V".format(
    battery_voltage))

# We are using the PM2.5 sensor over UART, so lets get that ready to sample
reset_pin = None
uart = busio.UART(board.TX, board.RX, baudrate=9600)
pm25 = PM25_UART(uart, reset_pin)

# Create i2c object for the BME280 temp/humidity sensor
i2c = board.I2C()
bme_sensor = adafruit_bme280.Adafruit_BME280_I2C(i2c)


### Sensor Functions ###
# Returns a calculated air quality index (AQI) and category as a tuple (multiple items in a single variable)
# We ideally need a 24-hour concentration average as if you don't, you'll have a higher AQI than you expect
def calculate_aqi(pm_sensor_reading):

    # Check sensor reading using EPA breakpoint (Clow-Chigh)
    if 0.0 <= pm_sensor_reading <= 12.0:
        # AQI calculation using EPA breakpoints (Ilow-IHigh)
        aqi_val = map_range(int(pm_sensor_reading), 0, 12, 0, 50)
        aqi_cat = "Good"
    elif 12.1 <= pm_sensor_reading <= 35.4:
        aqi_val = map_range(int(pm_sensor_reading), 12, 35, 51, 100)
        aqi_cat = "Moderate"
示例#9
0
raspiPORT = 5001
m5ADDRESS = "192.168.4.100"
m5PORT = 5000

s = socket(AF_INET, SOCK_DGRAM)
s.settimeout(0.8)
s.bind((HOST, raspiPORT))

#CSV save to
path = "/home/pi/Workspace/Data/"

#i2c 設定
i2c = busio.I2C(board.SCL, board.SDA)

#bme280 インスタンス
bme280 = basic.Adafruit_BME280_I2C(board.I2C(), address=0x76)

#display インスタンス
try:
    display = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3c)
    display.fill(0)
    display.text("initializing....", 0, 0, 1)
    display.show()
except:
    print("dhisplay not found")

#ADS1115 インスタンス ADS0 24V系 P0:チラー流量 P1:チラー温度 P2:未使用 P3:未使用
#ADS1115 インスタンス ADS1 24V系 P0:エア圧 P1-3:未使用
ADS0 = ADS.ADS1115(i2c, gain=1, address=0x48)
WaterFlow1 = AnalogIn(ADS0, ADS.P0)
WaterTemp1 = AnalogIn(ADS0, ADS.P1)