meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

sensor:ccs811 [2026/04/21 20:47] – created - external edit 127.0.0.1sensor:ccs811 [2026/05/07 23:54] (current) – [RP2040-ETH example code] vamsan
Line 18: Line 18:
   * **TVOC (Total Volatile Organic Compounds):** Detects a wide array of gases, including alcohols, aldehydes, ketones, organic acids, and amines.   * **TVOC (Total Volatile Organic Compounds):** Detects a wide array of gases, including alcohols, aldehydes, ketones, organic acids, and amines.
   * **On-board Processing:** Incorporates an integrated 8-bit microcontroller that runs intelligent algorithms to turn raw sensor data into air quality readings, decreasing the processing load on your main controller.   * **On-board Processing:** Incorporates an integrated 8-bit microcontroller that runs intelligent algorithms to turn raw sensor data into air quality readings, decreasing the processing load on your main controller.
 +==== eCO2 (Equivalent Carbon Dioxide) Levels ==== 
 +The CCS811 does not measure actual CO₂. Instead, it estimates it based on hydrogen gas levels. This ppm (parts per million) value accurately reflects how stuffy or occupied a room is.
 +
 +^eCO2 Value \\ (ppm)^Air Quality^Meaning & Recommended Action|
 +|400 – 600|<color green>♦</color> Excellent|Clean outdoor air level. Ideal baseline.|
 +|600 – 1000|<color yellow>♦</color> Good|Standard indoor level. Safe with no health effects.|
 +|1000 – 1500|<color orange>♦</color> Fair|Stale air. May cause slight drowsiness. Open a window.|
 +|1500 – 2000|<color red>♦</color> Poor|Headaches and fatigue can start. Ventilation required.|
 +|2000 – 5000|<color red>X</color> Severe|Heavy lethargy, loss of focus. Immediate fresh air is needed.|
 +
 +
 +==== TVOC (Total Volatile Organic Compounds) Levels ==== 
 +TVOC measures airborne chemicals, gases, and toxins (e.g., from cleaning sprays, perfumes, paints, adhesives, or new furniture) in ppb (parts per billion).
 +
 +^TVOC Value \\ (ppm)^Air Quality^Potential Effects & Actions|
 +|0 – 50|<color green>♦</color> Excellent|Clean, chemical-free air.|
 +|50 – 220|<color yellow>♦</color> Good|Normal indoor environment. Low risk of irritation.|
 +|220 – 660|<color orange>♦</color> Moderate|Sensitive individuals may feel eye or throat irritation.|
 +|660 – 2200|<color red>♦</color> Poor|Headaches, nausea, or chemical odors. Locate source and ventilate.|
 +|Over 2200|<color red>X</color> Unhealthy|Intense irritation and discomfort. Toxic for long-term exposure.|
  
 ==== Technical Specifications ==== ==== Technical Specifications ====
