SparkFun GM-X02B Arduino Library  v1.0.1
An Arduino library for the SparkFun Qwiic MEMS gas sensor breakouts built on the Winsen GM-x02B sensor family
Loading...
Searching...
No Matches
SparkFun_GMX02B.h
Go to the documentation of this file.
1
32#pragma once
33
34// clang-format off
35#include <SparkFun_Toolkit.h>
36#include "sfTk/sfDevGMX02B.h"
37#include <Arduino.h>
38// clang-format on
39
54{
55 public:
63 {
64 }
65
77 bool begin(TwoWire &wirePort = Wire)
78 {
79 return begin(getDefaultAddress(), wirePort);
80 }
81
93 bool begin(uint8_t address, TwoWire &wirePort = Wire)
94 {
95 // Initialize the Toolkit I2C bus with the given Wire port and address.
96 if (_theI2CBus.init(wirePort, address) != ksfTkErrOk)
97 return false;
98
99 // Confirm a device is actually responding at this address before we read from it.
100 if (_theI2CBus.ping() != ksfTkErrOk)
101 return false;
102
103 // The base class begin() confirms the ADC responds to a register read.
104 return sfDevGMX02B::begin(&_theI2CBus) == ksfTkErrOk;
105 }
106
117 bool begin(sfe_gmx02b_sensor_t sensor, TwoWire &wirePort = Wire)
118 {
119 if (!setSensorType(sensor))
120 return false;
121
122 return begin(getDefaultAddress(), wirePort);
123 }
124
129 uint8_t getAddress(void)
130 {
131 return _theI2CBus.address();
132 }
133
134 private:
136 sfTkArdI2C _theI2CBus;
137};
138
140// Per-Part Arduino Classes
142//
143// One thin class per board, following the same per-part pattern as the INA2XX library. Each passes
144// its part to the generic constructor, so the part is set by the class type rather than by an
145// argument:
146//
147// SfeGM602BArd gasSensor; // no enum to pass
148// gasSensor.begin(); // 0x58
149// gasSensor.begin(0x51); // re-jumpered board
150//
151// Prefer these for a sketch that knows its board at compile time. Use SfeGMX02BArd directly
152// when the part is chosen at runtime, or when you want one array holding several boards (see
153// Example05).
154
169{
170 public:
174};
175
187{
188 public:
192};
193
205{
206 public:
210};
211
223{
224 public:
228};
229
241{
242 public:
246};
247
259{
260 public:
264};
265
277{
278 public:
282};
283
297{
298 public:
302};
303
315{
316 public:
320};
Arduino I2C implementation for the SparkFun Qwiic GM-102B gas sensor breakout (nitrogen dioxide (NO2)...
Definition SparkFun_GMX02B.h:169
SfeGM102BArd()
Definition SparkFun_GMX02B.h:171
Arduino I2C implementation for the SparkFun Qwiic GM-202B gas sensor breakout (ethanol and smoke).
Definition SparkFun_GMX02B.h:187
SfeGM202BArd()
Definition SparkFun_GMX02B.h:189
Arduino I2C implementation for the SparkFun Qwiic GM-302B gas sensor breakout (alcohol and ethanol va...
Definition SparkFun_GMX02B.h:205
SfeGM302BArd()
Definition SparkFun_GMX02B.h:207
Arduino I2C implementation for the SparkFun Qwiic GM-402B gas sensor breakout (methane and propane).
Definition SparkFun_GMX02B.h:223
SfeGM402BArd()
Definition SparkFun_GMX02B.h:225
Arduino I2C implementation for the SparkFun Qwiic GM-502B gas sensor breakout (VOCs).
Definition SparkFun_GMX02B.h:241
SfeGM502BArd()
Definition SparkFun_GMX02B.h:243
Arduino I2C implementation for the SparkFun Qwiic GM-512B gas sensor breakout (breath odor (H2S,...
Definition SparkFun_GMX02B.h:259
SfeGM512BArd()
Definition SparkFun_GMX02B.h:261
Arduino I2C implementation for the SparkFun Qwiic GM-602B gas sensor breakout (hydrogen sulfide (H2S)...
Definition SparkFun_GMX02B.h:277
SfeGM602BArd()
Definition SparkFun_GMX02B.h:279
Arduino I2C implementation for the SparkFun Qwiic GM-702B gas sensor breakout (carbon monoxide (CO)).
Definition SparkFun_GMX02B.h:297
SfeGM702BArd()
Definition SparkFun_GMX02B.h:299
Arduino I2C implementation for the SparkFun Qwiic GM-802B gas sensor breakout (ammonia (NH3)).
Definition SparkFun_GMX02B.h:315
SfeGM802BArd()
Definition SparkFun_GMX02B.h:317
Arduino I2C implementation for the SparkFun Qwiic GM-x02B gas sensor breakouts.
Definition SparkFun_GMX02B.h:54
uint8_t getAddress(void)
Get the 7-bit I2C address this object is communicating on.
Definition SparkFun_GMX02B.h:129
SfeGMX02BArd(sfe_gmx02b_sensor_t sensor)
Construct a driver for a specific board variant.
Definition SparkFun_GMX02B.h:62
bool begin(uint8_t address, TwoWire &wirePort=Wire)
Initialize the board at an explicit I2C address.
Definition SparkFun_GMX02B.h:93
bool begin(sfe_gmx02b_sensor_t sensor, TwoWire &wirePort=Wire)
Declare the sensor variant and initialize it, in one call.
Definition SparkFun_GMX02B.h:117
bool begin(TwoWire &wirePort=Wire)
Initialize the board at the declared part's factory-default I2C address.
Definition SparkFun_GMX02B.h:77
Platform-independent driver for the SparkFun Qwiic MEMS gas sensor breakouts.
Definition sfDevGMX02B.h:172
sfTkError_t begin(sfTkIBus *theBus=nullptr)
Initialize the device driver with the given bus.
Definition sfDevGMX02B.cpp:171
bool setSensorType(sfe_gmx02b_sensor_t sensor)
Declare which family member is installed.
Definition sfDevGMX02B.cpp:237
uint8_t getDefaultAddress(void)
Get the factory-default I2C address for the current sensor variant.
Definition sfDevGMX02B.cpp:274
Header file for the SparkFun Winsen GM-X02B MEMS Gas Sensor Driver.
sfe_gmx02b_sensor_t
The Winsen GM-x02B sensing elements carried by the SparkFun Qwiic gas sensor boards.
Definition sfDevGMX02B.h:63
@ GM_302B
GM-302B - alcohol and ethanol vapor.
Definition sfDevGMX02B.h:66
@ GM_102B
GM-102B - nitrogen dioxide (NO2). Rs RISES with gas.
Definition sfDevGMX02B.h:64
@ GM_602B
GM-602B - hydrogen sulfide (H2S) and benzene.
Definition sfDevGMX02B.h:70
@ GM_702B
GM-702B - carbon monoxide (CO) and hydrogen.
Definition sfDevGMX02B.h:71
@ GM_202B
GM-202B - ethanol and smoke.
Definition sfDevGMX02B.h:65
@ GM_402B
GM-402B - methane and propane (combustibles).
Definition sfDevGMX02B.h:67
@ GM_502B
GM-502B - VOCs (ethanol, formaldehyde, toluene).
Definition sfDevGMX02B.h:68
@ GM_512B
GM-512B - breath odor (H2S, ethanol, acetone).
Definition sfDevGMX02B.h:69
@ GM_802B
GM-802B - ammonia (NH3).
Definition sfDevGMX02B.h:72