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@6:52d9088d70cd, 2021-02-10 (annotated)
- Committer:
- runesla
- Date:
- Wed Feb 10 19:05:31 2021 +0100
- Revision:
- 6:52d9088d70cd
- Parent:
- 2:c836ed5bafce
- Child:
- 7:3405d48c39bd
tidying up
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 |
0:2fec9850cc9b | 46 | public: |
runesla |
2:c836ed5bafce | 47 | GAS_GMXXX(PinName sda, PinName scl, uint8_t addr = 0x08); |
runesla |
2:c836ed5bafce | 48 | //void begin(); |
runesla |
2:c836ed5bafce | 49 | void init(); |
runesla |
0:2fec9850cc9b | 50 | void setAddress(uint8_t address = 0x08); |
runesla |
0:2fec9850cc9b | 51 | void preheated(); |
runesla |
0:2fec9850cc9b | 52 | void unPreheated(); |
runesla |
0:2fec9850cc9b | 53 | void changeGMXXXAddr(uint8_t address = 0x08); |
runesla |
6:52d9088d70cd | 54 | uint32_t measure_NO2() |
runesla |
6:52d9088d70cd | 55 | { |
runesla |
0:2fec9850cc9b | 56 | return getGM102B(); |
runesla |
0:2fec9850cc9b | 57 | }; |
runesla |
0:2fec9850cc9b | 58 | uint32_t getGM102B(); |
runesla |
6:52d9088d70cd | 59 | uint32_t measure_C2H5OH() |
runesla |
6:52d9088d70cd | 60 | { |
runesla |
0:2fec9850cc9b | 61 | return getGM302B(); |
runesla |
0:2fec9850cc9b | 62 | }; |
runesla |
0:2fec9850cc9b | 63 | uint32_t getGM302B(); |
runesla |
0:2fec9850cc9b | 64 | #ifdef GM_402B |
runesla |
0:2fec9850cc9b | 65 | uint32_t getGM402B(); |
runesla |
0:2fec9850cc9b | 66 | #endif |
runesla |
6:52d9088d70cd | 67 | uint32_t measure_VOC() |
runesla |
6:52d9088d70cd | 68 | { |
runesla |
0:2fec9850cc9b | 69 | return getGM502B(); |
runesla |
0:2fec9850cc9b | 70 | }; |
runesla |
0:2fec9850cc9b | 71 | uint32_t getGM502B(); |
runesla |
6:52d9088d70cd | 72 | uint32_t measure_CO() |
runesla |
6:52d9088d70cd | 73 | { |
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 |
6:52d9088d70cd | 80 | inline float calcVol(uint32_t adc) |
runesla |
6:52d9088d70cd | 81 | { |
runesla |
0:2fec9850cc9b | 82 | return (adc * 3.3) / GM_RESOLUTION; |
runesla |
0:2fec9850cc9b | 83 | }; |
runesla |
0:2fec9850cc9b | 84 | private: |
runesla |
2:c836ed5bafce | 85 | I2C* _i2c_p; |
runesla |
2:c836ed5bafce | 86 | I2C& _i2c; |
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 |