Skip to main content

Očitavanje koncentracije NO2

Što prikazuje ovaj primjer​

Primjer bridgeBoard iz biblioteke stvara senzor na I2C adresi pločice, pokreće ga i svake 2,5 sekunde ispisuje koncentraciju plina u ppm. Adresa od 0x30 do 0x37 govori biblioteci da komunicira s ATtiny404 mikrokontrolerom na pločici, koji umjesto vas upravlja čipovima LMP91000 i ADS1115.

The example creates the sensor with the carbon monoxide preset, SENSOR_CO. Change SENSOR_CO to SENSOR_NO2 before you upload it: SENSOR_NO2 is the library's preset for the SGX-4NO2 cell on this board. If you moved the ADDRESS switches, change 0x30 to the address they set.

I need to correct this: the answer must keep the line structure of the English. Here is the full, corrected version.

Primjer koda​

Select Board
bridgeBoard.ino
/**
**************************************************
*
* @file bridgeBoard.ino
* @brief See how to init a sensor on the new ATtiny404 bridge board revision,
*
* To successfully run the sketch:
* - Set the desired address using the jumpers on the back of the board
* (address = 0x30 + jumper offset, giving a range of 0x30-0x37)
* - Run the sketch and open serial monitor at 115200 baud!
*
* Note: on this board revision, LMPEN is hardwired to GND, so there's
* no configPin argument to pass - the constructor's third argument
* is ignored whenever the address falls in the bridge range (0x30-0x37).
*
*
* @authors @ soldered.com
***************************************************/

// Include the required library
#include "Electrochemical-Gas-Sensor-SOLDERED.h"

// Any additional boards on the same bus just need a different jumper setting
// (0x30-0x37), same as twoSensors.ino does for legacy boards with 0x49/0x4A/0x4B.
ElectrochemicalGasSensor sensor(SENSOR_CO, 0x30);

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 and jumper address!");
while (true)
delay(100);
}

Serial.println("Sensor initialized successfully!");
}

void loop()
{
// Make the reading
double reading = sensor.getPPM();

// If PPB is more relevant for your sensor, you can use:
// double reading = sensor.getPPB();

// Print the reading with 5 digits of precision
Serial.print("Sensor reading: ");
Serial.print(reading, 5);
Serial.println(" PPM");

// Wait a bit before reading again
delay(2500);
}

Komentar na vrhu primjera kaže da je LMPEN čvrsto spojen na GND. Na ovoj pločici LMPEN je ulaz za omogućavanje čipa LMP91000 i spojen je i na ATtiny404, kao što prikazuje Hardware Details . U oba slučaja na njega ne spajate ništa: na adresama od 0x30 do 0x37 biblioteka ne koristi treći argument konstruktora.

Očekivani rezultat:

Serial MonitorAutoscrollShow timestampNewline115200 baud
Message (Enter to send message to the board)
Sensor initialized successfully!
Sensor reading: 0.01453 PPM
Sensor reading: 0.01357 PPM
Sensor reading: 0.01379 PPM
Sensor reading: 0.01435 PPM

Nova linija Sensor reading: slijedi svake 2,5 sekunde, s koncentracijom NO2 u ppm na pet decimala. Ako pločica ne odgovori, ispisuje ERROR: Can't init the sensor! Check connections and jumper address! i staje.

Korištene funkcije​

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

Stvara objekt senzora. Ništa se ne šalje pločici dok ne pozovete begin(). Adresa određuje kako begin() komunicira s pločicom: od 0x30 do 0x37 šalje naredbe čipu ATtiny404, a od 0x48 do 0x4B (DEFAULT_ADC_ADDR je 0x49) izravno adresira ADS1115 na toj adresi i LMP91000.

ReturnsObjekt senzora.

Parametri

TypeNameDescription
sensorType_tThe cell's preset. Use SENSOR_NO2 for this board's SGX-4NO2 cell.
uint8_t_adcAddrThe board's I2C address. Use 0x30 to 0x37, as set by the ADDRESS switches; 0x30 as shipped.
int_configPinGPIO for the LMP91000 enable pin. Not used at addresses 0x30 to 0x37; leave it out.
sensor.begin()returns bool

Pokreće Wire, provjerava odgovara li pločica, zatim joj šalje pojačanje i brzinu podataka ADC-a te konfiguraciju čipa LMP91000 iz preseta. Svaki korak čeka do 500 ms na odgovor pločice. Pozovite ga jednom u setup().

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

sensor.getPPM()returns double

Traži od pločice novo očitanje ADC-a i pretvara ga u koncentraciju plina: napon minus unutarnja nula, plus kalibracijski pomak, podijeljeno s pojačanjem TIA-e i osjetljivošću ćelije iz preseta. Negativan rezultat vraća se kao 0.

ReturnsKoncentracija plina u ppm.

sensor.getPPB()returns double

Isto očitanje kao getPPM(), pomnoženo s 1000. Primjer ga u komentaru navodi kao redak koji treba koristiti kada vašem senzoru više odgovaraju dijelovi na milijardu.

ReturnsKoncentracija plina u ppb.

Sve zajedno​

begin() se izvršava jednom u setup(). Ako ne uspije, skica ispisuje pogrešku i ostaje u beskonačnoj petlji, pa se ništa drugo ne izvršava dok ne popravite spoj ili adresu i ne resetirate pločicu. U loop() svaki poziv getPPM() ponovno očitava ćeliju, a skica ispisuje vrijednost s pet decimala.