예제 #1
0
    def initialize_input(self):
        import adafruit_ccs811
        from adafruit_extended_bus import ExtendedI2C

        self.sensor = adafruit_ccs811.CCS811(
            ExtendedI2C(self.input_dev.i2c_bus),
            address=int(str(self.input_dev.i2c_location), 16))
예제 #2
0
def main(args):
    aio = Client('ryhajlo', 'b5fe0936d9a84629a2d49cd45858fc67')
    CCS811_RESET_GPIO = 17
    GPIO.setup(CCS811_RESET_GPIO, GPIO.OUT)
    GPIO.output(CCS811_RESET_GPIO, True)

    i2c_bus = busio.I2C(board.SCL, board.SDA)
    try:
        ccs811_sensor = adafruit_ccs811.CCS811(i2c_bus)

        while not ccs811_sensor.data_ready:
            pass
        temp = ccs811_sensor.temperature
        ccs811_sensor.temp_offset = temp - 25.0
        print("CCS811 temperature offset: " + str(temp))
        # Read three times
        for x in range(0, 3):
            print("Reading " + str(x))
            while not ccs811_sensor.data_ready:
                pass
            eco2 = ccs811_sensor.eco2
            tvoc = ccs811_sensor.tvoc
            temperature = ccs811_sensor.temperature
            time.sleep(0.5)
        while True:
            print("Gathering Data")
            gather_data(aio, ccs811_sensor)
            print("Sleeping for 60 seconds")
            time.sleep(60)
    except RuntimeError:
        GPIO.output(CCS811_RESET_GPIO, False)
        sys.exit("Resetting CCS811")
예제 #3
0
    def __init__(self, mode=None):
        i2c = busio.I2C(board.SCL, board.SDA)
        self.sensor = adafruit_ccs811.CCS811(i2c)

        if mode:
            print('Modificando modo de CJMCU811 a:', mode)
            self.sensor.drive_mode(mode)
예제 #4
0
    def __init__(self):

        self.lastGoodMeasured = dict(temp=20, humi=30, co2=800)
        self.temperatureBuffer = CircularBuffer(size=20)

        try:
            #installed with
            #sudo pip3 install adafruit-circuitpython-ccs811
            import board
            import busio
            import adafruit_ccs811

            i2c = busio.I2C(board.SCL, board.SDA)
            ccs811 = adafruit_ccs811.CCS811(i2c)

            # Wait for the sensor to be ready and calibrate the thermistor
            i = 0
            while not ccs811.data_ready and i < 10000:
                i = i + 1
                pass

            self.ccs811 = ccs811

        except ImportError as e:
            print("Error loading Adafruit_CCS811: {0}:{1}".format(
                e.__class__.__name__, e.message))
            return None
예제 #5
0
def init_sensors(motion_function):
    global LIGHT_SENSOR
    global CO2_SENSOR

    print("Setting GPIO mode.")
    # Use GPIO numbers instead of pin numbers
    GPIO.setmode(GPIO.BCM)

    ### Motion Sensor ###
    print("Initializing MOTION sensor.")
    # Init the motion sensor
    GPIO.setup(MOTION_SENSOR_PIN, GPIO.IN)

    # We need to wait until the sensor is ready.
    print("Waiting for the MOTION sensor.")
    #while GPIO.input(MOTION_SENSOR_PIN) != 0:
    #    time.sleep(0.1)

    # Add a callback function to be triggered everytime the
    # sensor detects motion and falls back again
    GPIO.add_event_detect(MOTION_SENSOR_PIN,
                          GPIO.BOTH,
                          callback=motion_function)

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

    ### CO2 Sensor ###
    CO2_SENSOR = adafruit_ccs811.CCS811(i2c)
    while not CO2_SENSOR.data_ready:
        time.sleep(0.1)

    ### Light Sensor ###
    LIGHT_SENSOR = adafruit_tsl2561.TSL2561(i2c)
    LIGHT_SENSOR.enabled = True
