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.
Revision 1:d0abe05bc21e, committed 2021-09-06
- Comitter:
- louatayehh
- Date:
- Mon Sep 06 11:32:22 2021 +0000
- Parent:
- 0:2c1dce3543ae
- Commit message:
- Capteur 2 : CSS811;
Changed in this revision
--- a/CCS811.cpp Mon Sep 06 09:17:14 2021 +0000 +++ b/CCS811.cpp Mon Sep 06 11:32:22 2021 +0000 @@ -1,7 +1,8 @@ +//*****************Capteur CCS811 - qualité de l'air ***************************// + #include "CCS811.h" -// Constructeur -CCS811::CCS811(PinName sda, PinName scl) : _i2c(sda, scl) {} +CCS811::CCS811(PinName sda, PinName scl) : _i2c(sda, scl) {} // Constructeur /** ** Initial CCS811 need write MODE register and should Write APP START register to begin measurement.
--- a/CCS811.h Mon Sep 06 09:17:14 2021 +0000 +++ b/CCS811.h Mon Sep 06 11:32:22 2021 +0000 @@ -1,32 +1,11 @@ +//*****************Capteur CCS811 - qualité de l'air ***************************// + #ifndef CCS811_H #define CCS811_H //CCS811 register define -#define CCS811_I2C_ADDR 0xB6 //This is already left shifted 0x5B, if using other address, should be 0xB4 which is 0x5A left shifted. -#define CCS811_REG_STATUS 0x00 //Status. -#define CCS811_REG_MEAS_MODE 0x01 //Mesurement mode and conditions register. -#define CCS811_REG_ALG_RESULT_DATA 0x02 //Algorithm result. 2 bytes co2 ppm next 2 bytes ppb VOC level. -#define CCS811_REG_RAW_DATA 0x03 //Raw ADC data. -#define CCS811_REG_ENV_DATA 0x05 //Temperature and humidity data can be write to enavle compensation. -#define CCS811_REG_NTC 0x06 //Provides the voltage across the reference registor and the voltage across the NTC resistor. -#define CCS811_REG_THRESHOLDS 0x10 //Thresholds for operation when interrupts are only generated when eCO2 ppm crosses a threshold. -#define CCS811_REG_BASELINE 0x11 //The encoded current baseline value can be read.A previously saved encoded baseline can be written. -#define CCS811_REG_HW_ID 0x20 //Hardware ID. The value is 0x81. -#define CCS811_REG_HW_VERSION 0x21 //Hardware version. The value is 0x1X. -#define CCS811_REG_BOOT_VERSION 0x23 //Firmware boot version. The First 2 bytes contain the firmware version number for the boot code. -#define CCS811_REG_APP_VERSION 0x24 //Firmware application version. The first 2 bytes contain the firmware version number for the application code. -#define CCS811_REG_ERROR_ID 0xE0 //Error ID. When the status register reports and error its source is lcated in this register. -#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. -#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. - -//mode setting -#define CCS811_MEASUREMENT_MODE0 0x00 //Idle(Measurements are disabled in this mode). -#define CCS811_MEASUREMENT_MODE1 0x10 //Constant power mode, IAQ measurement every second. -#define CCS811_MEASUREMENT_MODE2 0x20 //Pulse heating mode IAQ measurement every 10 seconds. - -//CCS811 register define -#define CCS811_I2C_ADDR 0xB6 //This is already left shifted 0x5B, if using other address, should be 0xB4 which is 0x5A left shifted. -#define CCS811_REG_STATUS 0x00 //Status. +#define CCS811_I2C_ADDR 0xB6 //Décalage adresse I2C de CCS811 (adresse 0x5B) +#define CCS811_REG_STATUS 0x00 //Status #define CCS811_REG_MEAS_MODE 0x01 //Mesurement mode and conditions register. #define CCS811_REG_ALG_RESULT_DATA 0x02 //Algorithm result. 2 bytes co2 ppm next 2 bytes ppb VOC level. #define CCS811_REG_RAW_DATA 0x03 //Raw ADC data. @@ -68,7 +47,6 @@ bool readerror(); protected: I2C _i2c; - private: };
--- a/main.cpp Mon Sep 06 09:17:14 2021 +0000 +++ b/main.cpp Mon Sep 06 11:32:22 2021 +0000 @@ -2,13 +2,13 @@ #include "CCS811.h" I2C i2c (I2C_SDA,I2C_SCL); -Serial bluetooth(p9,p10); +Serial bluetooth(p9,p10); #ifdef TARGET_UBLOX_EVK_ODIN_W2 CCS811 ccs811(p9, p10); #else CCS811 ccs811(I2C_SDA, I2C_SCL); -#endif +#endif uint16_t eco2, tvoc; @@ -18,7 +18,7 @@ bluetooth.baud(56000); //ccs811.readData(&eco2, &tvoc); //bluetooth.printf("eCO2 reading :%dppm, TVOC reading :%dppb\r\n", eco2, tvoc); - + ccs811.readData(&eco2, &tvoc); bluetooth.printf("eCO2 reading :%dppm", eco2); } @@ -29,7 +29,8 @@ ccs811.init(); wait(1); - while(1) { + while(1) + { ccs811.readstatus(); //0x90 reports everything working, 0x98 measurement ready to be used wait(1); CCS811Callback();