Eine benutzerdefinierte Sensorkonfiguration verwenden
Was dieses Beispiel zeigt
Das Beispiel customConfig baut sich einen eigenen sensorType, SENSOR_CUSTOM,
statt eines der Presets der Bibliothek zu verwenden, erstellt damit den Sensor an der
Standardadresse der Bibliothek, 0x49, und gibt die Gaskonzentration in PPM
alle 2,5 Sekunden aus.
So geben Sie der Bibliothek die Zelle dieses Boards vor. So, wie es geschrieben ist,
enthält SENSOR_CUSTOM eine Beispielempfindlichkeit von 100 nA pro ppm, daher sind die Messwerte
keine H2S-Werte. Setzen Sie für die Zelle SGX-4H2S-300 dieses Boards die Werte auf die
des Presets SENSOR_H2S der Bibliothek, mit dem Ausgangssignal, das das
Datenblatt der SGX-4H2S-300 angibt, nämlich 460 nA pro ppm (460 ± 140), statt der 1200 des Presets. Das
Preset ist für die Zelle SGX-4H2S-100 geschrieben, und mit der Zelle dieses Boards liest es
etwa 2,6-mal zu niedrig:
| Feld | Wert für dieses Board |
|---|---|
nanoAmperesPerPPM | 460.0F |
internalZeroCalibration | 0 |
adsGain | ADS_GAIN_4_096V |
TIA_GAIN_IN_KOHMS | TIA_GAIN_7_KOHM |
RLOAD | RLOAD_10_OHM |
REF_SOURCE | REF_EXTERNAL |
INTERNAL_ZERO | INTERNAL_ZERO_20_PERCENT |
BIAS_SIGN | BIAS_SIGN_POSITIVE |
BIAS | BIAS_0_PERCENT |
FET_SHORT | FET_SHORT_DISABLED |
OP_MODE | OP_MODE_3LEAD_AMP_CELL |
Der Beispielcode
// 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:
Sensor initialized successfully!
Danach gibt der Sketch alle 2,5 Sekunden Sensor reading: in einer Zeile aus
und in der nächsten die Konzentration in PPM mit fünf Nachkommastellen, gefolgt von PPM. Wenn
der Sensor nicht antwortet, gibt der Sketch
ERROR: Can't init the sensor! Check connections! aus und hält an.
Verwendete Funktionen
sensorType ist die Struktur, die die Einstellungen einer Zelle enthält, in dieser Reihenfolge:
| Feld | Typ | Bedeutung |
|---|---|---|
nanoAmperesPerPPM | double | Die Empfindlichkeit der Zelle in nA pro ppm. getPPM() teilt durch diesen Wert. |
internalZeroCalibration | double | Spannung, die vor der Umrechnung zum Messwert addiert wird, um ihn ohne das Zielgas auf null zu setzen. |
adsGain | uint8_t | Messbereich des ADC, ADS_GAIN_6_144V bis ADS_GAIN_0_256V. |
TIA_GAIN_IN_KOHMS | uint8_t | Verstärkung des Front-End-Verstärkers, TIA_GAIN_2_75_KOHM bis TIA_GAIN_350_KOHM, oder TIA_GAIN_EXTERNAL. |
RLOAD | uint8_t | Lastwiderstand, RLOAD_10_OHM bis RLOAD_100_OHM. |
REF_SOURCE | uint8_t | Referenzquelle, REF_INTERNAL oder REF_EXTERNAL. |
INTERNAL_ZERO | uint8_t | Interner Nullpunkt, INTERNAL_ZERO_20_PERCENT, INTERNAL_ZERO_50_PERCENT, INTERNAL_ZERO_67_PERCENT oder INTERNAL_ZERO_BYPASSED. |
BIAS_SIGN | uint8_t | Polarität der Bias-Spannung, BIAS_SIGN_NEGATIVE oder BIAS_SIGN_POSITIVE. |
BIAS | uint8_t | Bias-Spannung als Prozentsatz der Referenz, BIAS_0_PERCENT bis BIAS_24_PERCENT. |
FET_SHORT | uint8_t | FET_SHORT_DISABLED oder FET_SHORT_ENABLED. |
OP_MODE | uint8_t | Betriebsmodus; die Presets verwenden OP_MODE_3LEAD_AMP_CELL. |
ElectrochemicalGasSensor(sensorType _t, uint8_t _adcAddr = DEFAULT_ADC_ADDR, int _configPin = -1)returns noneErstellt das Sensorobjekt. Die Adresse bestimmt, wie begin() mit dem Board kommuniziert: Eine Adresse von 0x30 bis 0x37 läuft über den ATtiny404 des Boards; jede andere Adresse, etwa die Standardadresse 0x49, geht an einen ADS1115 unter dieser Adresse und direkt an den LMP91000.
ReturnsKonstruktor.
Parameter
| Name | Typ | Beschreibung |
|---|---|---|
_t | sensorType | Die zu verwendende Konfiguration. Dieses Beispiel übergibt SENSOR_CUSTOM. |
_adcAddr | uint8_t | Die Adresse, mit der begin() kommuniziert. Dieses Beispiel lässt sie weg, daher wird die Standardadresse 0x49 (DEFAULT_ADC_ADDR) verwendet. |
_configPin | int | Ein GPIO, den die Bibliothek auf High setzt und auf Low zieht, während sie den LMP91000 direkt konfiguriert. Wird bei Adressen von 0x30 bis 0x37 ignoriert. Dieses Beispiel lässt ihn weg (-1, keiner). |
bool begin()returns boolStartet I2C und wählt anhand der Adresse aus, wie mit dem Board kommuniziert wird. Bei einer Adresse von 0x30 bis 0x37 prüft es, ob der ATtiny404 des Boards antwortet, und sendet ihm die ADC-Verstärkung aus der Konfiguration mit der niedrigsten Datenrate; jeder Befehl wartet bis zu 500 ms auf eine Antwort. Bei jeder anderen Adresse startet es einen ADS1115 unter dieser Adresse mit derselben Verstärkung und Datenrate. In beiden Fällen schreibt es anschließend die Konfiguration in das LMP91000-Front-End. Rufen Sie es einmal vor dem Lesen auf.
Returnstrue, wenn jeder Schritt erfolgreich war, sonst false.
double getPPM()returns doubleLiest den ADC, subtrahiert den internen Nullpunkt des Front-Ends (2,5 V mal dessen Prozentwert), addiert die Nullpunktkalibrierung und teilt dann durch die Verstärkung des Verstärkers und durch die Empfindlichkeit der Konfiguration in nA pro ppm. Ein Ergebnis unter 0 wird als 0 zurückgegeben.
ReturnsGaskonzentration in PPM.
Zusammenfassung
Füllen Sie ein const sensorType mit den Werten Ihrer Zelle, übergeben Sie es an
ElectrochemicalGasSensor, rufen Sie begin() einmal auf und lesen Sie dann mit getPPM(). Für
dieses Board enthält die erste Tabelle die Werte.