Zum Hauptinhalt springen

Eigene Sensorkonfiguration verwenden

Was dieses Beispiel zeigt​

Das Beispiel customConfig der Bibliothek erstellt einen eigenen sensorType, statt ein Preset zu verwenden, legt den Sensor damit an und gibt die Gaskonzentration in ppm alle 2,5 Sekunden aus.

Der lange Kommentar über SENSOR_CUSTOM listet auf, was jeder Wert festlegt und aus welchen Konstanten Sie wählen können; passen Sie sie an das Datenblatt Ihres Sensors an. Zum Vergleich: Das Preset SENSOR_NO2 der Bibliothek für die SGX-4NO2-Zelle dieses Boards verwendet diese Werte:

FeldSENSOR_CUSTOM im BeispielPreset SENSOR_NO2
nanoAmperesPerPPM100.0F-600.0F
internalZeroCalibration00
adsGainADS_GAIN_4_096VADS_GAIN_2_048V
TIA_GAIN_IN_KOHMSTIA_GAIN_120_KOHMTIA_GAIN_35_KOHM
RLOADRLOAD_10_OHMRLOAD_10_OHM
REF_SOURCEREF_EXTERNALREF_EXTERNAL
INTERNAL_ZEROINTERNAL_ZERO_20_PERCENTINTERNAL_ZERO_67_PERCENT
BIAS_SIGNBIAS_SIGN_NEGATIVEBIAS_SIGN_NEGATIVE
BIASBIAS_0_PERCENTBIAS_0_PERCENT
FET_SHORTFET_SHORT_DISABLEDFET_SHORT_DISABLED
OP_MODEOP_MODE_3LEAD_AMP_CELLOP_MODE_3LEAD_AMP_CELL

Der Beispielcode​

Select Board
customConfig.ino
/**
**************************************************
*
* @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);
}

Erwartetes Ergebnis:

Serial MonitorAutoscrollShow timestampNewline115200 baud
Message (Enter to send message to the board)
Sensor initialized successfully!

Danach gibt der Sketch alle 2,5 Sekunden Sensor reading: in einer Zeile und in der nächsten die Konzentration in ppm mit fünf Nachkommastellen, gefolgt von PPM, aus: Dieses Beispiel gibt die Beschriftung mit println() aus. Schlägt begin() fehl, gibt es ERROR: Can't init the sensor! Check connections! aus und hält an.

Verwendete Funktionen​

ElectrochemicalGasSensor(sensorType _t, uint8_t _adcAddr = DEFAULT_ADC_ADDR, int _configPin = -1)returns ElectrochemicalGasSensor

Erstellt das Sensorobjekt. Es wird nichts an das Board gesendet, bevor Sie begin() aufrufen. Die Adresse bestimmt, wie begin() mit dem Board kommuniziert: Von 0x30 bis 0x37 sendet es seine Befehle an den ATtiny404, und von 0x48 bis 0x4B (DEFAULT_ADC_ADDR ist 0x49) spricht es den ADS1115 unter dieser Adresse und den LMP91000 direkt an.

ReturnsDas Sensorobjekt.

Parameter

TypNameBeschreibung
sensorType_tDie Einstellungen der Zelle: ein Preset oder Ihr eigener sensorType. Das Beispiel übergibt SENSOR_CUSTOM.
uint8_t_adcAddrDie Adresse, mit der begin() kommuniziert, standardmäßig 0x49; das Beispiel belässt den Standardwert.
int_configPinGPIO für den Enable-Pin des LMP91000 (LMPEN), nur bei 0x48 bis 0x4B verwendet. Standardmäßig -1 (keiner); das Beispiel übergibt keinen.

Ein sensorType enthält in dieser Reihenfolge: nanoAmperesPerPPM und internalZeroCalibration (beide double), dann adsGain, TIA_GAIN_IN_KOHMS, RLOAD, REF_SOURCE, INTERNAL_ZERO, BIAS_SIGN, BIAS, FET_SHORT und OP_MODE (jeweils uint8_t, gesetzt mit den Konstanten, die der Kommentar des Beispiels auflistet).

sensor.begin()returns bool

Startet Wire und schreibt die Konfiguration auf das Board. Von 0x30 bis 0x37 prüft es, ob der ATtiny404 antwortet, und sendet ihm dann die ADC-Verstärkung und Datenrate sowie die LMP91000-Konfiguration, wobei jeder Schritt bis zu 500 ms auf die Antwort wartet. Von 0x48 bis 0x4B startet es den ADS1115 unter dieser Adresse, stellt die Verstärkung der Konfiguration und die langsamste Datenrate ein und schreibt die LMP91000-Konfiguration; dabei zieht es _configPin auf LOW, falls einer angegeben ist. Rufen Sie es einmal in setup() auf.

Returnstrue, wenn alle Schritte erfolgreich waren, andernfalls false.

sensor.getPPM()returns double

Führt eine neue ADC-Messung durch und rechnet sie mit Ihrer Konfiguration in eine Gaskonzentration um: die Spannung minus den internen Nullpunkt, plus internalZeroCalibration, geteilt durch die TIA-Verstärkung und durch nanoAmperesPerPPM. Ein negatives Ergebnis wird als 0 zurückgegeben.

ReturnsDie Gaskonzentration in ppm.

Zusammenfassung​

Der Sketch definiert SENSOR_CUSTOM und legt damit den Sensor an, bevor setup() ausgeführt wird. begin() schreibt den ADC-Bereich und die Front-End- Einstellungen der Konfiguration; schlägt es fehl, gibt der Sketch den Fehler aus und bleibt in einer Endlosschleife. In loop() liest jeder Aufruf von getPPM() die Zelle erneut aus, und der Sketch gibt den Wert aus und wartet 2,5 Sekunden.