A component library for MiCS-6814 Multichannel Gas Sensor (seeed)
Dependents: MiCS6814_GasSensor_Hello grove_multichannel_GasSensor
Diff: MiCS6814_GasSensor.h
- Revision:
- 3:93b7f86b72e1
- Parent:
- 2:8d61377f2e2a
- Child:
- 4:a15eee9bb0e6
--- a/MiCS6814_GasSensor.h Wed May 24 13:38:46 2017 +0900 +++ b/MiCS6814_GasSensor.h Wed May 24 10:03:01 2017 +0000 @@ -41,10 +41,9 @@ #include "mbed.h" -//#define _DEBUG #define SLAVE_ADDRESS_MiCS6814 (0x04<<1) -#define ADDR_IS_SET 0 // This is read at initialization time, if 1126, set +#define ADDR_IS_SET 0 #define ADDR_FACTORY_ADC_NH3 2 #define ADDR_FACTORY_ADC_CO 4 #define ADDR_FACTORY_ADC_NO2 6 @@ -52,9 +51,7 @@ #define ADDR_USER_ADC_HN3 8 #define ADDR_USER_ADC_CO 10 #define ADDR_USER_ADC_NO2 12 -#define ADDR_IF_CALI 14 // IF USER HAD CALI - -#define ADDR_I2C_ADDRESS 20 +#define ADDR_IF_CALI 14 #define CH_VALUE_NH3 1 #define CH_VALUE_CO 2 @@ -75,7 +72,6 @@ #define HEATER_ON 1 #define HEATER_OFF 0 - #ifdef _DEBUG extern Serial pc; #define DEBUG_PRINT(...) pc.printf(__VA_ARGS__) @@ -95,16 +91,16 @@ * Serial pc(USBTX, USBRX); * * #if defined(TARGET_LPC1768) - * MiCS6814_GasSensor _gases(p28, p27); + * MiCS6814_GasSensor sensor(p28, p27); * #else - * MiCS6814_GasSensor _gases(I2C_SDA, I2C_SCL); + * MiCS6814_GasSensor sensor(I2C_SDA, I2C_SCL); * #endif * * int main() { * * while(1) { - * pc.printf("NH3: %.2f ppm, CO: %.2f ppm, NO2: %.2f ppm, C3H8: %.2f ppm \r\n", _gases.calcGas(NH3), _gases.calcGas(CO), _gases.calcGas(NO2), _gases.calcGas(C3H8)); - * pc.printf("C4H10: %.2f ppm, CH4: %.2f ppm, H2: %.2f ppm, C2H5OH: %.2f ppm \r\n", _gases.calcGas(C4H10), _gases.calcGas(CH4), _gases.calcGas(H2), _gases.calcGas(C2H5OH)); + * pc.printf("NH3: %.2f ppm, CO: %.2f ppm, NO2: %.2f ppm, C3H8: %.2f ppm \r\n", sensor.getGas(NH3), sensor.getGas(CO), sensor.getGas(NO2), sensor.getGas(C3H8)); + * pc.printf("C4H10: %.2f ppm, CH4: %.2f ppm, H2: %.2f ppm, C2H5OH: %.2f ppm \r\n", sensor.getGas(C4H10), sensor.getGas(CH4), sensor.getGas(H2), sensor.getGas(C2H5OH)); * wait(1); * } * } @@ -123,19 +119,15 @@ public: /** Create a MiCS6814_GasSensor instance * the sensor is connected to specified I2C pins with specified address - * 1.Create an I2C instance - * 2.Initialize private variables. * * @param[in] sda I2C-bus SDA pin * @param[in] scl I2C-bus SCL pin * @param[in] slave_adr (option) I2C-bus address (default: 0x04<<1) */ - MiCS6814_GasSensor(PinName sda, PinName sck, char slave_adr = SLAVE_ADDRESS_MiCS6814); + MiCS6814_GasSensor(PinName sda, PinName scl, char slave_adr = SLAVE_ADDRESS_MiCS6814); /** Create a MiCS6814_GasSensor instance * the sensor is connected to specified I2C pins with specified address - * 1.Pass an I2C instance, - * 2.Initialize private variables. * * @param[in] i2c_obj I2C object (instance) * @param[in] slave_adr (option) I2C-bus address (default: 0x04<<1) @@ -143,15 +135,11 @@ MiCS6814_GasSensor(I2C &i2c_obj, char slave_adr = SLAVE_ADDRESS_MiCS6814); /** Destructor of MiCS6814_GasSensor - * 1.Power off heater - * 2.Release allocated heap memory. */ virtual ~MiCS6814_GasSensor(); /** Initialize MiCS6814_GasSensor - * 1.Read firmware version from sensor - * 2.Power on heater - * 3.Clear private variables + * Read firmware version from sensor and power on heater */ void initialize(void); @@ -160,13 +148,14 @@ * @param[in] gas_type one of gas type defined at enum GAS_TYPE * @return the measured concentration of specific gas type (ppm) */ - float calcGas(const enum GAS_TYPE gas_type); + float getGas(const enum GAS_TYPE gas_type); private: I2C *_i2c_p; I2C &_i2c; char _address; //I2C address of this MCU + /** Check firmware version of sensor * only support version 2 */ @@ -194,14 +183,14 @@ * @param[in] index {0,1,2} * @return return A0_[x] */ - uint16_t readR0_A0(unsigned char _indix); + uint16_t readR0_A0(unsigned char index); /** Read An_[x] of sensor * * @param[in] index {0,1,2} * @return return An_[x] */ - uint16_t readRs_An(unsigned char _indix); + uint16_t readRs_An(unsigned char index); }; #endif // MBED_MULTIGAS_SENSOR_H