This is ccs811 driver for HaaS Python. HaaS Python is forked from micropython.
Project description
HaaS Python介绍
HaaS Python是阿里云IoT团队最新研发的一套低代码编程框架,兼容MicroPython编程规范,依托HaaS平台软硬件积木提供AI、支付、蓝牙配网、云连接、UI等物联网场景常用的能力,从而解决了物联网应用开发难的问题。有了Python轻应用框架,物联网编程不再局限于专业软件开发人员,一般的技术员也可以快速实现复杂的物联网需求。 更多HaaS Python介绍和开发资料见HaaS Python官网,创意案例, 硬件积木
HaaS Python is a set of low-code programming frameworks newly developed by Alibaba Cloud IoT team. It is compatible with MicroPython programming specifications. It relies on the hardware and software building blocks of the HaaS platform to provide capabilities commonly used in IoT scenarios such as AI, payment, Bluetooth network configuration, cloud connection, and UI. Solve the difficult problem of IoT application development. With the Python light application framework, IoT programming is no longer limited to professional software developers, and general technicians can quickly implement complex IoT requirements. For more HaaS Python introduction and development materials, see HaaS Python official website, Creative Case, Hardware Building Blocks
安装方法
- 在HaaS Python官网下载开发板对应的固件,并完成固件烧录
Download the firmware corresponding to the development board at HaaS Python website and complete the firmware burning
- 在开发板上运行以下命令完成安装和使用,如果您在使用过程中遇到问题,欢迎在github上向我们提交issue,我们的工程师会及时解答
Run the following commands on the development board to complete the installation and use. If you encounter problems during use, please submit an issue to us on github, Our engineers will answer in time
import upip
upip.install("haas-python-ccs811")
import haas-python-ccs811
空气质量检测模块 - CCS811
一、产品简介
通过CCS811传感器模块可以测量环境中TVOC(总挥发性有机物质)浓度和eCO2(二氧化碳)浓度,作为衡量空气质量(IAQ)的指标。
引脚定义
- VCC:3.3V
- GND:接地
- SCL:I2C时钟
- SDA:I2C数字
- WAK:接地
- INT:NC(阈值中断引脚)
- RST:NC(复位引脚)
- ADD:NC
二、技术参数
- 供电电压:3.3V
- 接口:I2C接口
- 分辨率:14位
- 工作电流:20mA
- 睡眠模式的电流:3uA
- 模块尺寸:15mm * 21mm
三、软件接口
CCS811传感器HaaS Python驱动:下载地址
CCS811(i2cObj) - 创建CCS811驱动对象
- 函数原型:
ccs811Obj = CCS811(i2cObj)
- 参数说明:
参数 | 类型 | 必选参数? | 说明 |
---|---|---|---|
i2cObj | I2C | 是 | 调用此函数前需确保i2cObj对象已经处于open状态 |
-
返回值: CCS811对象创建成功,返回CCS811对象;CCS811对象创建失败,抛出Exception
-
示例代码:
from driver import I2C
import ccs811
i2cObj = I2C()
i2cObj.open("ccs811")
devObj = ccs811.CCS811(i2cObj)
print("ccs811 inited!")
- 输出:
ccs811 inited!
geteCO2 - 获取空气中二氧化碳浓度
-
函数功能: 获取空气中二氧化碳浓度
-
函数原型:
CCS811.geteCO2()
-
参数说明: 无
-
返回值:
返回值 | 类型 | 说明 |
---|---|---|
status | 整型 | 0-无效数值; 1-有效数值 |
eco2 | 整型 | 单位:ppm,>=400 |
- 示例:
from driver import I2C
import ccs811
import utime
i2cObj = I2C()
i2cObj.open("ccs811")
devObj = ccs811.CCS811(i2cObj)
print("ccs811 inited!")
while True:
status,eco2 = devObj.geteCO2()
if status == 1:
print('eCO2: %d ppm' %(eco2))
utime.sleep(1)
- 输出:
ccs811 inited!
eCO2: 400 ppm
eCO2: 868 ppm
eCO2: 400 ppm
eCO2: 400 ppm
getTVOC - 获取空气中挥发有机物的浓度
-
函数功能: 获取空气中挥发有机物的浓度
-
函数原型:
CCS811.getTVOC()
-
参数说明: 无
-
返回值:
返回值 | 类型 | 说明 |
---|---|---|
status | 整型 | 0-无效数值; 1-有效数值 |
tvoc | 整型 | 单位:ppb |
- 示例:
from driver import I2C
import ccs811
import utime
i2cObj = I2C()
i2cObj.open("ccs811")
devObj = ccs811.CCS811(i2cObj)
print("ccs811 inited!")
while True:
status,tvoc = devObj.getTVOC()
if status == 1:
print('TVOC: %d ppb' %(tvoc))
utime.sleep(1)
- 输出:
ccs811 inited!
TVOC: 0 ppb
TVOC: 0 ppb
TVOC: 0 ppb
TVOC: 3 ppb
TVOC: 734 ppb
TVOC: 68 ppb
TVOC: 129 ppb
TVOC: 62 ppb
TVOC: 25 ppb
geteCO2TVOC - 获取空气中二氧化碳以及挥发有机物的浓度
-
函数功能: 获取空气中二氧化碳以及挥发有机物的浓度
-
函数原型:
CCS811.geteCO2TVOC()
-
参数说明: 无
-
返回值:
返回值 | 类型 | 说明 |
---|---|---|
status | 整型 | 0-无效数值; 1-有效数值 |
eco2 | 整型 | 单位:ppm,>=400 |
tvoc | 整型 | 单位:ppb |
- 示例:
from driver import I2C
import ccs811
import utime
i2cObj = I2C()
i2cObj.open("ccs811")
devObj = ccs811.CCS811(i2cObj)
print("ccs811 inited!")
while True:
status,eco2,tvoc = devObj.geteCO2TVOC()
if status == 1:
print('eCO2: %d ppm, TVOC: %d ppb' % (eco2, tvoc))
utime.sleep(1)
- 输出:
ccs811 inited!
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 1495 ppm, TVOC: 168 ppb
eCO2: 481 ppm, TVOC: 12 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
四、接口案例
此使用实例在board.json中定义了名为CCS811的I2C类型的对象。在Python脚本中周期性的获取二氧化碳、有机物浓度并打印在日志中。
- 代码: board.json配置
{
"name": "board-name",
"version": "1.0.0",
"io": {
"ccs811": {
"type": "I2C",
"port": 0,
"addrWidth": 7,
"freq": 400000,
"mode": "master",
"devAddr": 90
}
},
"debugLevel": "ERROR",
"repl": "disable"
}
# Python代码
from driver import I2C
import ccs811
import utime
i2cObj = I2C()
i2cObj.open("ccs811")
devObj = ccs811.CCS811(i2cObj)
print("ccs811 inited!")
while True:
status,eco2,tvoc = devObj.geteCO2TVOC()
if status == 1:
print('eCO2: %d ppm, TVOC: %d ppb' % (eco2, tvoc))
utime.sleep(1)
- 输出:
ccs811 inited!
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 1495 ppm, TVOC: 168 ppb
eCO2: 481 ppm, TVOC: 12 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
eCO2: 400 ppm, TVOC: 0 ppb
五、工作原理
INA219传感器寄存器描述如下表所示:
序号 | 寄存器地址 | 功能说明 | 默认值 |
---|---|---|---|
1 | 0x00 | 状态寄存器 | -- |
2 | 0x01 | 测量模式寄存器 | -- |
3 | 0x02 | 测量结果寄存器 | -- |
4 | 0x20 | 硬件ID寄存器 | 0x81 |
5 | 0x21 | 硬件版本寄存器 | 0x1X |
6 | 0xF4 | APP启动寄存器 | -- |
7 | 0xFF | 软件重启寄存器 | -- |
从下图可以看到CCS811内置I2C通信单元,与MCU进行数据交互。其中nINT和nRESET是可选的,根据实际项目需要而定,nWAKE低电平状态为激活CCS811。
引脚分布如下:
序号 | 引脚名 | 功能说明 |
---|---|---|
1 | I2C_ADDR | 低电平 - I2C地址总线0x5A 高电平 - I2C地址总线0x5B |
2 | nRESET | 复位引脚,低电平有效 |
3 | nINT | 阈值中断引脚 |
4 | PWM | -- |
5 | Sense | -- |
6 | VDD | 电源正 |
7 | nWAKE | 唤醒引脚,低电平有效 |
8 | AUX | -- |
9 | I2C_SDA | I2C数据线 |
10 | I2C_SCK | I2C时钟线 |
参考文献及购买链接
[1] CCS811传感器DATASHEET
[2] CCS811传感器模块购买
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file haas-python-ccs811-0.0.2.tar.gz
.
File metadata
- Download URL: haas-python-ccs811-0.0.2.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2a1784db86aa4c14d70a835b21071a9e6bb7984591150fe054158d569195764 |
|
MD5 | 3301da12053c9bb9c0b750f9c0c4bbc0 |
|
BLAKE2b-256 | f2c6e779f058a0dbc2222897135aa967c964030aa860ca8e320a00cd31cd853c |