跳转到主要内容

CircuitPython库,用于Adafruit SGP40空气质量传感器/挥发性有机化合物指数传感器模块

项目描述

介绍

Documentation Status Discord Build Status Code Style: Black

CircuitPython库,用于Adafruit SGP40空气质量传感器/挥发性有机化合物指数传感器模块

依赖项

此驱动程序依赖于

请确保所有依赖项都在CircuitPython文件系统中可用。这可以通过下载Adafruit库和驱动程序包轻松实现。

从PyPI安装

在支持GNU/Linux系统(如树莓派)上,您可以从PyPI 本地安装驱动程序。为当前用户安装

pip3 install adafruit-circuitpython-sgp40

为系统范围安装(在某些情况下可能需要)

sudo pip3 install adafruit-circuitpython-sgp40

在当前项目的虚拟环境中安装

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-sgp40

使用示例

import time
import board
import adafruit_sgp40

i2c = board.I2C()  # uses board.SCL and board.SDA
sgp = adafruit_sgp40.SGP40(i2c)

while True:
    print("Measurement: ", sgp.raw)
    print("")
    sleep(1)

对于湿度补偿的原始气体和VOC指数读取,我们需要一个辅助传感器,例如bme280

import time
import board
import adafruit_sgp40
import adafruit_bme280

i2c = board.I2C()  # uses board.SCL and board.SDA
sgp = adafruit_sgp40.SGP40(i2c)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)

while True:
    temperature = bme280.temperature
    humidity = bme280.relative_humidity

    # For compensated raw gas readings
    """
    compensated_raw_gas = sgp.measure_raw(
        temperature=temperature, relative_humidity=humidity
    )
    print("Raw Data:", compensated_raw_gas)
    """

    # For Compensated voc index readings
    voc_index = sgp.measure_index(
    temperature=temperature, relative_humidity=humidity)

    print("VOC Index:", voc_index)
    print("")
    time.sleep(1)

由于需要校准基线读取,VOC指数可能需要几分钟才能开始变化。VOC算法期望1赫兹的采样率。每秒运行一次measure_index()

文档

本库的API文档可以在Read the Docs上找到。

有关构建库文档的信息,请参阅此指南

贡献

欢迎贡献力量!在为该项目做出贡献之前,请阅读我们的行为准则,以帮助该项目保持欢迎的氛围。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分布

adafruit-circuitpython-sgp40-1.3.17.tar.gz (33.6 kB 查看散列值)

上传时间 源代码

构建分布

adafruit_circuitpython_sgp40-1.3.17-py3-none-any.whl (12.5 kB 查看散列值)

上传时间 Python 3

由以下赞助

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面