Rune L / Multichannel_Gas_Sensor
Committer:
runesla
Date:
Wed Feb 03 16:41:34 2021 +0100
Revision:
0:2fec9850cc9b
Child:
1:f0e19383efb9
init

Who changed what in which revision?

UserRevisionLine numberNew contents of line
runesla 0:2fec9850cc9b 1 /*
runesla 0:2fec9850cc9b 2 Multichannel_Gas_GMXXX.h
runesla 0:2fec9850cc9b 3 Description: A drive for Seeed Grove Multichannel gas sensor V2.0.
runesla 0:2fec9850cc9b 4 2019 Copyright (c) Seeed Technology Inc. All right reserved.
runesla 0:2fec9850cc9b 5 Author: Hongtai Liu(lht856@foxmail.com)
runesla 0:2fec9850cc9b 6 2019-6-18
runesla 0:2fec9850cc9b 7
runesla 0:2fec9850cc9b 8 The MIT License (MIT)
runesla 0:2fec9850cc9b 9 Permission is hereby granted, free of charge, to any person obtaining a copy
runesla 0:2fec9850cc9b 10 of this software and associated documentation files (the "Software"), to deal
runesla 0:2fec9850cc9b 11 in the Software without restriction, including without limitation the rights
runesla 0:2fec9850cc9b 12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
runesla 0:2fec9850cc9b 13 copies of the Software, and to permit persons to whom the Software is
runesla 0:2fec9850cc9b 14 furnished to do so, subject to the following conditions:
runesla 0:2fec9850cc9b 15 The above copyright notice and this permission notice shall be included in
runesla 0:2fec9850cc9b 16 all copies or substantial portions of the Software.
runesla 0:2fec9850cc9b 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
runesla 0:2fec9850cc9b 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
runesla 0:2fec9850cc9b 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
runesla 0:2fec9850cc9b 20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
runesla 0:2fec9850cc9b 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
runesla 0:2fec9850cc9b 22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
runesla 0:2fec9850cc9b 23 THE SOFTWARE.1 USA
runesla 0:2fec9850cc9b 24 */
runesla 0:2fec9850cc9b 25 #ifndef __GAS_GMXXX__
runesla 0:2fec9850cc9b 26 #define __GAS_GMXXX__
runesla 0:2fec9850cc9b 27
runesla 0:2fec9850cc9b 28 //#define SOFTWAREWIRE
runesla 0:2fec9850cc9b 29 /*#ifdef SOFTWAREWIRE
runesla 0:2fec9850cc9b 30 #include <SoftwareWire.h>
runesla 0:2fec9850cc9b 31 #else
runesla 0:2fec9850cc9b 32 #include <Wire.h>
runesla 0:2fec9850cc9b 33 #endif
runesla 0:2fec9850cc9b 34 */
runesla 0:2fec9850cc9b 35
runesla 0:2fec9850cc9b 36 #define GM_RESOLUTION 1023
runesla 0:2fec9850cc9b 37
runesla 0:2fec9850cc9b 38 //command
runesla 0:2fec9850cc9b 39 #define GM_102B 0x01
runesla 0:2fec9850cc9b 40 #define GM_302B 0x03
runesla 0:2fec9850cc9b 41 //#define GM_402B 0x04
runesla 0:2fec9850cc9b 42 #define GM_502B 0x05
runesla 0:2fec9850cc9b 43 #define GM_702B 0x07
runesla 0:2fec9850cc9b 44 //#define GM_802B 0x08
runesla 0:2fec9850cc9b 45 #define CHANGE_I2C_ADDR 0x55
runesla 0:2fec9850cc9b 46 #define WARMING_UP 0xFE
runesla 0:2fec9850cc9b 47 #define WARMING_DOWN 0xFF
runesla 0:2fec9850cc9b 48
runesla 0:2fec9850cc9b 49 template <class T>
runesla 0:2fec9850cc9b 50 class GAS_GMXXX {
runesla 0:2fec9850cc9b 51 public:
runesla 0:2fec9850cc9b 52 GAS_GMXXX();
runesla 0:2fec9850cc9b 53 void begin(T& wire = Wire, uint8_t address = 0x08);
runesla 0:2fec9850cc9b 54 void setAddress(uint8_t address = 0x08);
runesla 0:2fec9850cc9b 55 void preheated();
runesla 0:2fec9850cc9b 56 void unPreheated();
runesla 0:2fec9850cc9b 57 void changeGMXXXAddr(uint8_t address = 0x08);
runesla 0:2fec9850cc9b 58 uint32_t measure_NO2(){
runesla 0:2fec9850cc9b 59 return getGM102B();
runesla 0:2fec9850cc9b 60 };
runesla 0:2fec9850cc9b 61 uint32_t getGM102B();
runesla 0:2fec9850cc9b 62 uint32_t measure_C2H5OH(){
runesla 0:2fec9850cc9b 63 return getGM302B();
runesla 0:2fec9850cc9b 64 };
runesla 0:2fec9850cc9b 65 uint32_t getGM302B();
runesla 0:2fec9850cc9b 66 #ifdef GM_402B
runesla 0:2fec9850cc9b 67 uint32_t getGM402B();
runesla 0:2fec9850cc9b 68 #endif
runesla 0:2fec9850cc9b 69 uint32_t measure_VOC(){
runesla 0:2fec9850cc9b 70 return getGM502B();
runesla 0:2fec9850cc9b 71 };
runesla 0:2fec9850cc9b 72 uint32_t getGM502B();
runesla 0:2fec9850cc9b 73 uint32_t measure_CO(){
runesla 0:2fec9850cc9b 74 return getGM702B();
runesla 0:2fec9850cc9b 75 };
runesla 0:2fec9850cc9b 76 uint32_t getGM702B();
runesla 0:2fec9850cc9b 77 #ifdef GM_802B
runesla 0:2fec9850cc9b 78 uint32_t getGM802B();
runesla 0:2fec9850cc9b 79 #endif
runesla 0:2fec9850cc9b 80 inline float calcVol(uint32_t adc) {
runesla 0:2fec9850cc9b 81 return (adc * 3.3) / GM_RESOLUTION;
runesla 0:2fec9850cc9b 82 };
runesla 0:2fec9850cc9b 83 private:
runesla 0:2fec9850cc9b 84 T* _Wire;
runesla 0:2fec9850cc9b 85 bool isPreheated;
runesla 0:2fec9850cc9b 86 uint8_t GMXXX_ADDRESS;
runesla 0:2fec9850cc9b 87 void GMXXXWriteByte(uint8_t cmd);
runesla 0:2fec9850cc9b 88 uint32_t GMXXXRead32();
runesla 0:2fec9850cc9b 89 };
runesla 0:2fec9850cc9b 90 #endif