Skip to main content

Konfigurirajte vlastitu ćeliju

Što prikazuje ovaj primjer​

Primjer customConfig gradi vlastiti sensorType umjesto korištenja unaprijed definirane postavke, tako da svaku vrijednost možete postaviti prema tehničkom listu vaše ćelije, šalje ga na LMP91000 i ispisuje koncentraciju plina u dijelovima na milijun (PPM) svakih 2,5 sekunde.

Za ovaj primjer spojite kontroler na gornji header, a ne na Qwiic konektor: SDA kontrolera na SDA2, SCL na SCL2, napajanje od 3,3 V na 3V3 i masu na GND. Na ovoj adresi biblioteka komunicira s ADS1115 i LMP91000 izravno preko SDA2 i SCL2; ATtiny404 most pločice na adresi 0x30 ne koristi se. Preko Qwiic konektora radi samo primjer s mostom iz Brzog početka.

Kôd primjera​

Uredite vrijednosti u SENSOR_CUSTOM prema svojoj ćeliji; dugi komentar iznad njih navodi mogućnosti za svako polje. Skica stvara senzor samo pomoću SENSOR_CUSTOM, pa se koristi zadana adresa biblioteke.

Komentar u skici kaže da LMPEN treba spojiti na GPIO. Na ovoj pločici LMPEN ide na header i na ATtiny404 pločice.

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);
}

🔗Otvorite cijeli primjer

examples/customConfig u commitu c4df54b

→

Otvorite Serial Monitor na 115200 baud. Skica ispisuje:

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

Zatim svakih 2,5 sekunde ispisuje redak Sensor reading: , a iza njega redak s koncentracijom (pet decimala) i PPM. Ova skica ispisuje oznaku pomoću Serial.println(), pa se vrijednost nalazi u retku ispod nje. Ako begin() ne uspije, skica ispisuje ERROR: Can't init the sensor! Check connections! i zaustavlja se.

Polja strukture sensorType​

sensorType je obična struktura koja se popunjava redoslijedom u nastavku. Unaprijed definirane postavke poput SENSOR_CO također su vrijednosti tipa sensorType.

PoljeTipŠto postavlja
nanoAmperesPerPPMdoubleOsjetljivost ćelije u nA po PPM-u, prema njezinu tehničkom listu. Postavke biblioteke za NO2 i O3 koriste negativne vrijednosti.
internalZeroCalibrationdoubleNapon dodan svakom očitanju, vrijednost koju postavlja setCustomZeroCalibration().
adsGainuint8_tPuni mjerni opseg ADS1115: ADS_GAIN_6_144V, ADS_GAIN_4_096V, ADS_GAIN_2_048V, ADS_GAIN_1_024V, ADS_GAIN_0_512V ili ADS_GAIN_0_256V.
TIA_GAIN_IN_KOHMSuint8_tPojačanje pojačala LMP91000: 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 ili TIA_GAIN_350_KOHM.
RLOADuint8_tOpteretni otpornik: RLOAD_10_OHM, RLOAD_33_OHM, RLOAD_50_OHM ili RLOAD_100_OHM.
REF_SOURCEuint8_tReferenca: REF_INTERNAL ili REF_EXTERNAL. Pločica ima vanjsku referencu od 2,5 V.
INTERNAL_ZEROuint8_tUnutarnja nula kao udio reference: INTERNAL_ZERO_20_PERCENT, INTERNAL_ZERO_50_PERCENT, INTERNAL_ZERO_67_PERCENT ili INTERNAL_ZERO_BYPASSED.
BIAS_SIGNuint8_tPolaritet prednapona: BIAS_SIGN_NEGATIVE ili BIAS_SIGN_POSITIVE.
BIASuint8_tPrednapon kao udio reference, od BIAS_0_PERCENT do BIAS_24_PERCENT.
FET_SHORTuint8_tFET_SHORT_DISABLED ili FET_SHORT_ENABLED. Komentar u skici kaže da mora biti onemogućen da bi ćelija radila.
OP_MODEuint8_tNačin rada LMP91000: OP_MODE_3LEAD_AMP_CELL za ćeliju s 3 elektrode, ili OP_MODE_DEEP_SLEEP, OP_MODE_2LEAD_GROUND_CELL, OP_MODE_STANDBY, OP_MODE_TEMPERATURE_TIA_OFF, OP_MODE_TEMPERATURE_TIA_ON.

Korištene funkcije​

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

Stvara objekt senzora za jednu pločicu. Adresa određuje kako begin() komunicira s njim: za adresu od 0x30 do 0x37 koristi protokol mosta ATtiny404; za svaku drugu adresu komunicira s ADS1115 na toj adresi i izravno s LMP91000. Zadano je DEFAULT_ADC_ADDR (0x49).

ReturnsKonstruktor.

Parametri

NazivTipOpis
_tsensorTypeOvdje vlastiti SENSOR_CUSTOM iz skice.
_adcAddruint8_tAdresa koju koristi begin(). Adresa od 0x30 do 0x37 odabire protokol mosta; ova pločica odgovara na 0x30 u izvornom stanju, ili na adresi koju postavlja njezin prekidač. Svaka druga vrijednost tumači se kao adresa ADS1115. Zadano 0x49.
_configPinintGPIO za liniju omogućavanja LMP91000. Biblioteka je drži u visokom stanju i spušta je samo dok sama upisuje registre LMP91000; za adresu od 0x30 do 0x37 ne koristi se. Zadano -1 (nijedan).
bool begin()returns bool

Pokreće I2C pomoću Wire.begin() i bira protokol prema adresi. Za 0x30 do 0x37 provjerava odgovara li most, šalje ADC pojačanje iz konfiguracije i nalaže mostu da upiše registre LMP91000, pri čemu se svaki korak prekida nakon 500 ms. Za svaku drugu adresu provjerava odgovara li ADS1115 na toj adresi, postavlja njegovo pojačanje i upisuje registre LMP91000 kada LMP91000 javi da je spreman, a ako je zadan _configPin, spušta ga u nisko stanje tijekom upisa. Pozovite je jednom prije čitanja.

Returnstrue ako su svi koraci uspjeli, inače false.

double getPPM()returns double

Izvodi jedno očitanje kanala 0 ADS1115 (preko mosta za 0x30 do 0x37) i pretvara ga u koncentraciju prema konfiguraciji: uklanja pomak unutarnje nule, dodaje kalibraciju nule, dijeli s pojačanjem pojačala i s osjetljivošću u nA po PPM-u. Negativan rezultat vraća se kao 0.

ReturnsKoncentracija plina u PPM-u.

Sastavljanje cjeline​

Popunite sensorType prema tehničkom listu svoje ćelije i proslijedite ga ElectrochemicalGasSensor tamo gdje biste proslijedili unaprijed definiranu postavku. begin() šalje svoje postavke na LMP91000, a getPPM() za svako očitanje koristi njegove vrijednosti osjetljivosti i nule.