Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
471 changes: 471 additions & 0 deletions lib/lib_i2c/DFRobot_MICS-master/DFRobot_MICS.cpp

Large diffs are not rendered by default.

185 changes: 185 additions & 0 deletions lib/lib_i2c/DFRobot_MICS-master/DFRobot_MICS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*!
* @file DFRobot_MICS.h
* @brief Define the basic structure of class DFRobot_MicsSensor
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author [ZhixinLiu]([email protected])
* @version V1.1
* @date 2020-4-20
* @url https://github.com/DFRobot/DFRobot_MICS
*/
#ifndef __DFROBOT_MICS_H__
#define __DFROBOT_MICS_H__
#include <Arduino.h>
#include <Wire.h>

#define ENABLE_DBG ///< Open this macro to see the program running in detail

#ifdef ENABLE_DBG
#define DBG(...) {Serial.print("[");Serial.print(__FUNCTION__); Serial.print("(): "); Serial.print(__LINE__); Serial.print(" ] "); Serial.println(__VA_ARGS__);}
#else
#define DBG(...)
#endif

#define MICS_ADDRESS_0 0x75
#define MICS_ADDRESS_1 0x76
#define MICS_ADDRESS_2 0x77
#define MICS_ADDRESS_3 0x78
#define OX_REGISTER_HIGH 0x04
#define OX_REGISTER_LOW 0x05
#define RED_REGISTER_HIGH 0x06
#define RED_REGISTER_LOW 0x07
#define POWER_REGISTER_HIGH 0x08
#define POWER_REGISTER_LOW 0x09
#define POWER_MODE_REGISTER 0x0a
#define SLEEP_MODE 0x00
#define WAKE_UP_MODE 0x01
#define OX_MODE 0x00
#define RED_MODE 0x01
#define ERROR -1
#define EXIST 0x00
#define NO_EXIST 0x02

#define CO 0x01 ///< Carbon Monoxide
#define CH4 0x02 ///< Methane
#define C2H5OH 0x03 ///< Ethanol
#define C3H8 0x04 ///< Propane
#define C4H10 0x05 ///< Iso Butane
#define H2 0x06 ///< Hydrogen
#define H2S 0x07 ///< Hydrothion
#define NH3 0x08 ///< Ammonia
#define NO 0x09 ///< Nitric Oxide
#define NO2 0x0A ///< Nitrogen Dioxide


