Library for CCS811 CO2/VOC sensor for testing.

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
p0lyg0n1
Posts: 160
Joined: 04 Aug 2016 07:14

Library for CCS811 CO2/VOC sensor for testing.

Post by p0lyg0n1 » 14 Jul 2018 17:24

Hi,
Finally I have ported a library for CCS811 (AMS) . You can get it here for tests (see attachmens). I'll add it to next beta.
You have to use clock stretching enable Wire library from there https://forum.z-wave.me/viewtopic.php?f=3427&t=28957 to get it work.
Test sketch code

Code: Select all

#define MY_SERIAL Serial0
#include <ZUNO_CCS811.h> 

ZUNO_CCS811 ccs811;
CCS811_Environment env_data = {500, 2500}; // <--- You need an external humidity & temperature sensor like DHT22 or BME280 to make it accurate, Here is default values 50.0% 25.00*C
void setup() {
    
    MY_SERIAL.begin(115200);
    if(ccs811.begin()){
        MY_SERIAL.println("CCS811 found!");
        ccs811.setEnvironmentalData(&env_data);
    }


}
void loop() {
    if(ccs811.readData() & CCS811_STATUS_DATAREADY){
         MY_SERIAL.print("CO2: ");
         MY_SERIAL.print(ccs811.geteCO2());
         MY_SERIAL.println(" ppm");
         MY_SERIAL.print("VOC: ");
         MY_SERIAL.print(ccs811.getTVOC());
         MY_SERIAL.println(" ppb");
    }
    delay(5000);
}
Have FUN )
Attachments
ZUNO_CCS811.zip
(3.72 KiB) Downloaded 43 times

michap
Posts: 321
Joined: 26 Mar 2013 10:35
Contact:

Re: Library for CCS811 CO2/VOC sensor for testing.

Post by michap » 30 Jul 2018 11:15

Nice work!
Can confirm that lib is working with my sensor too.
As discussed, my sensor had another device-ID, so I had to modify the setting.

Would suggest to add a flag, that sensor was not found in readData, so that not invalid values can be given back.

BTW: code is working only from 2.1.4 b5 , here the new libs are integrated, with older versions you will get a compiler error.

Thanks,
Michael

AlexML
Posts: 1
Joined: 10 May 2018 04:58

Re: Library for CCS811 CO2/VOC sensor for testing.

Post by AlexML » 31 Jul 2018 16:02

Hi,
I tried the library for CCS811. However, I found the incorrect operation of setDriveMode(). Correctly works only modes CCS811_DRIVE_MODE_250MS and CCS811_DRIVE_MODE_10SEC, attempts to use any modes other thanCCS811_DRIVE_MODE_10SEC, CCS811_DRIVE_MODE_250MS resulted in failure.
Do you have new versions of the library, other than the published one?
Alexey.

michap
Posts: 321
Joined: 26 Mar 2013 10:35
Contact:

Re: Library for CCS811 CO2/VOC sensor for testing.

Post by michap » 31 Jul 2018 18:03

@AlexML,
I'm just "burning in" the sensor (first 48 hours, regarding datasheet), so I haven't tested the other modes or any more details.
Just the sample above with the library in latest beta before 2.1.4 release.
Will test more when sensor is "ready" for use :)

Michael

michap
Posts: 321
Joined: 26 Mar 2013 10:35
Contact:

Re: Library for CCS811 CO2/VOC sensor for testing.

Post by michap » 02 Aug 2018 11:33

I just have tested the different modes and they are working fine.

If you change the sample sketch - please note about the requirements (regarding documentation)
When a sensor operating mode is changed to a new mode with a lower sample rate (e.g. from Mode 1 to Mode 3), it should be placed in Mode 0 (Idle) for at least 10 minutes before enabling the new mode. When a sensor operating mode is changed to a new mode with a higher sample rate (e.g. from Mode 3 to Mode 1), there is no requirement to wait before enabling the new mode.
Additional - there should not be a request of sensor values in shorter time as the given interval - I have tested with twice the interval as sample (for 1sec - delay(2000), for 10sec - delay(20000),... etc.)

Of course you could ignore the status flag (new value available) - then you will get the values in any time.

Michael

Post Reply