Working eCO2 and TVOC sensor

Dependencies:   CCS811

Committer:
andcor02
Date:
Thu Oct 19 12:30:01 2017 +0000
Revision:
3:13e51613b175
Parent:
2:f0800e58f4b0
changed defines for global

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andcor02 0:c53d931d771e 1 #include "mbed.h"
andcor02 0:c53d931d771e 2 #include "CCS811.h"
andcor02 0:c53d931d771e 3
andcor02 0:c53d931d771e 4
andcor02 0:c53d931d771e 5
andcor02 0:c53d931d771e 6 Serial pc(USBTX, USBRX);
andcor02 0:c53d931d771e 7
andcor02 3:13e51613b175 8 #ifdef TARGET_UBLOX_EVK_ODIN_W2
andcor02 3:13e51613b175 9 CCS811 ccs811(PF_0, PF_1);
andcor02 3:13e51613b175 10 #else
andcor02 2:f0800e58f4b0 11 CCS811 ccs811(I2C_SDA, I2C_SCL);
andcor02 0:c53d931d771e 12 #endif
andcor02 3:13e51613b175 13
andcor02 0:c53d931d771e 14
andcor02 0:c53d931d771e 15 uint16_t eco2, tvoc;
andcor02 0:c53d931d771e 16
andcor02 0:c53d931d771e 17
andcor02 0:c53d931d771e 18 void CCS811Callback(void)
andcor02 0:c53d931d771e 19 {
andcor02 0:c53d931d771e 20
andcor02 0:c53d931d771e 21 ccs811.readData(&eco2, &tvoc);
andcor02 0:c53d931d771e 22
andcor02 0:c53d931d771e 23 pc.printf("eCO2 reading :%dppm, TVOC reading :%dppb\r\n", eco2, tvoc);
andcor02 0:c53d931d771e 24
andcor02 0:c53d931d771e 25 }
andcor02 0:c53d931d771e 26
andcor02 0:c53d931d771e 27
andcor02 0:c53d931d771e 28 int main()
andcor02 0:c53d931d771e 29 {
andcor02 0:c53d931d771e 30 ccs811.init();
andcor02 0:c53d931d771e 31 wait(1);
andcor02 0:c53d931d771e 32
andcor02 0:c53d931d771e 33 while(1) {
andcor02 0:c53d931d771e 34 // ccs811.readstatus(); //0x90 reports everything working, 0x98 measurement ready to be used
andcor02 0:c53d931d771e 35 wait(1);
andcor02 0:c53d931d771e 36 CCS811Callback();
andcor02 0:c53d931d771e 37 wait(1);
andcor02 0:c53d931d771e 38 }
andcor02 0:c53d931d771e 39 }