class DFRobot_MICS{
public:
DFRobot_MICS();
~DFRobot_MICS();

/**
* @fn warmUpTime
* @brief Waiting time for warm-up
* @param minute Units of minutes
* @return bool type
* @retval true is warm-up success
* @retval false is wait warm-up
*/
bool warmUpTime(uint8_t minute);

/**
* @fn getADCData
* @brief Read sensor ADC data
* @param mode oxmode redmode
* @n OX_MODE
* @n RED_MODE
* @return adcValue (0-1024)
*/
int16_t getADCData(uint8_t mode);

/**
* @fn getGasData
* @brief Read the concentration of the gas
* @param type gas type
* @n Methane (CH4) (1000 - 25000)PPM
* @n Ethanol (C2H5OH) (10 - 500)PPM
* @n Hydrogen (H2) (1 - 1000)PPM
* @n Ammonia (NH3) (1 - 500)PPM
* @n Carbon Monoxide (CO) (1 - 1000)PPM
* @n Nitrogen Dioxide (NO2) (0.1 - 10)PPM
* @return concentration Units of PPM
*/
float getGasData(uint8_t type);

/**
* @fn getGasExist
* @brief Read whether the gas is present
* @param gas type
* @n CO = 0x01 (Carbon Monoxide)
* @n CH4 = 0x02 (Methane)
* @n C2H5OH = 0x03 (Ethanol)
* @n C3H8 = 0x04 (Propane)
* @n C4H10 = 0x05 (Iso Butane)
* @n H2 = 0x06 (Hydrogen)
* @n H2S = 0x07 (Hydrothion)
* @n NH3 = 0x08 (Ammonia)
* @n NO = 0x09 (Nitric Oxide)
* @n NO2 = 0x0A (Nitrogen Dioxide)
* @return state
* @retval NO_EXIST
* @retval EXIST
*/
int8_t getGasExist(uint8_t gas);

/**
* @fn sleepMode
* @brief Sleep sensor
*/
void sleepMode(void);

/**
* @fn wakeUpMode
* @brief wakeup sensor
*/
void wakeUpMode(void);

/**
* @fn getPowerState
* @brief Gets the power mode of the sensor
* @return state
* @retval SLEEP_MODE
* @retval WAKE_UP_MODE
*/
uint8_t getPowerState(void);

private:
int16_t __r0_ox = 0;
int16_t __r0_red = 0;
uint32_t __nowTime = 0;
uint8_t __flag = 0;
int16_t getSensorData(uint16_t *oxData ,uint16_t *redData ,uint16_t *powerData);
float getCarbonMonoxide(float data);
float getMethane(float data);
float getEthanol(float data);
float getHydrogen(float data);
float getAmmonia(float data);
float getNitrogenDioxide(float data);
bool existPropane(float data);
bool existNitricOxide(float data);
bool existIsoButane(float data);
bool existHydrothion(float data);
bool existCarbonMonoxide(float data);
bool existMethane(float data);
bool existEthanol(float data);
bool existHydrogen(float data);
bool existAmmonia(float data);
bool existNitrogenDioxide(float data);
virtual void writeData(uint8_t reg ,uint8_t *data ,uint8_t len) = 0;
virtual int16_t readData(uint8_t reg ,uint8_t *data ,uint8_t len) = 0;
};

class DFRobot_MICS_I2C:public DFRobot_MICS{
public:
DFRobot_MICS_I2C(TwoWire *pWire=&Wire ,uint8_t addr = MICS_ADDRESS_3);
bool begin(void);
protected:
virtual void writeData(uint8_t reg ,uint8_t *data ,uint8_t len);
virtual int16_t readData(uint8_t reg ,uint8_t *data ,uint8_t len);
private:
TwoWire *_pWire;
uint8_t _I2C_addr;
};

class DFRobot_MICS_ADC:public DFRobot_MICS{
public:
DFRobot_MICS_ADC(uint8_t adcPin = A0, uint8_t powerPin = 10);
bool begin(void);
protected:
virtual void writeData(uint8_t reg ,uint8_t *data ,uint8_t len);
virtual int16_t readData(uint8_t reg ,uint8_t *data ,uint8_t len);
private:
uint8_t __powerPin = 0;
uint8_t __adcPin = 0;
};

#endif
21 changes: 21 additions & 0 deletions lib/lib_i2c/DFRobot_MICS-master/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 DFRobot

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
146 changes: 146 additions & 0 deletions lib/lib_i2c/DFRobot_MICS-master/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# DFRobot_MICS
- [中文版](./README_CN.md)

This is a 3.3/5V compatible MEMS gas concentration sensor from DFRobot. This sensor supports the detection of various gas concentrations like CO, C2H5OH (Alcohol), H2, NO2, NH3, and integrates various gas concentration conversion formulas in the code to facilitate the testing and use of sensors. With I2C output and 3.3~5.5V wide voltage input, it is compatible with Arduino, ESP32, Raspberry Pi and other mainstream controllers.<br>

![效果图](resources/images/SEN0377.jpg)


## Product Link(https://www.dfrobot.com/product-2417.html)

SKU:SEN0377

## Table of Contents

