Working eCO2 and TVOC sensor

Dependencies:   CCS811

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "CCS811.h"
00003 
00004 
00005 
00006 Serial pc(USBTX, USBRX);
00007 
00008 #ifdef TARGET_UBLOX_EVK_ODIN_W2
00009 CCS811 ccs811(PF_0, PF_1);
00010 #else
00011 CCS811 ccs811(I2C_SDA, I2C_SCL);
00012 #endif
00013 
00014 
00015 uint16_t eco2, tvoc;
00016 
00017 
00018 void CCS811Callback(void)
00019 {
00020 
00021     ccs811.readData(&eco2, &tvoc);
00022 
00023     pc.printf("eCO2 reading :%dppm, TVOC reading :%dppb\r\n", eco2, tvoc);
00024 
00025 }
00026 
00027 
00028 int main()
00029 {
00030     ccs811.init();
00031     wait(1);
00032 
00033     while(1) {
00034 //        ccs811.readstatus(); //0x90 reports everything working, 0x98 measurement ready to be used
00035         wait(1);
00036         CCS811Callback();
00037         wait(1);
00038     }
00039 }