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
SfeGM702BArd Class Reference

Arduino I2C implementation for the SparkFun Qwiic GM-702B gas sensor breakout (carbon monoxide (CO)). More...

#include <SparkFun_GMX02B.h>

Inheritance diagram for SfeGM702BArd:
SfeGMX02BArd sfDevGMX02B

Public Member Functions

 SfeGM702BArd ()
 
- Public Member Functions inherited from SfeGMX02BArd
 SfeGMX02BArd (sfe_gmx02b_sensor_t sensor)
 Construct a driver for a specific board variant.
 
bool begin (TwoWire &wirePort=Wire)
 Initialize the board at the declared part's factory-default I2C address.
 
bool begin (uint8_t address, TwoWire &wirePort=Wire)
 Initialize the board at an explicit I2C address.
 
bool begin (sfe_gmx02b_sensor_t sensor, TwoWire &wirePort=Wire)
 Declare the sensor variant and initialize it, in one call.
 
uint8_t getAddress (void)
 Get the 7-bit I2C address this object is communicating on.
 
- Public Member Functions inherited from sfDevGMX02B
 sfDevGMX02B (sfe_gmx02b_sensor_t sensor)
 Construct a driver for a specific family member.
 
sfTkError_t begin (sfTkIBus *theBus=nullptr)
 Initialize the device driver with the given bus.
 
bool isConnected (void)
 Check whether the board's ADC is connected and responding.
 
bool probeADC (bool assumeUnconfigured=false)
 Check that the responding device looks like an ADC101C021.
 
bool setSensorType (sfe_gmx02b_sensor_t sensor)
 Declare which family member is installed.
 
sfe_gmx02b_sensor_t getSensorType (void)
 Get the declared sensor variant.
 
const sfe_gmx02b_part_t * getPartInfo (void)
 Get the descriptor for the current sensor variant.
 
const char * getSensorName (void)
 Get a printable name for the current sensor variant.
 
const char * getTargetGas (void)
 Get a printable target gas description for the current sensor variant.
 
uint8_t getDefaultAddress (void)
 Get the factory-default I2C address for the current sensor variant.
 
bool rsRisesWithGas (void)
 Report whether Rs rises or falls with target gas concentration.
 
float getRangeMin_ppm (void)
 Get the low end of the part's detection range.
 
float getRangeMax_ppm (void)
 Get the high end of the part's detection range.
 
float getRatedSensitivity (void)
 Get the datasheet response ratio bound for this part.
 
float getRatedConcentration_ppm (void)
 Get the concentration at which getRatedSensitivity() is specified.
 
sfTkError_t readMeasurement (void)
 Read one conversion from the ADC and cache the result.
 
uint16_t getRaw (void)
 Get the raw 10-bit ADC value from the most recent readMeasurement().
 
float getVoltage_V (void)
 Get the sensor output voltage from the most recent readMeasurement().
 
sfTkError_t getSensorResistance_Ohm (float &ohms)
 Get the sensing element resistance (Rs) from the most recent readMeasurement().
 
sfTkError_t getRatio (float &ratio)
 Get the raw Rs/R0 ratio from the most recent readMeasurement().
 
sfTkError_t getGasResponse (float &response)
 Get the direction-normalized gas response from the most recent readMeasurement().
 
bool getAlertTriggered (void)
 Get the ADC alert flag from the most recent readMeasurement().
 
void setSupplyVoltage_V (float volts)
 Set the sensing circuit supply voltage used by getVoltage_V(), voltageToCounts() and countsToVoltage_V().
 
float getSupplyVoltage_V (void)
 Get the configured sensing circuit supply voltage.
 
void setLoadResistance_Ohm (float ohms)
 Override the load resistance (RL) used by getSensorResistance_Ohm().
 
float getLoadResistance_Ohm (void)
 Get the configured load resistance.
 
uint16_t voltageToCounts (float volts)
 Convert a voltage into the equivalent 10-bit ADC counts.
 
float countsToVoltage_V (uint16_t counts)
 Convert 10-bit ADC counts into the equivalent sensor output voltage.
 
uint16_t resistanceToCounts (float ohms)
 Convert a sensor resistance into the equivalent 10-bit ADC counts.
 
sfTkError_t responseToCounts (float response, uint16_t &counts)
 Convert a gas response ratio into the equivalent 10-bit ADC counts.
 
sfTkError_t measureCleanAirResistance (float &r0, uint8_t samples=kCleanAirSamples, uint16_t sampleDelayMs=kCleanAirSampleDelayMs)
 Measure and store the clean-air sensor resistance (R0).
 
