コード例 #1
0
ファイル: example_gui.py プロジェクト: nv-h/i2c_env_sensors
    def __init__(self):
        self.ccs811 = CCS811()
        self.bme280 = BME280()
        p, t, h = self.bme280.get()
        self.ccs811.compensate(h, t)

        self.data_co2 = np.zeros(int(X_LIMIT/RESOLUSION), dtype=int)
        self.data_t = np.zeros(int(X_LIMIT/RESOLUSION), dtype=int)
        self.data_h = np.zeros(int(X_LIMIT/RESOLUSION), dtype=int)
        self.data_p = np.zeros(int(X_LIMIT/RESOLUSION), dtype=int)

        self.root = tkinter.Tk()
        self.root.wm_title("Embedding in Tk anim")

        self.fig = Figure()
        # FuncAnimationより前に呼ぶ必要がある
        canvas = FigureCanvasTkAgg(self.fig, master=self.root)  # A tk.DrawingArea.

        x = np.arange(0, X_LIMIT, RESOLUSION)  # x軸(固定の値)
        self.l = np.arange(0, X_LIMIT, RESOLUSION)  # 表示期間(FuncAnimationで指定する関数の引数になる)
        plt_co2 = self.fig.add_subplot(211)
        plt_co2.set_ylim([0, 4000])
        self.line_co2, = plt_co2.plot(x, self.data_co2, 'C3', label="CO2 ppm")

        h0, l0 = plt_co2.get_legend_handles_labels()
        plt_co2.legend(h0, l0, loc='upper left')

        plt_t = self.fig.add_subplot(212)
        plt_t.set_ylim([-10, 50])
        self.line_t, = plt_t.plot(x, self.data_t, 'C1', label="Celsius")

        plt_h = plt_t.twinx()
        plt_h.set_ylim([0, 100])
        self.line_h, = plt_h.plot(x, self.data_h, 'C0', label="humidity %")

        plt_p = plt_t.twinx()
        plt_p.set_ylim([900, 1200])
        self.line_p, = plt_p.plot(x, self.data_p, 'C2', label="pressure hPa")

        h1, l1 = plt_t.get_legend_handles_labels()
        h2, l2 = plt_h.get_legend_handles_labels()
        h3, l3 = plt_p.get_legend_handles_labels()
        plt_t.legend(h1+h2+h3, l1+l2+l3, loc='upper left')

        self.ani = animation.FuncAnimation(self.fig, self.animate, self.l,
            init_func=self.init, interval=int(1000*RESOLUSION), blit=False,
            )

        toolbar = NavigationToolbar2Tk(canvas, self.root)
        canvas.get_tk_widget().pack(fill='both')

        button = tkinter.Button(master=self.root, text="Quit", command=self.quit)
        button.pack()
コード例 #2
0
ファイル: monitor.py プロジェクト: Batov/air_quality_monitor
    def __init__(self, update_env=600):
        self._scd30 = SCD30(use_pin=True)
        self._ccs811 = CCS811(use_pin=True)

        self.CO2 = 0
        self.eCO2 = 0
        self.temp = 0
        self.temp_NTC = 0
        self.hum = 0
        self.TVOC = 0

        self._update_env = update_env

        gevent.spawn(self._data_loop)
        gevent.spawn(self._update_env_loop)
コード例 #3
0
ファイル: get_data.py プロジェクト: akihiro0000/co2
 def __init__(self):
     self._ccs811 = CCS811()
     self.co2_status = self.CO2_STATUS_LOW
コード例 #4
0
#!/usr/bin/env python

from time import sleep
from bme280 import BME280
from ccs811 import CCS811

ccs811 = CCS811()
bme280 = BME280()
p, t, h = bme280.get()
ccs811.compensate(h, t)

while(True):
    try:
        p, t, h = bme280.get()
        voc, co2 = ccs811.get()
        print(f"{p:7.2f} hPa, {t:6.2f} C, {h:5.2f} %, TVOC:{voc:4d} ppb, eCO2:{co2:4d} ppm")
        sleep(1)
    except OSError:
        # i2c bus somtimes cannot access
        continue
    except KeyboardInterrupt:
        break
コード例 #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from ccs811 import CCS811
from time import sleep

if __name__ == '__main__':
    sensor = CCS811(debug=True)
    sensor.begin()
    sensor.setEnvironmentalData(22.0, 40.0)

    tick = 1
    while not sensor.dataAvailable():
        sleep(0.1)

    while True:
        print("Tick: {}".format(tick))
        if not sensor.dataAvailable():
            sleep(1)
            continue
        if sensor.readAlgorithmResults() == CCS811.STAT_SUCCESS:
            print("eCO2: {} ppm, TVOC: {} ppb".format(sensor.eCO2,
                                                      sensor.TVOC))
            sensor.getDriveMode()
        else:
            print("Pending")
        sleep(2)
        tick += 1
コード例 #6
0
ファイル: main.py プロジェクト: mchobby/la-maison-pythonic
# chargement des bibliotheques
try:
    from ccs811 import CCS811
    from machine import Pin
except Exception as e:
    print(e)
    led_error(step=3)

# créer les capteurs
try:
    i2c = get_i2c()
    adc = ADC(Pin(TMP36_PIN))
    adc.atten(ADC.ATTN_2_5DB)  # 1.5V max
    # Capteur temp CCS811
    ccs = CCS811(i2c)
    if ccs.check_error:
        raise Exception("CCS811 ERROR_ID = %s" % ccs.error_id.as_text)
except Exception as e:
    print(e)
    led_error(step=4)

try:
    # annonce connexion objet
    sMac = hexlify(WLAN().config('mac')).decode()
    q.publish("connect/%s" % CLIENT_ID, sMac)
    # Annonce l'état
except Exception as e:
    print(e)
    led_error(step=5)
コード例 #7
0
              u"CO2 :{:6.1f} ppm".format(co2),
              font=font,
              fill=255)

    disp.image(image)
    disp.display()


if __name__ == '__main__':
    # initialize variables
    is_thinger = True
    is_display = True
    SSD1306_I2C_Address = 0x3C

    # initialize Air sensor
    air_sensor = CCS811(debug=False)
    air_sensor.begin()

    # Initialize Environment sensor
    env_sensor = BME280(debug=True)
    env_sensor.begin()
    env_sensor.readData()

    # Initialize display
    disp = Adafruit_SSD1306.SSD1306_128_64(rst=None,
                                           i2c_address=SSD1306_I2C_Address)
    disp.begin()
    disp.clear()
    disp.display()

    air_sensor.setEnvironmentalData(env_sensor.Temperature,
コード例 #8
0
from Hologram.HologramCloud import HologramCloud
import time

hologram = HologramCloud(dict(), network='cellular')


def post_data(data):
    try:
        hologram.sendMessage(data, topics=['VOC'], timeout=3)
    except:
        print("Error!")
    return 0


if __name__ == "__main__":
    my_ccs811 = CCS811()
    my_ccs811.reset()

    print(my_ccs811.read_byte(0x00))
    print(my_ccs811.read_byte(0x20))

    my_ccs811.start_app()

    my_ccs811.read_byte(0x00)
    measurement_time = time.time()

    while True:
        if my_ccs811.read_byte(0x00) == 152:
            my_ccs811.write_byte(0x02)
            data = my_ccs811.read_bytes(8)