Koristite vlastite postavke front-enda
Što prikazuje ovaj primjer
Primjer customConfig izrađuje vlastitu predefiniranu konfiguraciju, sensorType pod nazivom
SENSOR_CUSTOM, umjesto da koristi neku od konfiguracija iz biblioteke. Konfiguracija sadrži osjetljivost
ćelije, raspon ADC-a i sve postavke front-enda čipa LMP91000, pa je to način da isprobate druge
vrijednosti za ćeliju. Skica zatim ispisuje očitanje u ppm svakih 2,5 sekunde.
Primjer izrađuje senzor samo s predefiniranom konfiguracijom, pa biblioteka koristi svoju zadanu adresu,
DEFAULT_ADC_ADDR (0x49). Na toj adresi biblioteka komunicira
s ADS1115 i LMP91000 izravno, a ne preko mosta ATtiny404 na pločici, a zaglavlje skice traži da LMPEN
bude spojen na GPIO. Pogledajte pregled biblioteke
da vidite kako adresa to određuje.
Za ćeliju SGX-4NO-250 na ovoj pločici konfiguracija SENSOR_NO iz same biblioteke koristi
vrijednosti iz tablice u nastavku. SENSOR_CUSTOM iz primjera razlikuje se od nje
u osjetljivosti (100 nA po ppm) i u prednapetosti (negativna, 0 %).
| Polje | Vrijednost SENSOR_NO |
|---|---|
nanoAmperesPerPPM | 400.0F |
internalZeroCalibration | 0 |
adsGain | ADS_GAIN_4_096V |
TIA_GAIN_IN_KOHMS | TIA_GAIN_120_KOHM |
RLOAD | RLOAD_10_OHM |
REF_SOURCE | REF_EXTERNAL |
INTERNAL_ZERO | INTERNAL_ZERO_20_PERCENT |
BIAS_SIGN | BIAS_SIGN_POSITIVE |
BIAS | BIAS_12_PERCENT |
FET_SHORT | FET_SHORT_DISABLED |
OP_MODE | OP_MODE_3LEAD_AMP_CELL |
Kod primjera
Popis je datoteka iz biblioteke na učvršćenom commitu. Izostavljeni su samo retci komentara: onaj koji imenuje stari konektor i retci zaglavlja koji vode na trgovinske stranice drugih proizvoda.
/**
**************************************************
*
* @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);
}
Očekivani rezultat, uz SENSOR_CUSTOM postavljen na vrijednosti SENSOR_NO (očitanja
na čistom zraku; vaša će se razlikovati):
Sensor initialized successfully!
Sensor reading:
0.00610 PPM
Sensor reading:
0.00601 PPM
Sensor reading:
0.00600 PPM
Sensor reading:
0.00614 PPM
Svakih 2,5 sekunde ispisuje se redak Sensor reading: i, u idućem
retku, koncentracija u ppm s pet decimala i s PPM na kraju: skica ispisuje oznaku pomoću Serial.println(), pa vrijednost počinje u novom retku. Ako begin() ne uspije, skica ispisuje
ERROR: Can't init the sensor! Check connections! i tu staje.
Korištene funkcije
sensorTypereturns sensorTypeStruktura koja sadrži jednu predefiniranu konfiguraciju. Njezina polja, redom: nanoAmperesPerPPM, internalZeroCalibration, adsGain, TIA_GAIN_IN_KOHMS, RLOAD, REF_SOURCE, INTERNAL_ZERO, BIAS_SIGN, BIAS, FET_SHORT i OP_MODE. Konfiguracije iz biblioteke, poput SENSOR_NO, vrijednosti su tipa sensorType u datoteci sensorConfigData.h. begin() šalje polja front-enda čipu LMP91000, a pojačanje ADC-u; getPPM() koristi osjetljivost i nultu kalibraciju.
ReturnsPredefinirana konfiguracija koju prosljeđujete objektu ElectrochemicalGasSensor.
ElectrochemicalGasSensor(sensorType _t, uint8_t _adcAddr = DEFAULT_ADC_ADDR, int _configPin = -1)returns ElectrochemicalGasSensorIzrađuje objekt senzora za jednu pločicu. Ništa se ne šalje preko I2C dok ne pozovete begin().
ReturnsObjekt senzora.
Parametri
| Tip | Naziv | Opis |
|---|---|---|
sensorType | _t | Predefinirana konfiguracija, u primjeru SENSOR_CUSTOM. |
uint8_t | _adcAddr | I2C adresa. U primjeru je izostavljena, pa je DEFAULT_ADC_ADDR, 0x49. Za adresu od 0x30 do 0x37 biblioteka komunicira s mostom ATtiny404 na pločici; za svaku drugu komunicira s ADS1115 na toj adresi i izravno s LMP91000. |
int | _configPin | GPIO spojen na LMPEN. U primjeru je izostavljen (-1), pa biblioteka ne prebacuje nijedan pin. |
sensor.begin()returns boolPokreće I2C pomoću Wire.begin(). Za adresu od 0x30 do 0x37 provjerava odgovara li most na pločici te preko njega šalje postavke ADC-a i front-enda, čekajući do 500 ms za svaki korak. Za svaku drugu adresu pokreće ADS1115 na toj adresi s pojačanjem iz predefinirane konfiguracije i najsporijom brzinom podataka, zatim konfigurira LMP91000 (pojačanje, opterećenje, referencu, unutarnju nulu, prednapetost i način rada), pri čemu drži GPIO _configPin u niskom stanju dok to traje, ako je zadan.
Returnstrue ako su svi koraci uspjeli, inače false.
sensor.getPPM()returns doubleUzima jedno očitanje ADC-a i pretvara ga: oduzima unutarnju nulu (2,5 V puta postotak unutarnje nule iz predefinirane konfiguracije), dodaje nultu kalibraciju, dijeli s pojačanjem pojačala da dobije struju ćelije, a to dijeli s vrijednošću nA po ppm iz predefinirane konfiguracije.
ReturnsKoncentracija plina u ppm. Negativan rezultat vraća se kao 0.
Sve zajedno
Predefinirana konfiguracija samo su podaci: definirate je jednom, proslijedite konstruktoru, a
begin() šalje njezine postavke front-enda kad pokrene senzor. Za isprobavanje drugih
vrijednosti uredite polja SENSOR_CUSTOM i ponovno učitajte skicu.