Skip to main content

Prilagođena konfiguracija analognog sučelja

Što ovaj primjer prikazuje​

Primjer customConfig iz biblioteke gradi vlastiti sensorType umjesto korištenja unaprijed definirane postavke i šalje te postavke analognom sučelju LMP91000 i ADC-u. Koristite ga kada želite sami podesiti pojačanje, unutarnju nulu ili pomak nule.

Primjer stvara senzor s vlastitim SENSOR_CUSTOM i bez adrese, pa se koristi zadana adresa biblioteke. Za ćeliju ove pločice vrijednosti postavke SENSOR_NH3 dobra su polazna točka:

PoljeVrijednost SENSOR_NH3
nanoAmperesPerPPM40.0F
internalZeroCalibration0
adsGainADS_GAIN_4_096V
TIA_GAIN_IN_KOHMSTIA_GAIN_35_KOHM
RLOADRLOAD_10_OHM
REF_SOURCEREF_EXTERNAL
INTERNAL_ZEROINTERNAL_ZERO_20_PERCENT
BIAS_SIGNBIAS_SIGN_POSITIVE
BIASBIAS_0_PERCENT
FET_SHORTFET_SHORT_DISABLED
OP_MODEOP_MODE_3LEAD_AMP_CELL

Vlastite vrijednosti primjera (100 nA po ppm, pojačanje od 120 kΩ, negativan predznak biasa) samo su uzorak, a ne vrijednosti ove ćelije.

Biblioteka komunicira s ATtiny404 mostom na pločici samo kada je adresa u rasponu od 0x30 do 0x37. Svaka druga adresa, poput zadane 0x49 koju koristi ovaj primjer, tumači se kao I2C adresa ADS1115 s kojim biblioteka komunicira izravno. Na ovoj je pločici ADS1115 spojen na pinove SDA2/SCL2 headera, do kojih Qwiic konektori ne dopiru, pa se ovaj primjer ne izvodi preko Qwiic kabela. Umjesto toga povežite kontroler s headerom: 3,3 V na 3V3, GND na GND, SDA na SDA2 i SCL na SCL2. Primjer se tada izvodi onako kako je napisan, bez promjene adrese.

Komentari u primjeru povezuju LMPEN na GPIO pin. Na ovoj pločici LMPEN ostavite nepovezan: otpornik od 10 kΩ već ga povlači na GND, a na njega je spojen i ATtiny404.

Kod primjera​

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

Serijski monitor prikazuje:

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

Zatim primjer svake 2,5 sekunde ispisuje Sensor reading: u zasebnom retku, a u sljedećem retku vrijednost i PPM.

Ako begin() vrati false, primjer umjesto toga ispisuje ERROR: Can't init the sensor! Check connections! i zaustavlja se.

Korištene funkcije​

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

Stvara objekt senzora s bilo kojim sensorType, unaprijed definiranim ili vlastitim. begin() na temelju adrese odabire kako će komunicirati s pločicom: od 0x30 do 0x37 koristi ATtiny404 most; svaka druga adresa koristi se kao vlastita I2C adresa ADS1115. Ako se adresa izostavi, kao u ovom primjeru, koristi se DEFAULT_ADC_ADDR, 0x49.

ReturnsKonstruktor.

Parametri

ParametarTipOpis
_tsensorTypeVaša konfiguracija, ovdje SENSOR_CUSTOM.
_adcAddruint8_tAdresa. Zadano DEFAULT_ADC_ADDR (0x49). Na ovoj pločici prekidač ADDRESS postavlja adresu mosta od 0x30 do 0x37.
_configPinintGPIO koji biblioteka postavlja u nisko stanje dok konfigurira LMP91000 kada je adresa izvan raspona od 0x30 do 0x37. Ne koristi se od 0x30 do 0x37. Zadano -1, bez pina.
bool begin()returns bool

Pokreće I2C, postavlja ADC s pojačanjem iz vašeg sensorType (preko mosta za adresu od 0x30 do 0x37, ili izravno preko ADS1115 za svaku drugu adresu) te upisuje tri vrijednosti registara LMP91000 izgrađene iz vašeg sensorType.

Returnstrue kada su svi koraci uspjeli. false kada most nije odgovorio s OK unutar 500 ms ili je javio pogrešku, kada pokretanje ADS1115 nije uspjelo ili kada konfiguracija analognog sučelja nije uspjela.

double getPPM()returns double

Očitava jednu vrijednost i pretvara je u ppm uz pojačanje, unutarnju nulu, pomak i osjetljivost iz vaše konfiguracije. Rezultat manji od nule vraća se kao 0.

ReturnsKoncentracija plina u ppm.

Sve zajedno​

begin() pakira vaš sensorType u tri registra postavki LMP91000 i upisuje ih, a getPPM() ista polja koristi za preračunavanje. Mijenjajte jedno po jedno polje i usporedite s postavkom SENSOR_NH3 kako biste vidjeli što koje od njih radi.