Package: haas-python-ccs811
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, seeHaaS Python official website,Creative Case,Hardware Building Blocks安装方法在HaaS Python官网下载开发板对应的固件，并完成固件烧录Download the firmware corresponding to the development board atHaaS Python websiteand 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 ongithub, Our engineers will answer in timeimport upip
upip.install("haas-python-ccs811")
import haas-python-ccs811空气质量检测模块 - CCS811一、产品简介通过CCS811传感器模块可以测量环境中TVOC(总挥发性有机物质)浓度和eCO2(二氧化碳)浓度，作为衡量空气质量（IAQ）的指标。引脚定义VCC：3.3VGND：接地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)参数说明：参数类型必选参数？说明i2cObjI2C是调用此函数前需确保i2cObj对象已经处于open状态返回值：
CCS811对象创建成功，返回CCS811对象；CCS811对象创建失败，抛出Exception示例代码：fromdriverimportI2Cimportccs811i2cObj=I2C()i2cObj.open("ccs811")devObj=ccs811.CCS811(i2cObj)print("ccs811 inited!")输出：ccs811 inited!geteCO2 - 获取空气中二氧化碳浓度函数功能：
获取空气中二氧化碳浓度函数原型：CCS811.geteCO2()参数说明：
无返回值：返回值类型说明status整型0-无效数值；1-有效数值eco2整型单位：ppm，>=400示例：fromdriverimportI2Cimportccs811importutimei2cObj=I2C()i2cObj.open("ccs811")devObj=ccs811.CCS811(i2cObj)print("ccs811 inited!")whileTrue:status,eco2=devObj.geteCO2()ifstatus==1:print('eCO2:%dppm'%(eco2))utime.sleep(1)输出：ccs811 inited!
eCO2: 400 ppm
eCO2: 868 ppm
eCO2: 400 ppm
eCO2: 400 ppmgetTVOC - 获取空气中挥发有机物的浓度函数功能：
获取空气中挥发有机物的浓度函数原型：CCS811.getTVOC()参数说明：
无返回值：返回值类型说明status整型0-无效数值；1-有效数值tvoc整型单位：ppb示例：fromdriverimportI2Cimportccs811importutimei2cObj=I2C()i2cObj.open("ccs811")devObj=ccs811.CCS811(i2cObj)print("ccs811 inited!")whileTrue:status,tvoc=devObj.getTVOC()ifstatus==1:print('TVOC:%dppb'%(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 ppbgeteCO2TVOC - 获取空气中二氧化碳以及挥发有机物的浓度函数功能：
获取空气中二氧化碳以及挥发有机物的浓度函数原型：CCS811.geteCO2TVOC()参数说明：
无返回值：返回值类型说明status整型0-无效数值；1-有效数值eco2整型单位：ppm,>=400tvoc整型单位：ppb示例：fromdriverimportI2Cimportccs811importutimei2cObj=I2C()i2cObj.open("ccs811")devObj=ccs811.CCS811(i2cObj)print("ccs811 inited!")whileTrue:status,eco2,tvoc=devObj.geteCO2TVOC()ifstatus==1:print('eCO2:%dppm, TVOC:%dppb'%(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代码fromdriverimportI2Cimportccs811importutimei2cObj=I2C()i2cObj.open("ccs811")devObj=ccs811.CCS811(i2cObj)print("ccs811 inited!")whileTrue:status,eco2,tvoc=devObj.geteCO2TVOC()ifstatus==1:print('eCO2:%dppm, TVOC:%dppb'%(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传感器寄存器描述如下表所示：序号寄存器地址功能说明默认值10x00状态寄存器--20x01测量模式寄存器--30x02测量结果寄存器--40x20硬件ID寄存器0x8150x21硬件版本寄存器0x1X60xF4APP启动寄存器--70xFF软件重启寄存器--从下图可以看到CCS811内置I2C通信单元，与MCU进行数据交互。其中nINT和nRESET是可选的，根据实际项目需要而定，nWAKE低电平状态为激活CCS811。引脚分布如下：序号引脚名功能说明1I2C_ADDR低电平 - I2C地址总线0x5A高电平 - I2C地址总线0x5B2nRESET复位引脚，低电平有效3nINT阈值中断引脚4PWM--5Sense--6VDD电源正7nWAKE唤醒引脚，低电平有效8AUX--9I2C_SDAI2C数据线10I2C_SCKI2C时钟线参考文献及购买链接[1]CCS811传感器DATASHEET[2]CCS811传感器模块购买