void setCleanAirResistance_Ohm (float ohms)
 Set the clean-air resistance (R0) directly.
 
float getCleanAirResistance_Ohm (void)
 Get the stored clean-air resistance (R0).
 
void setResponseCurve (float a, float b)
 Set a power-law curve that converts gas response into a concentration.
 
sfTkError_t getConcentration_ppm (float &ppm)
 Get the estimated target gas concentration.
 
bool isInRange (float ppm)
 Check whether a concentration falls inside the part's rated detection range.
 
sfTkError_t setGasAlertResponse (float response)
 Set a hardware gas threshold in gas response units.
 
sfTkError_t getGasAlert (bool &gasDetected)
 Read the hardware alert status as a single "gas detected" flag.
 
sfTkError_t setAlertLowLimit (uint16_t counts)
 Set the alert low limit (under-range threshold).
 
sfTkError_t getAlertLowLimit (uint16_t &counts)
 Get the alert low limit.
 
sfTkError_t setAlertHighLimit (uint16_t counts)
 Set the alert high limit (over-range threshold).
 
sfTkError_t getAlertHighLimit (uint16_t &counts)
 Get the alert high limit.
 
sfTkError_t setAlertHysteresis (uint16_t counts)
 Set the alert hysteresis.
 
sfTkError_t getAlertHysteresis (uint16_t &counts)
 Get the alert hysteresis.
 
sfTkError_t setAlertHysteresis_mV (float millivolts)
 Set the alert hysteresis as a sensor-output voltage band.
 
sfTkError_t getAlertHysteresis_mV (float &millivolts)
 Get the alert hysteresis as a sensor-output voltage band.
 
sfTkError_t enableAlertFlag (bool enable)
 Enable or disable the alert flag in the conversion result register.
 
sfTkError_t enableAlertPin (bool enable)
 Enable or disable the ADC's ALERT output pin.
 
sfTkError_t setAlertPinActiveHigh (bool activeHigh)
 Set the active polarity of the ALERT output pin.
 
sfTkError_t enableAlertHold (bool enable)
 Enable or disable alert hold.
 
sfTkError_t getAlertStatus (bool &underRange, bool &overRange)
 Read the raw alert status flags.
 
sfTkError_t clearAlertStatus (void)
 Clear both alert status flags.
 
sfTkError_t setCycleTime (sfe_gmx02b_cycle_time_t cycleTime)
 Set the automatic conversion cycle time (enables / disables automatic mode).
 
sfTkError_t getCycleTime (sfe_gmx02b_cycle_time_t &cycleTime)
 Get the automatic conversion cycle time.
 
sfTkError_t getPeakGasCounts (uint16_t &counts)
 Get the peak GAS conversion recorded in automatic conversion mode.
 
sfTkError_t getPeakGasVoltage_V (float &volts)
 Get the peak gas conversion as a sensor output voltage.
 
sfTkError_t clearPeakGasCounts (void)
 Reset the peak gas tracking register for this part.
 
sfTkError_t getLowestConversion (uint16_t &counts)
 Get the lowest conversion result recorded in automatic conversion mode.
 
sfTkError_t getHighestConversion (uint16_t &counts)
 Get the highest conversion result recorded in automatic conversion mode.
 
sfTkError_t clearLowestConversion (void)
 Reset the lowest conversion register (to full scale).
 
sfTkError_t clearHighestConversion (void)
 Reset the highest conversion register (to zero).
 

Additional Inherited Members

- Protected Member Functions inherited from sfDevGMX02B
sfTkError_t readRegister8 (uint8_t reg, uint8_t &value)
 Read an 8-bit register from the ADC.
 
sfTkError_t writeRegister8 (uint8_t reg, uint8_t value)
 Write an 8-bit register on the ADC.
 
sfTkError_t readRegister16 (uint8_t reg, uint16_t &value)
 Read a 16-bit register from the ADC (most significant byte first).
 
sfTkError_t writeRegister16 (uint8_t reg, uint16_t value)
 Write a 16-bit register on the ADC (most significant byte first).
 
sfTkError_t readValueRegister (uint8_t reg, uint16_t &counts)
 Read a 10-bit value register (value stored in bits 11:2).
 
sfTkError_t writeValueRegister (uint8_t reg, uint16_t counts)
 Write a 10-bit value register (value stored in bits 11:2).
 
