Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Multichannel_Gas_GMXXX.h@1:f0e19383efb9, 2021-02-03 (annotated)
- Committer:
- runesla
- Date:
- Wed Feb 03 17:03:19 2021 +0100
- Revision:
- 1:f0e19383efb9
- Parent:
- 0:2fec9850cc9b
- Child:
- 2:c836ed5bafce
missing inttypes
Who changed what in which revision?
User | Revision | Line number | New 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 |
1:f0e19383efb9 | 28 | #include <inttypes.h> |
runesla |
1:f0e19383efb9 | 29 | |
runesla |
0:2fec9850cc9b | 30 | //#define SOFTWAREWIRE |
runesla |
0:2fec9850cc9b | 31 | /*#ifdef SOFTWAREWIRE |
runesla |
0:2fec9850cc9b | 32 | #include <SoftwareWire.h> |
runesla |
0:2fec9850cc9b | 33 | #else |
runesla |
0:2fec9850cc9b | 34 | #include <Wire.h> |
runesla |
0:2fec9850cc9b | 35 | #endif |
runesla |
0:2fec9850cc9b | 36 | */ |
runesla |
0:2fec9850cc9b | 37 | |
runesla |
0:2fec9850cc9b | 38 | #define GM_RESOLUTION 1023 |
runesla |
0:2fec9850cc9b | 39 | |
runesla |
0:2fec9850cc9b | 40 | //command |
runesla |
0:2fec9850cc9b | 41 | #define GM_102B 0x01 |
runesla |
0:2fec9850cc9b | 42 | #define GM_302B 0x03 |
runesla |
0:2fec9850cc9b | 43 | //#define GM_402B 0x04 |
runesla |
0:2fec9850cc9b | 44 | #define GM_502B 0x05 |
runesla |
0:2fec9850cc9b | 45 | #define GM_702B 0x07 |
runesla |
0:2fec9850cc9b | 46 | //#define GM_802B 0x08 |
runesla |
0:2fec9850cc9b | 47 | #define CHANGE_I2C_ADDR 0x55 |
runesla |
0:2fec9850cc9b | 48 | #define WARMING_UP 0xFE |
runesla |
0:2fec9850cc9b | 49 | #define WARMING_DOWN 0xFF |
runesla |
0:2fec9850cc9b | 50 | |
runesla |
0:2fec9850cc9b | 51 | template <class T> |
runesla |
0:2fec9850cc9b | 52 | class GAS_GMXXX { |
runesla |
0:2fec9850cc9b | 53 | public: |
runesla |
0:2fec9850cc9b | 54 | GAS_GMXXX(); |
runesla |
0:2fec9850cc9b | 55 | void begin(T& wire = Wire, uint8_t address = 0x08); |
runesla |
0:2fec9850cc9b | 56 | void setAddress(uint8_t address = 0x08); |
runesla |
0:2fec9850cc9b | 57 | void preheated(); |
runesla |
0:2fec9850cc9b | 58 | void unPreheated(); |
runesla |
0:2fec9850cc9b | 59 | void changeGMXXXAddr(uint8_t address = 0x08); |
runesla |
0:2fec9850cc9b | 60 | uint32_t measure_NO2(){ |
runesla |
0:2fec9850cc9b | 61 | return getGM102B(); |
runesla |
0:2fec9850cc9b | 62 | }; |
runesla |
0:2fec9850cc9b | 63 | uint32_t getGM102B(); |
runesla |
0:2fec9850cc9b | 64 | uint32_t measure_C2H5OH(){ |
runesla |
0:2fec9850cc9b | 65 | return getGM302B(); |
runesla |
0:2fec9850cc9b | 66 | }; |
runesla |
0:2fec9850cc9b | 67 | uint32_t getGM302B(); |
runesla |
0:2fec9850cc9b | 68 | #ifdef GM_402B |
runesla |
0:2fec9850cc9b | 69 | uint32_t getGM402B(); |
runesla |
0:2fec9850cc9b | 70 | #endif |
runesla |
0:2fec9850cc9b | 71 | uint32_t measure_VOC(){ |
runesla |
0:2fec9850cc9b | 72 | return getGM502B(); |
runesla |
0:2fec9850cc9b | 73 | }; |
runesla |
0:2fec9850cc9b | 74 | uint32_t getGM502B(); |
runesla |
0:2fec9850cc9b | 75 | uint32_t measure_CO(){ |
runesla |
0:2fec9850cc9b | 76 | return getGM702B(); |
runesla |
0:2fec9850cc9b | 77 | }; |
runesla |
0:2fec9850cc9b | 78 | uint32_t getGM702B(); |
runesla |
0:2fec9850cc9b | 79 | #ifdef GM_802B |
runesla |
0:2fec9850cc9b | 80 | uint32_t getGM802B(); |
runesla |
0:2fec9850cc9b | 81 | #endif |
runesla |
0:2fec9850cc9b | 82 | inline float calcVol(uint32_t adc) { |
runesla |
0:2fec9850cc9b | 83 | return (adc * 3.3) / GM_RESOLUTION; |
runesla |
0:2fec9850cc9b | 84 | }; |
runesla |
0:2fec9850cc9b | 85 | private: |
runesla |
0:2fec9850cc9b | 86 | T* _Wire; |
runesla |
0:2fec9850cc9b | 87 | bool isPreheated; |
runesla |
0:2fec9850cc9b | 88 | uint8_t GMXXX_ADDRESS; |
runesla |
0:2fec9850cc9b | 89 | void GMXXXWriteByte(uint8_t cmd); |
runesla |
0:2fec9850cc9b | 90 | uint32_t GMXXXRead32(); |
runesla |
0:2fec9850cc9b | 91 | }; |
runesla |
0:2fec9850cc9b | 92 | #endif |