Read the NO concentration
What this example shows
The bridgeBoard example talks to the board at its I2C address, 0x30. The
library sees an address from 0x30 to 0x37 and uses the board's ATtiny404 bridge:
begin() checks that the bridge answers, sets up the ADC and configures the
LMP91000 front end for the chosen cell. Each getPPM() then triggers one ADC
conversion and turns it into a concentration in ppm.
Connect the breakout with a Qwiic cable and leave the ADDRESS switch as it came, so the board answers at its default address, 0x30.
Change SENSOR_CO to SENSOR_NO before you upload. SENSOR_NO is the
library's preset for this board's SGX-4NO-250 cell: 400 nA per ppm, a 120 kΩ
amplifier gain and a positive 12% bias. SENSOR_CO is the preset for a
carbon monoxide cell, with no bias and a 14 kΩ gain, so its result is not NO
in ppm.
The example code
The listing is the library's file at the pinned commit. Only comment lines are left out: the three that name the old connector, and the header lines that link other products' store pages.
The sketch's comment says LMPEN is hardwired to GND. On this board a 10 kΩ
resistor pulls LMPEN to GND, and the pin is also wired to the ATtiny404 and
the header. Either way you pass no pin for it: at 0x30 to 0x37 the library
ignores the constructor's third argument.
/**
**************************************************
*
* @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);
}
Expected result (readings in clean air; yours will differ):
Sensor initialized successfully!
Sensor reading: 0.00630 PPM
Sensor reading: 0.00629 PPM
Sensor reading: 0.00591 PPM
Sensor reading: 0.00588 PPM
Each Sensor reading: line is one reading, with the NO concentration in ppm
to five decimals and PPM at the end. If the board does
not answer, the sketch prints
ERROR: Can't init the sensor! Check connections and jumper address! and stops
there.
Functions used
ElectrochemicalGasSensor(sensorType _t, uint8_t _adcAddr = DEFAULT_ADC_ADDR, int _configPin = -1)returns ElectrochemicalGasSensorCreates the sensor object for one board. Nothing is sent over I2C until you call begin().
ReturnsThe sensor object.
Parameters
| Type | Name | Description |
|---|---|---|
sensorType | _t | The cell preset. Use SENSOR_NO for this board. The library also has SENSOR_CO, SENSOR_NO2, SENSOR_SO2, SENSOR_O3, SENSOR_H2S, SENSOR_NH3 and SENSOR_CL2. |
uint8_t | _adcAddr | The I2C address. The example passes 0x30, the address the board ships with. The ADDRESS switch moves it within 0x30 to 0x37, but which setting gives which address is not confirmed yet, so only 0x30 is certain. For an address from 0x30 to 0x37 the library talks to the board's bridge; for any other, such as the default DEFAULT_ADC_ADDR (0x49), it talks to the ADC and the front end directly. |
int | _configPin | The GPIO wired to LMPEN. Ignored at addresses 0x30 to 0x37, so the example leaves it out. |
sensor.begin()returns boolStarts I2C with Wire.begin(), checks that the board's bridge answers, sets the ADC gain from the preset and the slowest ADC data rate, then configures the LMP91000 front end (gain, load, reference, internal zero, bias and mode) from the preset. Each step waits up to 500 ms for the bridge to answer.
Returnstrue when every step succeeded, false otherwise.
sensor.getPPM()returns doubleTakes one ADC reading and converts it: subtracts the internal zero (2.5 V times the preset's internal zero percentage), adds the zero calibration, divides by the amplifier gain to get the cell current, and divides that by the preset's nA per ppm.
ReturnsThe gas concentration in ppm. A negative result is returned as 0.
sensor.getPPB()returns doubleThe alternative the sketch's comment offers: takes the same reading as getPPM() and multiplies it by 1000.
ReturnsThe gas concentration in ppb.
Putting it together
begin() runs once in setup(). If it returns false, the sketch prints the
error and stays in an endless loop, so you see the problem at once instead of
zeros. In loop(), each getPPM() makes one fresh measurement and the sketch
prints it with five decimals, then waits 2.5 seconds.