sfTkError_t updateConfiguration (uint8_t mask, uint8_t value)
 Read-modify-write bits of the 8-bit configuration register.
 
- Protected Attributes inherited from sfDevGMX02B
sfTkIBus * _theBus
 Pointer to the communication bus device.
 
sfe_gmx02b_sensor_t _sensorType = GM_602B
 Declared sensor variant.
 
const sfe_gmx02b_part_t * _part = nullptr
 Descriptor for _sensorType. Never null after construction.
 
uint16_t _counts = 0
 Raw 10-bit ADC value.
 
bool _alertFlag = false
 Alert flag (bit D15) from the conversion result.
 
float _supplyVoltage = kSupplyVoltageDefault
 ADC reference / sensing loop supply (V).
 
float _loadResistance = 0.0f
 Load resistor RL (Ohm). Set from the part descriptor.
 
float _cleanAirResistance = 0.0f
 Stored clean-air sensor resistance R0 (Ohm); 0 = not set.
 
float _curveA = 0.0f
 Multiplier; 0 = no curve set.
 
float _curveB = 0.0f
 Exponent.
 
- Static Protected Attributes inherited from sfDevGMX02B
static const uint8_t kRegConversionResult = 0x00
 Conversion result (16-bit, read only).
 
static const uint8_t kRegAlertStatus = 0x01
 Alert status flags (8-bit).
 
static const uint8_t kRegConfiguration = 0x02
 Configuration (8-bit).
 
static const uint8_t kRegLowLimit = 0x03
 Alert low limit (16-bit).
 
static const uint8_t kRegHighLimit = 0x04
 Alert high limit (16-bit).
 
static const uint8_t kRegHysteresis = 0x05
 Alert hysteresis (16-bit).
 
static const uint8_t kRegLowestConversion = 0x06
 Lowest conversion seen (16-bit).
 
static const uint8_t kRegHighestConversion = 0x07
 Highest conversion seen (16-bit).
 
static const uint8_t kValueShift = 2
 Bit position of the 10-bit value.
 
static const uint16_t kValueMask = 0x03FF
 Mask for the 10-bit value (after shifting).
 
static const uint16_t kAlertFlagMask = 0x8000
 Alert flag (D15) in the conversion result.
 
static const uint16_t kValueReservedMask = 0xF003
 D15:D12 and D1:D0.
 
static const uint8_t kAlertStatusUnderRange = 0x01
 Under-range alert flag.
 
static const uint8_t kAlertStatusOverRange = 0x02
 Over-range alert flag.
 
static const uint8_t kConfigCycleTimeMask = 0xE0
 Cycle time field (D7:5).
 
static const uint8_t kConfigCycleTimeShift = 5
 Cycle time field bit position.
 
static const uint8_t kConfigAlertHold = 0x10
 Alert hold enable (D4).
 
static const uint8_t kConfigAlertFlagEnable = 0x08
 Conversion result alert flag enable (D3).
 
static const uint8_t kConfigAlertPinEnable = 0x04
 ALERT pin enable (D2).
 
static const uint8_t kConfigReserved = 0x02
 Reserved, reads zero (D1).
 
static const uint8_t kConfigPolarity = 0x01
 ALERT pin polarity: 1 = active high (D0).
 
static const uint16_t kAdcFullScale = 1024
 10-bit ADC full-scale count (1 LSB = VA / 1024).
 
static const uint16_t kAdcMaxCounts = 1023
 Maximum 10-bit ADC value.
 
static constexpr float kAdcFullScaleInv = 1.0f / 1024.0f
 Precomputed 1 / full scale.
 
static constexpr float kSupplyVoltageDefault = 3.3f
 Qwiic 3.3 V rail powers ADC and sensing loop.
 
static const uint8_t kCleanAirSamples = 16
 Default readings averaged for R0.
 
static const uint16_t kCleanAirSampleDelayMs = 50
 Default delay between R0 readings (ms).
 

Detailed Description

Arduino I2C implementation for the SparkFun Qwiic GM-702B gas sensor breakout (carbon monoxide (CO)).

Convenience class, equivalent to SfeGMX02BArd constructed with GM_702B. Factory I2C address 0x59.

Note
The datasheet specifies a cycled heater for this element, not a steady voltage.
See also
SfeGMX02BArd
sfDevGMX02B

Constructor & Destructor Documentation

◆ SfeGM702BArd()

SfeGM702BArd::SfeGM702BArd ( )
inline

The documentation for this class was generated from the following file: