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@9:07c1751a6d00, 2021-03-03 (annotated)
- Committer:
- runesla 
- Date:
- Wed Mar 03 15:22:39 2021 +0100
- Revision:
- 9:07c1751a6d00
- Parent:
- 8:705631dd7248
removed unnecessary constructor
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 | 2:c836ed5bafce | 29 | #include "mbed.h" | 
| runesla | 0:2fec9850cc9b | 30 | |
| runesla | 0:2fec9850cc9b | 31 | #define GM_RESOLUTION 1023 | 
| runesla | 0:2fec9850cc9b | 32 | |
| runesla | 0:2fec9850cc9b | 33 | //command | 
| runesla | 0:2fec9850cc9b | 34 | #define GM_102B 0x01 | 
| runesla | 0:2fec9850cc9b | 35 | #define GM_302B 0x03 | 
| runesla | 0:2fec9850cc9b | 36 | //#define GM_402B 0x04 | 
| runesla | 0:2fec9850cc9b | 37 | #define GM_502B 0x05 | 
| runesla | 0:2fec9850cc9b | 38 | #define GM_702B 0x07 | 
| runesla | 0:2fec9850cc9b | 39 | //#define GM_802B 0x08 | 
| runesla | 0:2fec9850cc9b | 40 | #define CHANGE_I2C_ADDR 0x55 | 
| runesla | 0:2fec9850cc9b | 41 | #define WARMING_UP 0xFE | 
| runesla | 0:2fec9850cc9b | 42 | #define WARMING_DOWN 0xFF | 
| runesla | 0:2fec9850cc9b | 43 | |
| runesla | 6:52d9088d70cd | 44 | class GAS_GMXXX | 
| runesla | 6:52d9088d70cd | 45 | { | 
| runesla | 9:07c1751a6d00 | 46 | public: | 
| runesla | 9:07c1751a6d00 | 47 | GAS_GMXXX(PinName sda, PinName scl, uint8_t addr = 0x08); | 
| runesla | 9:07c1751a6d00 | 48 | void init(); | 
| runesla | 9:07c1751a6d00 | 49 | void setAddress(uint8_t address = 0x08); | 
| runesla | 9:07c1751a6d00 | 50 | void preheated(); | 
| runesla | 9:07c1751a6d00 | 51 | void unPreheated(); | 
| runesla | 9:07c1751a6d00 | 52 | void changeGMXXXAddr(uint8_t address = 0x08); | 
| runesla | 9:07c1751a6d00 | 53 | uint32_t measure_NO2() | 
| runesla | 9:07c1751a6d00 | 54 | { | 
| runesla | 9:07c1751a6d00 | 55 | return getGM102B(); | 
| runesla | 9:07c1751a6d00 | 56 | }; | 
| runesla | 9:07c1751a6d00 | 57 | uint32_t getGM102B(); | 
| runesla | 9:07c1751a6d00 | 58 | uint32_t measure_C2H5OH() | 
| runesla | 9:07c1751a6d00 | 59 | { | 
| runesla | 9:07c1751a6d00 | 60 | return getGM302B(); | 
| runesla | 9:07c1751a6d00 | 61 | }; | 
| runesla | 9:07c1751a6d00 | 62 | uint32_t getGM302B(); | 
| runesla | 9:07c1751a6d00 | 63 | #ifdef GM_402B | 
| runesla | 9:07c1751a6d00 | 64 | uint32_t getGM402B(); | 
| runesla | 9:07c1751a6d00 | 65 | #endif | 
| runesla | 9:07c1751a6d00 | 66 | uint32_t measure_VOC() | 
| runesla | 9:07c1751a6d00 | 67 | { | 
| runesla | 9:07c1751a6d00 | 68 | return getGM502B(); | 
| runesla | 9:07c1751a6d00 | 69 | }; | 
| runesla | 9:07c1751a6d00 | 70 | uint32_t getGM502B(); | 
| runesla | 9:07c1751a6d00 | 71 | uint32_t measure_CO() | 
| runesla | 9:07c1751a6d00 | 72 | { | 
| runesla | 9:07c1751a6d00 | 73 | return getGM702B(); | 
| runesla | 9:07c1751a6d00 | 74 | }; | 
| runesla | 9:07c1751a6d00 | 75 | uint32_t getGM702B(); | 
| runesla | 9:07c1751a6d00 | 76 | #ifdef GM_802B | 
| runesla | 9:07c1751a6d00 | 77 | uint32_t getGM802B(); | 
| runesla | 9:07c1751a6d00 | 78 | #endif | 
| runesla | 9:07c1751a6d00 | 79 | inline float calcVol(uint32_t adc) | 
| runesla | 9:07c1751a6d00 | 80 | { | 
| runesla | 9:07c1751a6d00 | 81 | return (adc * 3.3) / GM_RESOLUTION; | 
| runesla | 9:07c1751a6d00 | 82 | }; | 
| runesla | 9:07c1751a6d00 | 83 | void read(); | 
| runesla | 9:07c1751a6d00 | 84 | bool gas_detected(); | 
| runesla | 9:07c1751a6d00 | 85 | float get_no2(); | 
| runesla | 9:07c1751a6d00 | 86 | float get_c2h5oh(); | 
| runesla | 9:07c1751a6d00 | 87 | float get_voc(); | 
| runesla | 9:07c1751a6d00 | 88 | float get_co(); | 
| runesla | 9:07c1751a6d00 | 89 | private: | 
| runesla | 9:07c1751a6d00 | 90 | I2C* _i2c_p; | 
| runesla | 9:07c1751a6d00 | 91 | I2C& _i2c; | 
| runesla | 8:705631dd7248 | 92 | |
| runesla | 9:07c1751a6d00 | 93 | float _no2, _c2h5oh, _voc, _co; | 
| runesla | 8:705631dd7248 | 94 | |
| runesla | 9:07c1751a6d00 | 95 | bool isPreheated; | 
| runesla | 9:07c1751a6d00 | 96 | bool gasDetected; | 
| runesla | 9:07c1751a6d00 | 97 | uint8_t GMXXX_ADDRESS; | 
| runesla | 9:07c1751a6d00 | 98 | void GMXXXWriteByte(uint8_t cmd); | 
| runesla | 9:07c1751a6d00 | 99 | uint32_t GMXXXRead32(); | 
| runesla | 0:2fec9850cc9b | 100 | }; | 
| runesla | 0:2fec9850cc9b | 101 | #endif |