
Template Software STM32F429 Discovery Kit with SCD41 CO2 Sensor
Dependencies: LCD_DISCO_F429ZI TS_DISCO_F429ZI BSP_DISCO_F429ZI
scd41.h@13:aff8e9f42652, 2022-03-22 (annotated)
- Committer:
- garj
- Date:
- Tue Mar 22 10:19:59 2022 +0000
- Revision:
- 13:aff8e9f42652
update to SCD41
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
garj | 13:aff8e9f42652 | 1 | #ifndef SCD41_H |
garj | 13:aff8e9f42652 | 2 | #define SCD41_H |
garj | 13:aff8e9f42652 | 3 | |
garj | 13:aff8e9f42652 | 4 | #include "mbed.h" |
garj | 13:aff8e9f42652 | 5 | // i2c sensor address |
garj | 13:aff8e9f42652 | 6 | #define SCD41_ADR 0x62 |
garj | 13:aff8e9f42652 | 7 | // sensor automatically starts measurement. RDY pin signals measurement ready. |
garj | 13:aff8e9f42652 | 8 | #define COMMAND_CONTINUOUS_MEASUREMENT {0x21, 0xB1} |
garj | 13:aff8e9f42652 | 9 | #define COMMAND_CONTINUOUS_MEASUREMENT_LEN 2 |
garj | 13:aff8e9f42652 | 10 | // command that needs to be sent before reading out the measurement result |
garj | 13:aff8e9f42652 | 11 | #define COMMAND_READ_MEASUREMENT {0xec, 0x05} |
garj | 13:aff8e9f42652 | 12 | #define COMMAND_READ_MEASUREMENT_LEN 2 |
garj | 13:aff8e9f42652 | 13 | |
garj | 13:aff8e9f42652 | 14 | /** Create Scd41 controller class |
garj | 13:aff8e9f42652 | 15 | * |
garj | 13:aff8e9f42652 | 16 | * @param Scd41 class |
garj | 13:aff8e9f42652 | 17 | * |
garj | 13:aff8e9f42652 | 18 | */ |
garj | 13:aff8e9f42652 | 19 | class Scd41 { |
garj | 13:aff8e9f42652 | 20 | |
garj | 13:aff8e9f42652 | 21 | public: |
garj | 13:aff8e9f42652 | 22 | enum ScdError { |
garj | 13:aff8e9f42652 | 23 | SCD_ERROR_NO_ERROR, |
garj | 13:aff8e9f42652 | 24 | SCD_ERROR_COM_ERROR |
garj | 13:aff8e9f42652 | 25 | }; |
garj | 13:aff8e9f42652 | 26 | |
garj | 13:aff8e9f42652 | 27 | /** Create a Scd41 object using the specified I2C object |
garj | 13:aff8e9f42652 | 28 | * @param sda - mbed I2C interface pin |
garj | 13:aff8e9f42652 | 29 | * @param scl - mbed I2C interface pin |
garj | 13:aff8e9f42652 | 30 | * @param I2C Frequency (in Hz) |
garj | 13:aff8e9f42652 | 31 | * |
garj | 13:aff8e9f42652 | 32 | * @return none |
garj | 13:aff8e9f42652 | 33 | */ |
garj | 13:aff8e9f42652 | 34 | Scd41(PinName sda, PinName scl, int i2cFrequency, PinName rdy); |
garj | 13:aff8e9f42652 | 35 | |
garj | 13:aff8e9f42652 | 36 | /** Initialize settings and start Auto-Measurement |
garj | 13:aff8e9f42652 | 37 | * |
garj | 13:aff8e9f42652 | 38 | * @param --none-- |
garj | 13:aff8e9f42652 | 39 | * |
garj | 13:aff8e9f42652 | 40 | * @return enum ScdError |
garj | 13:aff8e9f42652 | 41 | */ |
garj | 13:aff8e9f42652 | 42 | uint8_t init(); |
garj | 13:aff8e9f42652 | 43 | |
garj | 13:aff8e9f42652 | 44 | /** Check if measurement is ready |
garj | 13:aff8e9f42652 | 45 | * |
garj | 13:aff8e9f42652 | 46 | * @param --none-- |
garj | 13:aff8e9f42652 | 47 | * |
garj | 13:aff8e9f42652 | 48 | * @return bool true=ready |
garj | 13:aff8e9f42652 | 49 | */ |
garj | 13:aff8e9f42652 | 50 | bool isMeasurementReady(); |
garj | 13:aff8e9f42652 | 51 | |
garj | 13:aff8e9f42652 | 52 | /** Read all environmental parameters (CO2, Temp and Hum) from sensor |
garj | 13:aff8e9f42652 | 53 | * |
garj | 13:aff8e9f42652 | 54 | * @param --none- |
garj | 13:aff8e9f42652 | 55 | * |
garj | 13:aff8e9f42652 | 56 | * @return enum ScdError |
garj | 13:aff8e9f42652 | 57 | */ |
garj | 13:aff8e9f42652 | 58 | uint8_t readMeasurement(); |
garj | 13:aff8e9f42652 | 59 | |
garj | 13:aff8e9f42652 | 60 | /** Get current temperature value |
garj | 13:aff8e9f42652 | 61 | * |
garj | 13:aff8e9f42652 | 62 | * @param --none-- |
garj | 13:aff8e9f42652 | 63 | * |
garj | 13:aff8e9f42652 | 64 | * @return enum SCDerror |
garj | 13:aff8e9f42652 | 65 | */ |
garj | 13:aff8e9f42652 | 66 | float getTemp(){ return _temp;}; |
garj | 13:aff8e9f42652 | 67 | |
garj | 13:aff8e9f42652 | 68 | /** Get current Humidity value |
garj | 13:aff8e9f42652 | 69 | * |
garj | 13:aff8e9f42652 | 70 | * @param --none-- |
garj | 13:aff8e9f42652 | 71 | * |
garj | 13:aff8e9f42652 | 72 | * @return enum SCDerror |
garj | 13:aff8e9f42652 | 73 | */ |
garj | 13:aff8e9f42652 | 74 | float getHumi(){ return _humi;}; |
garj | 13:aff8e9f42652 | 75 | |
garj | 13:aff8e9f42652 | 76 | /** Get current CO2 value |
garj | 13:aff8e9f42652 | 77 | * |
garj | 13:aff8e9f42652 | 78 | * @param --none-- |
garj | 13:aff8e9f42652 | 79 | * |
garj | 13:aff8e9f42652 | 80 | * @return enum SCDerror |
garj | 13:aff8e9f42652 | 81 | */ |
garj | 13:aff8e9f42652 | 82 | float getCo2(){ return _co2;}; |
garj | 13:aff8e9f42652 | 83 | |
garj | 13:aff8e9f42652 | 84 | private: |
garj | 13:aff8e9f42652 | 85 | I2C _i2c; |
garj | 13:aff8e9f42652 | 86 | DigitalIn _rdy; |
garj | 13:aff8e9f42652 | 87 | float _temp; |
garj | 13:aff8e9f42652 | 88 | float _humi; |
garj | 13:aff8e9f42652 | 89 | float _co2; |
garj | 13:aff8e9f42652 | 90 | |
garj | 13:aff8e9f42652 | 91 | }; |
garj | 13:aff8e9f42652 | 92 | #endif |