Custom address
What this example shows
The customAddress example creates the sensor at an address you choose
instead of the default, starts it, and prints a reading in PPM every 2.5
seconds. It passes the SENSOR_SO2 configuration, address 0x4B and pin 5
for LMPEN.
The example's comment names jumpers JP5 to JP7 for its addresses. On this
board the ADS1115 address jumpers are JP2 to JP4, and JP5 and JP6 connect the
I2C pull-ups; see
Hardware Details.
The board's own address, from 0x30 to 0x37, is set with the three-position
ADDRESS switch on its top side, not with jumpers on the back as the sketch's
comments say.
You do not need to wire LMPEN on this board, whatever the sketch's comments
say: the board holds it low itself.
The example code
/**
**************************************************
*
* @file customAddress.ino
* @brief See how to init a sensor on a custom address
*
* To successfully run the sketch:
* - Set the custom address using the jumpers on the back of the board
* - Connect LMPEN pin to GND or a GPIO pin so the breakout can be configured
* - Run the sketch and open serial monitor at 115200 baud!
*
*
* @authors Robert @ soldered.com
***************************************************/
// Include the required library
#include "Electrochemical-Gas-Sensor-SOLDERED.h"
// Create the sensor object with the according type
// To set a custom address, connect one of the following jumpers:
// JP5 for 0x49
// JP6 for 0x4A
// JP7 for 0x4B
// The final parameter is the GPIO pin for LMPEN
ElectrochemicalGasSensor sensor(SENSOR_SO2, 0x4B, 5);
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();
// 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);
}
What this board prints with the sketch as written has not been measured yet.
When this board was tested over Qwiic, an I2C scan found only one address,
0x30, so nothing answered at 0x4B, the address this sketch passes. If
begin() fails, the sketch prints
ERROR: Can't init the sensor! Check connections! and stops.
When begin() succeeds, the sketch prints:
Sensor initialized successfully!
After it, a line Sensor reading: followed by a value with five decimals and
PPM arrives every 2.5 seconds.
Functions used
ElectrochemicalGasSensor(sensorType _t, uint8_t _adcAddr = DEFAULT_ADC_ADDR, int _configPin = -1)returns ElectrochemicalGasSensorCreates the sensor object with a sensor configuration, an address and an LMPEN pin. Nothing is sent until you call begin(). begin() picks how to talk to the board from the address: from 0x30 to 0x37 it uses the ATtiny404 bridge's commands and ignores the third argument; any other address is taken as the ADS1115's own address, and the LMP91000 is written directly.
ReturnsThe sensor object.
Parameters
| Type | Name | Description |
|---|---|---|
sensorType | _t | The front end and conversion settings, SENSOR_SO2 in the example. The presets live in the library's src/sensorConfigData.h. |
uint8_t | _adcAddr | The address, 0x4B in the example. |
int | _configPin | The GPIO pin connected to LMPEN, 5 in the example. Not used for an address from 0x30 to 0x37. |
sensor.begin()returns boolStarts I2C with Wire.begin(). For an address from 0x30 to 0x37 it checks that the bridge answers, sends it the ADC gain and the slowest ADC data rate, then the LMP91000 settings; each bridge command waits up to 500 ms. For any other address it starts the ADS1115 at that address with the same gain and data rate, sets the LMPEN pin high if one was given, then writes the LMP91000 settings, holding that pin low while it does.
Returnstrue when every step succeeded, false otherwise.
sensor.getPPM()returns doubleTakes one ADC reading and turns the voltage into a concentration: it subtracts the internal zero (a share of the 2.5 V reference), adds the configuration's zero calibration, divides by the TIA gain to get the cell current, then divides by the configuration's nanoamperes per PPM. A negative result is returned as 0.
ReturnsThe concentration in PPM.
sensor.getPPB()returns doubleThe commented-out alternative in the example: the same reading as getPPM(), multiplied by 1000.
ReturnsThe concentration in PPB.
Putting it together
SENSOR_SO2 is the preset for an SGX-4SO2 sulphur dioxide cell. The library
has no preset for this board's SGX-4OX-ROHS oxygen cell yet, so the value the
example prints is calculated with the sulphur dioxide (SO2) preset's settings. The
custom configuration
page shows how to write your own.