Line 111: Line 131:
   * **Accuracy:** Remember that this sensor requires a 20-minute warm-up for stable readings and a 48-hour burn-in period when first used.   * **Accuracy:** Remember that this sensor requires a 20-minute warm-up for stable readings and a 48-hour burn-in period when first used.
  
 +==== RP2040-ETH Micropython example code ====
 +
 +I²C settings: i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=100000)
 +
 +<code python>
 +from machine import UART, Pin, I2C
 +import machine
 +import time
 +
 +# I2C konfiguráció az RP2040-ETH szabadon használható pinjein
 +# Gyári alapértelmezett I2C cím a CCS811-nél: 0x5A (ha az ADDR pin GND-n van)
 +CCS811_ADDR = 0x5A 
 +
 +# Regiszter címek a CCS811 adatlap szerint
 +REG_STATUS = 0x00
 +REG_MEAS_MODE = 0x01
 +REG_ALG_DATA = 0x02
 +REG_HW_ID = 0x20
 +REG_APP_START = 0xF4
 +REG_SW_RESET = 0xFF
 +
 +# I2C busz inicializálása
 +i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=100000)
 +
 +def init_ccs811():
 +    print("CCS811 inicializálása...")
 +    
 +    # 1. Eszköz keresése az I2C buszon
 +    devices = i2c.scan()
 +    if CCS811_ADDR not in devices:
 +        raise RuntimeError("A CCS811 szenzor nem található! Ellenőrizd a WAKE -> GND bekötést.")
 +
 +    # 2. Hardver ID ellenőrzése (kötelezően 0x81)
 +    hw_id = i2c.readfrom_mem(CCS811_ADDR, REG_HW_ID, 1)[0]
 +    if hw_id != 0x81:
 +        raise RuntimeError(f"Hibás Hardver ID: {hex(hw_id)} (0x81 helyett)")
 +
 +    # 3. Szoftveres indítás (Átváltás Bootloaderből Alkalmazás módba)
 +    # Üres adatot kell írni az APP_START regiszterbe
 +    i2c.writeto_mem(CCS811_ADDR, REG_APP_START, b'')
 +    time.sleep_ms(100)
 +
 +    # 4. Mérési mód beállítása (Mód 1: Mérés másodpercenként egyszer)
 +    # A 0x10 érték beírja az 1-es módot (Drive Mode 1) és letiltja az megszakításokat
 +    i2c.writeto_mem(CCS811_ADDR, REG_MEAS_MODE, b'\x10')
 +    time.sleep_ms(100)
 +    print("Szenzor sikeresen elindítva Mód 1-ben (1 mp mintavétel).")
 +
 +def read_air_quality():
 +    # Állapotregiszter ellenőrzése
 +    status = i2c.readfrom_mem(CCS811_ADDR, REG_STATUS, 1)[0]
 +    
 +    # A 3-as bit (0x08) jelzi, ha van új adat (DATA_READY)
 +    if status & 0x08:
 +        # Az ALG_DATA regiszterből 4 byte-ot olvasunk be:
 +        # Byte 0-1: eCO2 (ppm)
 +        # Byte 2-3: TVOC (ppb)
 +        data = i2c.readfrom_mem(CCS811_ADDR, REG_ALG_DATA, 4)
 +        
 +        eco2 = (data[0] << 8) | data[1]
 +        tvoc = (data[2] << 8) | data[3]
 +        
 +        return eco2, tvoc
 +    return None, None
 +
 +# Főprogram futtatása
 +try:
 +    init_ccs811()
 +    print("Mérés indítása... (Az első értékek beállásához idő kell)\n")
 +    
 +    while True:
 +        eco2, tvoc = read_air_quality()
 +        
 +        if eco2 is not None:
 +            print(f"[{time.ticks_ms() // 1000}s] eCO2: {eco2} ppm | TVOC: {tvoc} ppb")
 +        else:
 +            # Ha még nem frissült az adatregiszter, várunk
 +            pass
 +            
 +        time.sleep(1)
 +
 +except Exception as e:
 +    print(f"Hiba történt: {e}")
 +</code>
 +
 +**Output**
 +
 +<code>
 +[2788s] eCO2: 717 ppm | TVOC: 48 ppb
 +[2789s] eCO2: 665 ppm | TVOC: 40 ppb
 +[2790s] eCO2: 634 ppm | TVOC: 35 ppb
 +[2791s] eCO2: 634 ppm | TVOC: 35 ppb
 +[2792s] eCO2: 634 ppm | TVOC: 35 ppb
 +[2793s] eCO2: 641 ppm | TVOC: 36 ppb
 +[2794s] eCO2: 641 ppm | TVOC: 36 ppb
 +[2795s] eCO2: 657 ppm | TVOC: 39 ppb
 +[2796s] eCO2: 649 ppm | TVOC: 37 ppb
 +[2797s] eCO2: 649 ppm | TVOC: 37 ppb
 +</code>
 ===== I²C topics on lamaPLC ===== ===== I²C topics on lamaPLC =====
 {{topic>i2c}} {{topic>i2c}}
  
-{{tag>CJMCU-811 CCS811 Gas Sensor VOCs TVOC eCO2 CO2 Arduino Air_Quality_Metal_Oxide MOX I2C}}+{{tag>CJMCU-811 CCS811 Gas Sensor VOCs TVOC eCO2 CO2 Arduino Air_Quality_Metal_Oxide MOX I2C micropython RP2040-ETH}}
  
 This page has been accessed for: Today: {{counter|today}}, Until now: {{counter|total}} This page has been accessed for: Today: {{counter|today}}, Until now: {{counter|total}}