Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
CCS811.h@1:d0abe05bc21e, 2021-09-06 (annotated)
- Committer:
- louatayehh
- Date:
- Mon Sep 06 11:32:22 2021 +0000
- Revision:
- 1:d0abe05bc21e
- Parent:
- 0:2c1dce3543ae
Capteur 2 : CSS811;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
louatayehh | 1:d0abe05bc21e | 1 | //*****************Capteur CCS811 - qualité de l'air ***************************// |
louatayehh | 1:d0abe05bc21e | 2 | |
louatayehh | 0:2c1dce3543ae | 3 | #ifndef CCS811_H |
louatayehh | 0:2c1dce3543ae | 4 | #define CCS811_H |
louatayehh | 0:2c1dce3543ae | 5 | |
louatayehh | 0:2c1dce3543ae | 6 | //CCS811 register define |
louatayehh | 1:d0abe05bc21e | 7 | #define CCS811_I2C_ADDR 0xB6 //Décalage adresse I2C de CCS811 (adresse 0x5B) |
louatayehh | 1:d0abe05bc21e | 8 | #define CCS811_REG_STATUS 0x00 //Status |
louatayehh | 0:2c1dce3543ae | 9 | #define CCS811_REG_MEAS_MODE 0x01 //Mesurement mode and conditions register. |
louatayehh | 0:2c1dce3543ae | 10 | #define CCS811_REG_ALG_RESULT_DATA 0x02 //Algorithm result. 2 bytes co2 ppm next 2 bytes ppb VOC level. |
louatayehh | 0:2c1dce3543ae | 11 | #define CCS811_REG_RAW_DATA 0x03 //Raw ADC data. |
louatayehh | 0:2c1dce3543ae | 12 | #define CCS811_REG_ENV_DATA 0x05 //Temperature and humidity data can be write to enavle compensation. |
louatayehh | 0:2c1dce3543ae | 13 | #define CCS811_REG_NTC 0x06 //Provides the voltage across the reference registor and the voltage across the NTC resistor. |
louatayehh | 0:2c1dce3543ae | 14 | #define CCS811_REG_THRESHOLDS 0x10 //Thresholds for operation when interrupts are only generated when eCO2 ppm crosses a threshold. |
louatayehh | 0:2c1dce3543ae | 15 | #define CCS811_REG_BASELINE 0x11 //The encoded current baseline value can be read.A previously saved encoded baseline can be written. |
louatayehh | 0:2c1dce3543ae | 16 | #define CCS811_REG_HW_ID 0x20 //Hardware ID. The value is 0x81. |
louatayehh | 0:2c1dce3543ae | 17 | #define CCS811_REG_HW_VERSION 0x21 //Hardware version. The value is 0x1X. |
louatayehh | 0:2c1dce3543ae | 18 | #define CCS811_REG_BOOT_VERSION 0x23 //Firmware boot version. The First 2 bytes contain the firmware version number for the boot code. |
louatayehh | 0:2c1dce3543ae | 19 | #define CCS811_REG_APP_VERSION 0x24 //Firmware application version. The first 2 bytes contain the firmware version number for the application code. |
louatayehh | 0:2c1dce3543ae | 20 | #define CCS811_REG_ERROR_ID 0xE0 //Error ID. When the status register reports and error its source is lcated in this register. |
louatayehh | 0:2c1dce3543ae | 21 | #define CCS811_REG_APP_START 0xF4 //Application start. Used to transition the CCS811 state from boot to application mode, a write with no data is required. Before performing a write to APP_START the Status register should be accessed to check if there is a valid application present. |
louatayehh | 0:2c1dce3543ae | 22 | #define CCS811_REG_SW_RESET 0xFF //If the correct 4 byres (0x11, 0xE5, 0x72, 0x8A)are written to this register in a single sequence the device will reset and return to BOOT bode. |
louatayehh | 0:2c1dce3543ae | 23 | |
louatayehh | 0:2c1dce3543ae | 24 | //mode setting |
louatayehh | 0:2c1dce3543ae | 25 | #define CCS811_MEASUREMENT_MODE0 0x00 //Idle(Measurements are disabled in this mode). |
louatayehh | 0:2c1dce3543ae | 26 | #define CCS811_MEASUREMENT_MODE1 0x10 //Constant power mode, IAQ measurement every second. |
louatayehh | 0:2c1dce3543ae | 27 | #define CCS811_MEASUREMENT_MODE2 0x20 //Pulse heating mode IAQ measurement every 10 seconds. |
louatayehh | 0:2c1dce3543ae | 28 | #define CCS811_MEASUREMENT_MODE3 0x30 //Low power pulse heating mode IAQ measurement every 60 seconds. |
louatayehh | 0:2c1dce3543ae | 29 | #define CCS811_MEASUREMENT_MODE4 0x40 //Constant power mode, sensor measurement every 250ms. 1xx: Reserved modes (For future use). |
louatayehh | 0:2c1dce3543ae | 30 | |
louatayehh | 0:2c1dce3543ae | 31 | //Interrupt control |
louatayehh | 0:2c1dce3543ae | 32 | #define CCS811_INT_DATARDY 0x08 //At the end of each measurement cycle (250ms, 1s, 10s, 60s) a flag is set in the STATUS register regardless of the setting of this bit. |
louatayehh | 0:2c1dce3543ae | 33 | #define CCS811_INT_THRESH 0x04 //0: Interrupt mode (if enabled) operates normally 1: Interrupt mode (if enabled) only asserts the nINT signal (driven low) if the new ALG_RESULT_DATA crosses one of the thresholds set in the THRESHOLDS register by more than the hysteresis value (also in the THRESHOLDS register). |
louatayehh | 0:2c1dce3543ae | 34 | |
louatayehh | 0:2c1dce3543ae | 35 | #include "mbed.h" |
louatayehh | 0:2c1dce3543ae | 36 | |
louatayehh | 0:2c1dce3543ae | 37 | class CCS811 { |
louatayehh | 0:2c1dce3543ae | 38 | public: |
louatayehh | 0:2c1dce3543ae | 39 | CCS811(PinName sda, PinName scl); // Créer une instance CCS811 connectée aux pin I2C sda et scl |
louatayehh | 0:2c1dce3543ae | 40 | void init(); // Initialisation capteur CCS811 |
louatayehh | 0:2c1dce3543ae | 41 | int setMeasureMode(char mode); |
louatayehh | 0:2c1dce3543ae | 42 | int readData(uint16_t *ECO2, uint16_t *TVOC); |
louatayehh | 0:2c1dce3543ae | 43 | bool checkHW(); |
louatayehh | 0:2c1dce3543ae | 44 | bool softRest(); |
louatayehh | 0:2c1dce3543ae | 45 | bool readstatus(); |
louatayehh | 0:2c1dce3543ae | 46 | bool readmeas(); |
louatayehh | 0:2c1dce3543ae | 47 | bool readerror(); |
louatayehh | 0:2c1dce3543ae | 48 | protected: |
louatayehh | 0:2c1dce3543ae | 49 | I2C _i2c; |
louatayehh | 0:2c1dce3543ae | 50 | }; |
louatayehh | 0:2c1dce3543ae | 51 | |
louatayehh | 0:2c1dce3543ae | 52 | |
louatayehh | 0:2c1dce3543ae | 53 | #endif |