Andrea Corrado
/
CCS811-TEST
Working eCO2 and TVOC sensor
main.cpp@2:f0800e58f4b0, 2017-10-19 (annotated)
- Committer:
- andcor02
- Date:
- Thu Oct 19 11:32:39 2017 +0000
- Revision:
- 2:f0800e58f4b0
- Parent:
- 0:c53d931d771e
- Child:
- 3:13e51613b175
changed error in declaration in main for I2C
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:c53d931d771e | 8 | #ifdef TARGET_K64F |
andcor02 | 2:f0800e58f4b0 | 9 | CCS811 ccs811(I2C_SDA, I2C_SCL); |
andcor02 | 0:c53d931d771e | 10 | #endif |
andcor02 | 0:c53d931d771e | 11 | #ifdef TARGET_UBLOX_EVK_ODIN_W2 |
andcor02 | 2:f0800e58f4b0 | 12 | CCS811 ccs811(PF_0, PF_1); |
andcor02 | 0:c53d931d771e | 13 | #endif |
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 | } |