Configure your own cell
What this example shows
The customConfig example builds its own sensorType instead of using a
preset, so you can set every value from your cell's datasheet, sends it to the
LMP91000 and prints the gas concentration in parts per million (PPM) every 2.5
seconds.
Wire your controller to the top header for this example, not to a Qwiic
connector: the controller's SDA to SDA2, its SCL to SCL2, its 3.3 V supply
to 3V3 and its ground to GND. At this address the library talks to the
ADS1115 and the LMP91000 directly on SDA2 and SCL2; the board's ATtiny404 bridge at 0x30
is not used. Over
Qwiic, only the bridge example in the
Quick Start
works.
The example code
Edit the values in SENSOR_CUSTOM to match your cell; the long comment above
it lists the choices for each field. The sketch creates the sensor with
SENSOR_CUSTOM alone, so the library's default address is used.
The sketch's comment says to connect LMPEN to a GPIO. On this board,
LMPEN goes to the header and to the board's ATtiny404.
/**
**************************************************
*
* @file customConfig.ino
* @brief Create a custom config for the LMP91000 and upload it to the device.
* This enables you to use this breakout with any electrochemical sensor.
*
* To successfully run the sketch:
* - Edit the custom configuration
* - Connect LMPEN to any GPIO pin
* - Run the sketch and open serial monitor at 115200 baud!
*
*
* @authors Robert @ soldered.com
***************************************************/
// Include the required library
#include "Electrochemical-Gas-Sensor-SOLDERED.h"
/**
* Here are parameters to configure for the custom sensor:
*
* nanoAmperesPerPPM: From the datasheet of the particular electrochemical
* sensor, used in the calculation of PPM/PPB
*
* internalZeroCalibration: A fixed value which is summed to the voltage
* measured by the ADS. The value here should make the reading be
* just barely 0 PPM when the sensor is in a place with none of the target gas
*
* adsGain: The gain of the ADS
* The voltage here represents the max range which it can measure
* ADS_GAIN_6_144V 6.144 V
* ADS_GAIN_4_096V 4.096 V
* ADS_GAIN_2_048V 2.048 V
* ADS_GAIN_1_024V 1.024 V
* ADS_GAIN_0_512V 0.512 V
* ADS_GAIN_0_256V 0.256 V
*
* TIA_GAIN_IN_KOHMS: The gain of the amplifier
* This increases the sensitivity of the measurement
* TIA_GAIN_EXTERNAL External resistance
* TIA_GAIN_2_75_KOHM 2.75 kOhm
* TIA_GAIN_3_5_KOHM 3.5 kOhm
* TIA_GAIN_7_KOHM 7 kOhm
* TIA_GAIN_14_KOHM 14 kOhm
* TIA_GAIN_35_KOHM 35 kOhm
* TIA_GAIN_120_KOHM 120 kOhm
* TIA_GAIN_350_KOHM 350 kOhm
*
* RLOAD: The load resistor in the LMP91000
* Specified in the electrochemical sensor's datasheet
* RLOAD_10_OHM 10 Ohm
* RLOAD_33_OHM 33 Ohm
* RLOAD_50_OHM 50 Ohm
* RLOAD_100_OHM 100 Ohm
*
* REF_SOURCE: Source of the control voltage reference
* For our breakout, use external, there's a 2.5V external
* reference voltage
* REF_INTERNAL Internal
* REF_EXTERNAL External
*
* INTERNAL_ZERO: Internal zero selection
* If the electrochemical sensor has a positive polarity, you
* would usually want to use 20% for the most headroom in the signal
* INTERNAL_ZERO_20_PERCENT 20%
* INTERNAL_ZERO_50_PERCENT 50%
* INTERNAL_ZERO_67_PERCENT 67%
* INTERNAL_ZERO_BYPASSED Internal zero bypassed
*
* BIAS_SIGN: The polarity of the bias voltage
* BIAS_SIGN_NEGATIVE Negative
* BIAS_SIGN_POSITIVE Positive
*
* BIAS: Added bias, percentage of the reference voltage
* Most sensors don't require this, check each sensor's datasheet
* BIAS_0_PERCENT 0%
* BIAS_1_PERCENT 1%
* BIAS_2_PERCENT 2%
* BIAS_4_PERCENT 4%
* BIAS_6_PERCENT 6%
* ...
* BIAS_22_PERCENT 22%
* BIAS_24_PERCENT 24%
*
* FET_SHORT: Short the FET
* Used to perserve the electrochemical sensor
* Has to be disabled for the sensor to be operable
* FET_SHORT_DISABLED Disabled
* FET_SHORT_ENABLED Enabled
*
* OP_MODE: Mode of operation
* OP_MODE_DEEP_SLEEP Deep Sleep (default)
* OP_MODE_2LEAD_GROUND_CELL 2-lead ground referred galvanic cell
* OP_MODE_STANDBY Standby
* OP_MODE_3LEAD_AMP_CELL 3-lead amperometric cell
* OP_MODE_TEMPERATURE_TIA_OFF Temperature measurement (TIA Off)
* OP_MODE_TEMPERATURE_TIA_ON Temperature measurement (TIA On)
*
* For more details, check thge LMP91000 datasheet, chapter 7.6
*/
// Here is an example of a custom configuration:
const sensorType SENSOR_CUSTOM = {
100.0F, // nanoAmperesPerPPM
0, // internalZeroCalibration
ADS_GAIN_4_096V, // adsGain
TIA_GAIN_120_KOHM, // TIA_GAIN_IN_KOHMS
RLOAD_10_OHM, // RLOAD
REF_EXTERNAL, // REF_SOURCE
INTERNAL_ZERO_20_PERCENT, // INTERNAL_ZERO
BIAS_SIGN_NEGATIVE, // BIAS_SIGN
BIAS_0_PERCENT, // BIAS
FET_SHORT_DISABLED, // FET_SHORT
OP_MODE_3LEAD_AMP_CELL, // OP_MODE
};
// Create the sensor object with the custom type
ElectrochemicalGasSensor sensor(SENSOR_CUSTOM);
void setup()
{
Serial.begin(115200); // For debugging
// Init the breakout
if (!sensor.begin())
{
// Can't init? Notify the user and go to infinite loop
Serial.println("ERROR: Can't init the sensor! Check connections!");
while (true)
delay(100);
}
Serial.println("Sensor initialized successfully!");
}
void loop()
{
// Make the reading
double reading = sensor.getPPM();
// Print the reading with 5 digits of precision
Serial.println("Sensor reading: ");
Serial.print(reading, 5);
Serial.println(" PPM");
// Wait a bit before reading again
delay(2500);
}
🔗Open the complete example
examples/customConfig at commit c4df54b
Open the Serial Monitor at 115200 baud. The sketch prints:
Sensor initialized successfully!
Then, every 2.5 seconds, a Sensor reading: line followed by a line with the
concentration (five decimals) and PPM. This sketch prints the label with
Serial.println(), so the value lands on the line below it. If begin()
fails, the sketch prints ERROR: Can't init the sensor! Check connections!
and stops.
The sensorType fields
sensorType is a plain structure, filled in the order below. The presets such
as SENSOR_CO are sensorType values too.
| Field | Type | What it sets |
|---|---|---|
nanoAmperesPerPPM | double | The cell's sensitivity in nA per PPM, from its datasheet. The library's NO2 and O3 presets use negative values. |
internalZeroCalibration | double | A voltage added to each reading, the value setCustomZeroCalibration() sets. |
adsGain | uint8_t | The ADS1115 full-scale range: ADS_GAIN_6_144V, ADS_GAIN_4_096V, ADS_GAIN_2_048V, ADS_GAIN_1_024V, ADS_GAIN_0_512V or ADS_GAIN_0_256V. |
TIA_GAIN_IN_KOHMS | uint8_t | The LMP91000's amplifier gain: TIA_GAIN_EXTERNAL, TIA_GAIN_2_75_KOHM, TIA_GAIN_3_5_KOHM, TIA_GAIN_7_KOHM, TIA_GAIN_14_KOHM, TIA_GAIN_35_KOHM, TIA_GAIN_120_KOHM or TIA_GAIN_350_KOHM. |
RLOAD | uint8_t | The load resistor: RLOAD_10_OHM, RLOAD_33_OHM, RLOAD_50_OHM or RLOAD_100_OHM. |
REF_SOURCE | uint8_t | The reference: REF_INTERNAL or REF_EXTERNAL. The board has a 2.5 V external reference. |
INTERNAL_ZERO | uint8_t | The internal zero as a share of the reference: INTERNAL_ZERO_20_PERCENT, INTERNAL_ZERO_50_PERCENT, INTERNAL_ZERO_67_PERCENT or INTERNAL_ZERO_BYPASSED. |
BIAS_SIGN | uint8_t | The bias polarity: BIAS_SIGN_NEGATIVE or BIAS_SIGN_POSITIVE. |
BIAS | uint8_t | The bias as a share of the reference, from BIAS_0_PERCENT to BIAS_24_PERCENT. |
FET_SHORT | uint8_t | FET_SHORT_DISABLED or FET_SHORT_ENABLED. The sketch's comment says it has to be disabled for the cell to work. |
OP_MODE | uint8_t | The LMP91000's mode: OP_MODE_3LEAD_AMP_CELL for a 3-lead cell, or OP_MODE_DEEP_SLEEP, OP_MODE_2LEAD_GROUND_CELL, OP_MODE_STANDBY, OP_MODE_TEMPERATURE_TIA_OFF, OP_MODE_TEMPERATURE_TIA_ON. |
Functions used
ElectrochemicalGasSensor(sensorType _t, uint8_t _adcAddr = DEFAULT_ADC_ADDR, int _configPin = -1)returns noneCreates the sensor object for one board. The address decides how begin() talks to it: for an address from 0x30 to 0x37 it uses the protocol of the ATtiny404 bridge; for any other address it talks to an ADS1115 at that address and to the LMP91000 itself. The default is DEFAULT_ADC_ADDR (0x49).
ReturnsConstructor.
Parameters
| Name | Type | Description |
|---|---|---|
_t | sensorType | Here, the sketch's own SENSOR_CUSTOM. |
_adcAddr | uint8_t | The address begin() uses. 0x30 to 0x37 selects the bridge protocol; this board answers at 0x30 out of the box, or at the address its switch sets. Any other value is taken as an ADS1115 address. 0x49 by default. |
_configPin | int | A GPIO for the LMP91000 enable line. The library holds it high and pulls it low only while it writes the LMP91000's registers itself; for an address from 0x30 to 0x37 it is not used. -1 (none) by default. |
bool begin()returns boolStarts I2C with Wire.begin() and picks the protocol from the address. For 0x30 to 0x37 it checks that the bridge answers, sends the ADC gain from the configuration and has the bridge write the LMP91000's registers, each step giving up after 500 ms. For any other address it checks that an ADS1115 answers at that address, sets its gain, and writes the LMP91000's registers when the LMP91000 reports ready, pulling _configPin low around the writes when one is given. Call it once before reading.
Returnstrue when every step succeeded, false otherwise.
double getPPM()returns doubleTakes one reading of the ADS1115's channel 0 (through the bridge for 0x30 to 0x37) and converts it to a concentration with the configuration: it removes the internal zero offset, adds the zero calibration, divides by the amplifier gain and by the sensitivity in nA per PPM. A negative result is returned as 0.
ReturnsThe gas concentration in PPM.
Putting it together
Fill a sensorType from your cell's datasheet and pass it to
ElectrochemicalGasSensor where you would pass a preset. begin() sends its
settings to the LMP91000, and getPPM() uses its sensitivity and zero values
for every reading.