
Template Software STM32F429 Discovery Kit with SCD41 CO2 Sensor
Dependencies: LCD_DISCO_F429ZI TS_DISCO_F429ZI BSP_DISCO_F429ZI
scd30.h@8:6906f3ee5538, 2021-03-19 (annotated)
- Committer:
- garj
- Date:
- Fri Mar 19 07:49:19 2021 +0000
- Revision:
- 8:6906f3ee5538
- Parent:
- 7:17a87b6d8516
- Child:
- 9:4d526b2f44e9
fix i2c addr
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
garj | 7:17a87b6d8516 | 1 | #ifndef SCD30_H |
garj | 7:17a87b6d8516 | 2 | #define SCD30_H |
garj | 7:17a87b6d8516 | 3 | |
garj | 7:17a87b6d8516 | 4 | #include "mbed.h" |
garj | 7:17a87b6d8516 | 5 | // i2c sensor address |
garj | 8:6906f3ee5538 | 6 | #define SCD30_ADR = 0x61 |
garj | 7:17a87b6d8516 | 7 | // sensor automatically starts measurement. RDY pin signals measurement ready. |
garj | 7:17a87b6d8516 | 8 | #define COMMAND_CONTINUOUS_MEASUREMENT {0x00, 0x10, 0x00, 0x00, 0x00} |
garj | 7:17a87b6d8516 | 9 | #define COMMAND_CONTINUOUS_MEASUREMENT_LEN sizeof(COMMAND_CONTINUOUS_MEASUREMENT) |
garj | 7:17a87b6d8516 | 10 | // 2s measurement Interval |
garj | 7:17a87b6d8516 | 11 | #define COMMAND_SET_MEASUREMENT_INTERVAL {0x46, 0x00, 0x00, 0x02, 0x00} |
garj | 7:17a87b6d8516 | 12 | #define COMMAND_SET_MEASUREMENT_INTERVAL_LEN sizeof(COMMAND_SET_MEASUREMENT_INTERVAL) |
garj | 7:17a87b6d8516 | 13 | // automatic self calibration on |
garj | 7:17a87b6d8516 | 14 | #define COMMAND_AUTOMATIC_SELF_CALIBRATION {0x53, 0x06, 0x00, 0x01, 0x00} |
garj | 7:17a87b6d8516 | 15 | #define COMMAND_AUTOMATIC_SELF_CALIBRATION_LEN sizeof(COMMAND_AUTOMATIC_SELF_CALIBRATION) |
garj | 7:17a87b6d8516 | 16 | // command that needs to be sent before reading out the measurement result |
garj | 7:17a87b6d8516 | 17 | #define COMMAND_READ_MEASUREMENT {0x03, 0x00} |
garj | 7:17a87b6d8516 | 18 | #define COMMAND_READ_MEASUREMENT_LEN sizeof(COMMAND_READ_MEASUREMENT) |
garj | 7:17a87b6d8516 | 19 | |
garj | 7:17a87b6d8516 | 20 | /** Create SCD30 controller class |
garj | 7:17a87b6d8516 | 21 | * |
garj | 7:17a87b6d8516 | 22 | * @param Scd30 class |
garj | 7:17a87b6d8516 | 23 | * |
garj | 7:17a87b6d8516 | 24 | */ |
garj | 7:17a87b6d8516 | 25 | class Scd30 { |
garj | 7:17a87b6d8516 | 26 | |
garj | 7:17a87b6d8516 | 27 | public: |
garj | 7:17a87b6d8516 | 28 | enum ScdError { |
garj | 7:17a87b6d8516 | 29 | SCD_ERROR_NO_ERROR, |
garj | 7:17a87b6d8516 | 30 | SCD_ERROR_COM_ERROR |
garj | 7:17a87b6d8516 | 31 | }; |
garj | 7:17a87b6d8516 | 32 | |
garj | 7:17a87b6d8516 | 33 | /** Create a SCD30 object using the specified I2C object |
garj | 7:17a87b6d8516 | 34 | * @param sda - mbed I2C interface pin |
garj | 7:17a87b6d8516 | 35 | * @param scl - mbed I2C interface pin |
garj | 7:17a87b6d8516 | 36 | * @param I2C Frequency (in Hz) |
garj | 7:17a87b6d8516 | 37 | * |
garj | 7:17a87b6d8516 | 38 | * @return none |
garj | 7:17a87b6d8516 | 39 | */ |
garj | 7:17a87b6d8516 | 40 | Scd30(PinName sda, PinName scl, int i2cFrequency, PinName rdy); |
garj | 7:17a87b6d8516 | 41 | |
garj | 7:17a87b6d8516 | 42 | /** Initialize settings and start Auto-Measurement |
garj | 7:17a87b6d8516 | 43 | * |
garj | 7:17a87b6d8516 | 44 | * @param --none-- |
garj | 7:17a87b6d8516 | 45 | * |
garj | 7:17a87b6d8516 | 46 | * @return enum ScdError |
garj | 7:17a87b6d8516 | 47 | */ |
garj | 7:17a87b6d8516 | 48 | uint8_t init(); |
garj | 7:17a87b6d8516 | 49 | |
garj | 7:17a87b6d8516 | 50 | /** Check if measurement is ready |
garj | 7:17a87b6d8516 | 51 | * |
garj | 7:17a87b6d8516 | 52 | * @param --none-- |
garj | 7:17a87b6d8516 | 53 | * |
garj | 7:17a87b6d8516 | 54 | * @return bool true=ready |
garj | 7:17a87b6d8516 | 55 | */ |
garj | 7:17a87b6d8516 | 56 | bool isMeasurementReady(); |
garj | 7:17a87b6d8516 | 57 | |
garj | 7:17a87b6d8516 | 58 | /** Read all environmental parameters (CO2, Temp and Hum) from sensor |
garj | 7:17a87b6d8516 | 59 | * |
garj | 7:17a87b6d8516 | 60 | * @param --none- |
garj | 7:17a87b6d8516 | 61 | * |
garj | 7:17a87b6d8516 | 62 | * @return enum ScdError |
garj | 7:17a87b6d8516 | 63 | */ |
garj | 7:17a87b6d8516 | 64 | uint8_t readMeasurement(); |
garj | 7:17a87b6d8516 | 65 | |
garj | 7:17a87b6d8516 | 66 | /** Get current CO2 value |
garj | 7:17a87b6d8516 | 67 | * |
garj | 7:17a87b6d8516 | 68 | * @param --none-- |
garj | 7:17a87b6d8516 | 69 | * |
garj | 7:17a87b6d8516 | 70 | * @return enum SCDerror |
garj | 7:17a87b6d8516 | 71 | */ |
garj | 7:17a87b6d8516 | 72 | float getCo2(){ return _co2;}; |
garj | 7:17a87b6d8516 | 73 | |
garj | 7:17a87b6d8516 | 74 | private: |
garj | 7:17a87b6d8516 | 75 | I2C _i2c; |
garj | 7:17a87b6d8516 | 76 | DigitalIn _rdy; |
garj | 7:17a87b6d8516 | 77 | float _co2; |
garj | 7:17a87b6d8516 | 78 | |
garj | 7:17a87b6d8516 | 79 | }; |
garj | 7:17a87b6d8516 | 80 | #endif |