예제 #6
0
 def initalize(self):
     LOGGER.debug("Resetting %s", self.NAME)
     self._ccs811.reset()
     time.sleep(0.5)
     LOGGER.debug("Initializing %s", self.NAME)
     self._ccs811 = adafruit_ccs811.CCS811(self._i2c)
     self.starting_time = datetime.now()
     LOGGER.debug("%s startedt at %s", self.NAME, self.starting_time)
예제 #7
0
    def __init__(self, busio, envirophat, lcd, backlight, board,
                 adafruit_ccs811):
        self.unit = 'hPa'
        self.light = envirophat.light
        self.weather = envirophat.weather
        self.motion = envirophat.motion
        self.analog = envirophat.analog
        self.backlight = backlight
        self.lcd = lcd

        i2c_bus = busio.I2C(board.SCL, board.SDA)
        self.ccs811 = adafruit_ccs811.CCS811(i2c_bus)
        self.views = ['temp_press', 'gas', 'co2_voc', 'light']
        self.current_view = 0
        self.prepare_lcd()

        self.backlight.rgb(255, 255, 255)
예제 #8
0
def read_atm():
    try:
        i2c = busio.I2C(board.SCL, board.SDA)
        ccs811 = adafruit_ccs811.CCS811(i2c)

        while not ccs811.data_ready:  # Wait for the sensor to be ready and calibrate the thermistor
            return -9999, -9999, -9999
        if ccs811.data_ready:
            temp = ccs811.temperature  # deg C
            voc = ccs811.tvoc  # PPM
            eco2 = ccs811.eco2  # PPM

            return temp, voc, eco2
    except Exception as e:
        print("Read atm failed.")
        print(e)
        return -9999, -9999, -9999
예제 #9
0
    def __init__(self):
        self._checkSensors = None
        self._ccs811_reset = digitalio.DigitalInOut(board.D18)
        self._ccs811_reset.direction = digitalio.Direction.OUTPUT
        self.init_ccs811()

        self._i2c_bus = busio.I2C(board.SCL, board.SDA)
        self._ccs811 = adafruit_ccs811.CCS811(self._i2c_bus, address=0x5B)
        self._bme280 = adafruit_bme280.Adafruit_BME280_I2C(self._i2c_bus,
                                                           address=0x76)
        self.R_PIN = 8
        self.G_PIN = 7
        self.B_PIN = 25
        self.FAN_PIN = 12
        self.LIGHT_PIN = 16
        self.pgpio = pigpio.pi()
        self.pgpio.set_PWM_frequency(self.LIGHT_PIN, 120)
        self.pgpio.set_PWM_frequency(self.FAN_PIN, 25000)
        self.pgpio.set_PWM_dutycycle(self.FAN_PIN, 50)
예제 #10
0
    def _init_sensor(self):
        """
        Inits driver and tries to communicate.
        Imports the real driver only on target platform.
        """
        import adafruit_ccs811
        import board
        import busio  # pylint: disable=import-outside-toplevel
        try:
            i2c = busio.I2C(board.SCL, board.SDA)
            self._sensor_driver = adafruit_ccs811.CCS811(i2c)

            # wait for the sensor to be ready - try max 3 times
            i = 0
            while not self._sensor_driver.data_ready and i <= 3:
                i += 1
                time.sleep(1)
        except Exception as error:
            self._logger.error("CCS811: can not be initialized - %s", str(error))
            return
예제 #11
0
 def __init__(self):
     self.i2c = busio.I2C(board.SCL, board.SDA)
     self.ccs811 = adafruit_ccs811.CCS811(i2c)
예제 #12
0
import busio
import adafruit_ccs811
import time
from board import *

print("Starting up CCS811 Sensor")
i2c_bus = busio.I2C(SCL, SDA)
sensor = adafruit_ccs811.CCS811(i2c_bus)

while True:
    try:
        if sensor.data_ready:
            timestamp = time.strftime("%m/%d/%Y %H:%M:%S", time.localtime())
            print(
                f"[{timestamp}] C02: {sensor.eco2} ppm, TVOC: {sensor.tvoc} ppm, Temperature: {round(sensor.temperature)}°C"
            )
    except Exception as error:
        print(error)