* [Summary](#Summary)
* [Installation](#Installation)
* [Methods](#Methods)
* [Compatibility](#Compatibility)
* [History](#History)
* [Credits](#Credits)

## Summary

- Detection of Physical Quantities: gas concentration of CO,C2H5OH(Alcohol), H2, NO2, NH3, CH4<br>
- Operating Voltage: 3.3~5.5V DC<br>
- Power Dissipation: 0.45W(5V)<br>
- Output Signal: I2C(0~3V)<br>
- Measuring Range:<br>
1 – 1000ppm(Carbon monoxide CO )<br>
0.05 – 10ppm(Nitrogen dioxide NO2 )<br>
10 – 500ppm( Ethanol C2H5OH )<br>
1 – 1000ppm(Hydrogen H2)<br>
1 – 500ppm(Ammonia NH3 )<br>
1000 - ∞ ppm(Methane CH4 )<br>
- Working Temperature: -30~85℃<br>
- Working Humidity: 5~95%RH (No condensation)<br>
- Storage Temperature: -40~85℃<br>
- Lifespan: >2 years (in the air)<br>
- Circuit Board Size: 27mm*37mm<br>
- Mounting Hole Size: inner diameter 3.1mm/outer diameter 6mm<br>

## Installation
There are two methods for using this library:<br>
1. Open Arduino IDE, search for "DFRobot_MICS" on the status bar in Tools ->Manager Libraries and install the library.<br>
2. Download the library file before use, paste it into \Arduino\libraries directory, then open the examples folder and run the demo in the folder.<br>

## Methods

```C++
/**
* @fn warmUpTime
* @brief Waiting time for warm-up
* @param minute Units of minutes
* @return bool type
* @retval true is warm-up success
* @retval false is wait warm-up
*/
bool warmUpTime(uint8_t minute);

/**
* @fn getADCData
* @brief Read sensor ADC data
* @param mode oxmode redmode
* @n OX_MODE
* @n RED_MODE
* @return adcValue (0-1024)
*/
int16_t getADCData(uint8_t mode);

/**
* @fn getGasData
* @brief Read the concentration of the gas
* @param type gas type
* @n Methane (CH4) (1000 - 25000)PPM
* @n Ethanol (C2H5OH) (10 - 500)PPM
* @n Hydrogen (H2) (1 - 1000)PPM
* @n Ammonia (NH3) (1 - 500)PPM
* @n Carbon Monoxide (CO) (1 - 1000)PPM
* @n Nitrogen Dioxide (NO2) (0.1 - 10)PPM
* @return concentration Units of PPM
*/
float getGasData(uint8_t type);

/**
* @fn getGasExist
* @brief Read whether the gas is present
* @param gas type
* @n CO = 0x01 (Carbon Monoxide)
* @n CH4 = 0x02 (Methane)
* @n C2H5OH = 0x03 (Ethanol)
* @n C3H8 = 0x04 (Propane)
* @n C4H10 = 0x05 (Iso Butane)
* @n H2 = 0x06 (Hydrogen)
* @n H2S = 0x07 (Hydrothion)
* @n NH3 = 0x08 (Ammonia)
* @n NO = 0x09 (Nitric Oxide)
* @n NO2 = 0x0A (Nitrogen Dioxide)
* @return state
* @retval NO_EXIST
* @retval EXIST
*/
int8_t getGasExist(uint8_t gas);

/**
* @fn sleepMode
* @brief Sleep sensor
*/
void sleepMode(void);

/**
* @fn wakeUpMode
* @brief wakeup sensor
*/
void wakeUpMode(void);

/**
* @fn getPowerState
* @brief Gets the power mode of the sensor
* @return state
* @retval SLEEP_MODE
* @retval WAKE_UP_MODE
*/
uint8_t getPowerState(void);

```

## Compatibility

MCU | Work Well | Work Wrong | Untested | Remarks
------------------ | :----------: | :----------: | :---------: | :----:
Arduino Uno | √ | | |
Arduino MEGA2560 | √ | | |
Arduino Leonardo | √ | | |
FireBeetle-ESP32 | √ | | |
Micro:bit | | | √ |


## History

- 2021/1/13 - V1.0.0 Version
- 2021/4/20 - V1.1.0 Version
- 2021/7/18 - V1.2.0 Version

## Credits

Written by ZhixinLiu([email protected]), 2020. (Welcome to our [website](https://www.dfrobot.com/))
Loading