ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
esphome::mics_5524::micsmath Namespace Reference

Data Structures

struct  VendorCurve
 Per-gas constants of the vendor model. More...
 

Enumerations

enum  ConversionModel : uint8_t { CONVERSION_MODEL_DFROBOT = 0 , CONVERSION_MODEL_DATASHEET = 1 }
 Generated through CONVERSION_MODELS in init.py. More...
 

Functions

float air_value_from_voltage (float voltage, float vcc)
 x = VCC - V_ao: 0 at VCC (a saturated sensor, never clean air).
 
float ratio_from_air_value (float x, float x_air)
 ratio = x / x_air (NaN when either value is unusable).
 
float ppm_from_vendor_curve (float ratio, const VendorCurve &curve)
 ratio -> ppm as DFRobot_MICS getGasData(): 0 above the threshold or below the vendor range, the top of the range at ratio 0 (a saturated sensor), NaN stays NaN.
 
float datasheet_dead_input_voltage (float vcc)
 Smallest V_ao the datasheet model reads: the output of RS = MAX_RS_OVER_RL * RL.
 
float rs_from_voltage (float voltage, float vcc, float rl)
 RS = (VCC * RL) / V - RL in kOhm: 0 at VCC (a saturated sensor).
 
float ratio_from_rs (float rs, float r0)
 ratio = RS / R0 (NaN when either value is unusable); 0 is the saturated end.
 
float ppm_from_power_law (float a, float b, float ratio)
 ppm = a * ratio^b; NaN for a ratio or coefficient that cannot produce a reading.
 
float clamp_ppm (float ppm, float min_ppm, float max_ppm)
 Clamp to the configured range: below min_ppm counts as not detected and reads 0, 0 itself never changes, and a reading past a finite max_ppm (infinity included) is max_ppm.
 
bool calibration_is_stable (float min_value, float max_value, float mean)
 True when the clean-air samples spread at most MAX_CALIBRATION_SPREAD of their mean.
 

Variables

constexpr float VENDOR_DEAD_INPUT_FRACTION = 0.05f
 Share of VCC at or below which the vendor model reads the output as disconnected: clean air sits a volt or two below VCC, so a reading near 0 V is a wiring fault, not gas-free air.
 
constexpr float MAX_RS_OVER_RL = 200.0f
 Largest RS the datasheet model reads, as a multiple of RL.
 
constexpr float MAX_CALIBRATION_SPREAD = 0.25f
 Largest relative spread (max - min) / mean a clean-air calibration accepts.
 

Enumeration Type Documentation

◆ ConversionModel

Generated through CONVERSION_MODELS in init.py.

Enumerator
CONVERSION_MODEL_DFROBOT 
CONVERSION_MODEL_DATASHEET 

Definition at line 14 of file mics_math.h.

Function Documentation

◆ air_value_from_voltage()

float esphome::mics_5524::micsmath::air_value_from_voltage ( float voltage,
float vcc )
inline

x = VCC - V_ao: 0 at VCC (a saturated sensor, never clean air).

NaN at or below VENDOR_DEAD_INPUT_FRACTION of VCC (a disconnected pin) and above VCC, which only a wrong vcc or voltage_multiplier produces.

Definition at line 36 of file mics_math.h.

◆ calibration_is_stable()

bool esphome::mics_5524::micsmath::calibration_is_stable ( float min_value,
float max_value,
float mean )
inline

True when the clean-air samples spread at most MAX_CALIBRATION_SPREAD of their mean.

Definition at line 122 of file mics_math.h.

◆ clamp_ppm()

float esphome::mics_5524::micsmath::clamp_ppm ( float ppm,
float min_ppm,
float max_ppm )
inline

Clamp to the configured range: below min_ppm counts as not detected and reads 0, 0 itself never changes, and a reading past a finite max_ppm (infinity included) is max_ppm.

NaN stays NaN.

Definition at line 104 of file mics_math.h.

◆ datasheet_dead_input_voltage()

float esphome::mics_5524::micsmath::datasheet_dead_input_voltage ( float vcc)
inline

Smallest V_ao the datasheet model reads: the output of RS = MAX_RS_OVER_RL * RL.

Definition at line 73 of file mics_math.h.

◆ ppm_from_power_law()

float esphome::mics_5524::micsmath::ppm_from_power_law ( float a,
float b,
float ratio )
inline

ppm = a * ratio^b; NaN for a ratio or coefficient that cannot produce a reading.

Ratio 0, the saturated end, gives infinity on a falling curve, which clamp_ppm turns into max_ppm.

Definition at line 93 of file mics_math.h.

◆ ppm_from_vendor_curve()

float esphome::mics_5524::micsmath::ppm_from_vendor_curve ( float ratio,
const VendorCurve & curve )
inline

ratio -> ppm as DFRobot_MICS getGasData(): 0 above the threshold or below the vendor range, the top of the range at ratio 0 (a saturated sensor), NaN stays NaN.

Definition at line 51 of file mics_math.h.

◆ ratio_from_air_value()

float esphome::mics_5524::micsmath::ratio_from_air_value ( float x,
float x_air )
inline

ratio = x / x_air (NaN when either value is unusable).

Definition at line 43 of file mics_math.h.

◆ ratio_from_rs()

float esphome::mics_5524::micsmath::ratio_from_rs ( float rs,
float r0 )
inline

ratio = RS / R0 (NaN when either value is unusable); 0 is the saturated end.

Definition at line 85 of file mics_math.h.

◆ rs_from_voltage()

float esphome::mics_5524::micsmath::rs_from_voltage ( float voltage,
float vcc,
float rl )
inline

RS = (VCC * RL) / V - RL in kOhm: 0 at VCC (a saturated sensor).

NaN above VCC, which only a wrong vcc or voltage_multiplier produces, and at or below datasheet_dead_input_voltage().

Definition at line 77 of file mics_math.h.

Variable Documentation

◆ MAX_CALIBRATION_SPREAD

float esphome::mics_5524::micsmath::MAX_CALIBRATION_SPREAD = 0.25f
inlineconstexpr

Largest relative spread (max - min) / mean a clean-air calibration accepts.

Definition at line 119 of file mics_math.h.

◆ MAX_RS_OVER_RL

float esphome::mics_5524::micsmath::MAX_RS_OVER_RL = 200.0f
inlineconstexpr

Largest RS the datasheet model reads, as a multiple of RL.

The datasheet puts the clean-air resistance of a module below about 1.5 MOhm, 150 x the usual 10k RL, so an output voltage below that of this resistance is a disconnected input.

Definition at line 70 of file mics_math.h.

◆ VENDOR_DEAD_INPUT_FRACTION

float esphome::mics_5524::micsmath::VENDOR_DEAD_INPUT_FRACTION = 0.05f
inlineconstexpr

Share of VCC at or below which the vendor model reads the output as disconnected: clean air sits a volt or two below VCC, so a reading near 0 V is a wiring fault, not gas-free air.

Definition at line 31 of file mics_math.h.