예제 #13
0
    def __init__(self, mode=None):
        i2c = busio.I2C(board.SCL, board.SDA)
        self.sensor = adafruit_ccs811.CCS811(i2c)

        if mode:
            self.sensor.drive_mode(mode)
import time

from board import SCL, SDA
import busio

import adafruit_ccs811

i2c_bus = busio.I2C(SCL, SDA)

ccs = adafruit_ccs811.CCS811(i2c_bus)

#wait for the sensor to be ready and calibrate the thermistor
while not ccs.data_ready:
    pass
temp = ccs.temperature
ccs.temp_offset = temp - 25.0

while True:
    print("CO2: ", ccs.eco2, " TVOC:", ccs.tvoc, " temp:", ccs.temperature)
    time.sleep(.5)
예제 #15
0
        ultraDistance = echoLength * DIST_CONV_FACTOR
        
    # Returns appropriate distance
    if (ultrasonicFail):
        ultraDistance = -1
    else:
        ultraDistance = echoLength * DIST_CONV_FACTOR
    return ultraDistance


### Configuration
print('Configuration has begun.')

## I2C setup (Air quality and pressure sensors)
i2c_bus = busio.I2C(board.SCL, board.SDA)
ccs811 = adafruit_ccs811.CCS811(i2c_bus, AIRQ_SENS_ADDRESS)
presSensor = adafruit_mpl3115a2.MPL3115A2(i2c_bus, address=PRES_SENS_ADDRESS)
presSensor.sealevel_pressure = SEA_LEVEL_PRES
print('I2C has been configured.')

## Camera setup
print('Configuring the camera.')
# Setup the UART 
uart = serial.Serial(UART_PORT, baudrate=UART_BAUD_RATE, timeout=UART_TIMEOUT)

# Setup VC0706 camera
vc0706 = adafruit_vc0706.VC0706(uart)
 
# Print the version string from the camera.
print('VC0706 version:')
print(vc0706.version)
예제 #16
0
lcd_d6 = digitalio.DigitalInOut(board.D22)
lcd_d5 = digitalio.DigitalInOut(board.D24)
lcd_d4 = digitalio.DigitalInOut(board.D25)
lcd_columns = 20
lcd_rows = 4
lcd = characterlcd.Character_LCD_Mono(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6,
                                      lcd_d7, lcd_columns, lcd_rows)

# initialize multiplexer board
tca_multi = TCA.TCA9548A(i2c)

# initialize saffron_grow_sensors
# tca_multi[1] = ADS1115, bme680, ccs811
ads1115 = ADS.ADS1115(tca_multi[1])
bme680_1 = BME.Adafruit_BME680_I2C(tca_multi[1])
ccs811 = CCS.CCS811(tca_multi[1])
# chan0 = AnalogIn(ads1115, ADS.P0)
chan1 = AnalogIn(ads1115, ADS.P1)
chan2 = AnalogIn(ads1115, ADS.P2)

while True:
    try:
        lcd.clear()
        temp_c_room = round(bme680_1.temperature, 1)
        temp_f_room = round(((9 / 5) * temp_c_room + 32), 1)
        rh_room = round(bme680_1.humidity, 1)
        # coir_vwc = round(get_soil_moisture(chan0.voltage), 1)
        coir50_vwc = round(get_soil_moisture(chan1.voltage), 1)
        rockwool_vwc = round(get_soil_moisture(chan2.voltage), 1)

        # This sensor can malfunction and throw and error, so
 def __init__(self):
     self.i2c = busio.I2C(board.SCL, board.SDA)
     self.ccs5A = adafruit_ccs811.CCS811(self.i2c, 0x5a)
     self.ccs5B = adafruit_ccs811.CCS811(self.i2c, 0x5b)
예제 #18
0
# indoors and the main producers of CO2 are humans#
#
# author: philippti
# date: 20.11.2020
"""
==============================================================================================================================================================================================
"""
""" imports """

import board  # CircuitPython module used to define id's for available Pins
import busio  # python module supporting serial protocols
import adafruit_ccs811  # importing the module for interacting with the breakout board and the sensor
""" initializing the sensor and board """

i2c = busio.I2C(
    board.SCL, board.SDA
)  # initialize the I2C Bus of the Pi, use the board method to assign the right GPIO (general purpse input output) pins
ccs811 = adafruit_ccs811.CCS811(
    i2c
)  # initialize the sensor using the module for the breakout board provided by Adafruit
""" functions """


def readout():  # simple method to readout the values of the sensor

    co2 = ccs811.eco2  # storing the equivalent CO2 concentration in the air
    tvoc = ccs811.tvoc  # tvoc: total volatile organic compounds
    temp = ccs811.temperature  # air temperature

    return co2, tvoc, temp  # return the three values as a tuple
예제 #19
0
    def __init__(self):
        ### Configuration
        print('Configuration has begun.')

        ## I2C setup (Air quality and pressure sensors)
        self.i2c_bus = busio.I2C(board.SCL, board.SDA)
        self.ccs811 = adafruit_ccs811.CCS811(self.i2c_bus,
                                             Sensors.AIRQ_SENS_ADDRESS)
        self.presSensor = adafruit_mpl3115a2.MPL3115A2(
            self.i2c_bus, address=Sensors.PRES_SENS_ADDRESS)
        self.presSensor.sealevel_pressure = Sensors.SEA_LEVEL_PRES
        print('I2C has been configured.')

        ## Camera setup
        print('Configuring the camera.')
        # Setup the UART
        self.uart = serial.Serial(Sensors.UART_PORT,
                                  baudrate=Sensors.UART_BAUD_RATE,
                                  timeout=Sensors.UART_TIMEOUT)

        # Setup VC0706 camera
        self.vc0706 = adafruit_vc0706.VC0706(self.uart)

        # Print the version string from the camera.
        print('VC0706 version:')
        print(self.vc0706.version)

        # Set the image size.
        self.vc0706.image_size = adafruit_vc0706.IMAGE_SIZE_640x480

        # Note you can also read the property and compare against those values to see the current size:
        imageSize = self.vc0706.image_size
        if imageSize == adafruit_vc0706.IMAGE_SIZE_640x480:
            print('Using 640x480 size image.')
        elif imageSize == adafruit_vc0706.IMAGE_SIZE_320x240:
            print('Using 320x240 size image.')
        elif imageSize == adafruit_vc0706.IMAGE_SIZE_160x120:
            print('Using 160x120 size image.')
        print('Camera has been configured.')

        ## Ultrasonic sensor setup
        self.echoPin = gpiozero.DigitalInputDevice(Sensors.ULTRA_ECHO_PIN_NUM)
        self.trigPin = gpiozero.DigitalOutputDevice(Sensors.ULTRA_TRIG_PIN_NUM)

        self.trigPin.off()
        print('Ultrasonic sensor has been configured.')

        ## Humidity sensor setup
        self.humidSensor = Adafruit_DHT.DHT22
        self.humidPin = Sensors.HUMID_PIN_NUM
        print('Humidity sensor has been configured.')

        ## SPI setup
        # Sets up MCP3202 ADCs
        self.solarIrradADC = gpiozero.MCP3202(
            channel=0,
            differential=True,
            select_pin=Sensors.SOLAR_IRRAD_SEL_PIN_NUM)
        self.powerOutADC = gpiozero.MCP3202(
            channel=0,
            differential=True,
            select_pin=Sensors.POWER_OUT_SEL_PIN_NUM)
        self.surfTempADC0 = gpiozero.MCP3208(channel=0,
                                             differential=False,
                                             select_pin=13)
        self.surfTempADC1 = gpiozero.MCP3208(channel=1,
                                             differential=False,
                                             select_pin=13)
        self.surfTempADC2 = gpiozero.MCP3208(channel=2,
                                             differential=False,
                                             select_pin=13)
        self.surfTempADC3 = gpiozero.MCP3208(channel=3,
                                             differential=False,
                                             select_pin=13)
        self.surfTempADC4 = gpiozero.MCP3208(channel=4,
                                             differential=False,
                                             select_pin=13)
        self.surfTempADC5 = gpiozero.MCP3208(channel=5,
                                             differential=False,
                                             select_pin=13)
        print('SPI ADCs have been configured.')

        ######### Need code for MCP3208 ADCs

        ## Wait for the AQ sensor to be ready, then wait another few seconds for things to settle
        print('Waiting for sensors to be ready.')
        while not self.ccs811.data_ready:
            pass
        time.sleep(Sensors.INIT_WAIT_TIME)
        print('Sensors ready. Real time loop beginning.')
        print('------------------------------------------------\n')
예제 #20
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self._ccs811 = adafruit_ccs811.CCS811(self._i2c)
     self.starting_time = datetime.now()
     self.baseline_was_set_after_start = False
예제 #21
0
import time
import board
import busio
import adafruit_ccs811

i2c = busio.I2C(board.SCL, board.SDA)
ccs811 = adafruit_ccs811.CCS811(i2c)

#If sensor isnt ready pass
while not ccs811.data_ready:
    pass
#Print out CO2 in PPM and the TVOC(Total volotile orgo#anic compounds)  , asically toxic particles
while True:
    print("CO2: {} PPM, TVOC: {} PPB, Baseline: {}, data_ready: {}, eco2: {}, error: {}, error_code: {}, reset: {}".format(ccs811.eco2,ccs811.tvoc,ccs811.baseline, ccs811.data_ready,ccs811.eco2,ccs811.error,ccs811.error_code,ccs811.reset))

    time.sleep(0.5)
예제 #22
0
def read_sensor(location="", extra="", sensor_name="", *args):
    # Try importing the modules then give-up and report to user if it fails
    import datetime
    import time
    try:
        import board
        import busio
        import adafruit_ccs811
    except:
        print("ccs811 module not installed, install using the gui")
        return None

    # set up and read the sensor
    i2c = busio.I2C(board.SCL, board.SDA)
    ccs811 = adafruit_ccs811.CCS811(i2c)
    # Wait for the sensor to be ready
    while not ccs811.data_ready:
        pass
    # Wait some more for a valid reading
    time.sleep(10)  # this value is a guess
    # start read attempts
    read_attempt = 1
    co2 = None
    while read_attempt < 5:
        try:
            #
            # Wait some more for a valid reading
            #print("Reading Sensor...")
            test_data = []
            test_val = 0
            y = 0
            for x in range(0, 50):
                time.sleep(0.25)
                co2 = ccs811.eco2
                if not co2 == 0:
                    y = y + 1
                    test_val = test_val + co2
            test_val = test_val / y
            #print("Run in test value ", test_val)
            test_data.append(["co2_run_in", test_val])
            test2_val = 0
            y = 0
            for x in range(0, 50):
                co2 = ccs811.eco2
                if not co2 == 0:
                    y = y + 1
                    test2_val = test2_val + co2
                time.sleep(0.25)
            test2_val = test2_val / y
            #print("test2 value ", test2_val)
            test_data.append(["co2_test_2", test2_val])
            # sleep while the sensor warms up
            time.sleep(20)  # this value is a guess
            test2_val = 0
            y = 0
            for x in range(0, 50):
                co2 = ccs811.eco2
                if not co2 == 0:
                    y = y + 1
                    test2_val = test2_val + co2
                time.sleep(0.25)
            test2_val = test2_val / y
            #print("after delay value ", test2_val)
            test_data.append(["co2_after_delay", test2_val])
            #
            co2 = ccs811.eco2
            tvoc = ccs811.tvoc
            if co2 == "None":
                print("--problem reading CCS811, try " + str(read_attempt))
                time.sleep(2)
                read_attempt = read_attempt + 1
            else:
                logtime = datetime.datetime.now()
                data = [['time', logtime], ['co2', co2], ['tvoc', tvoc]]
                data = data + test_data
                #print(data)
                return data
        except Exception as e:
            print("--exception while reading CCS811, try " + str(read_attempt))
            print(" -- " + str(e))
            time.sleep(2)
            read_attempt = read_attempt + 1
    return None