Two sensors
What this example shows
The electrochemical-twoSensors.py example creates two sensor objects on one
I2C bus, sensor1 and sensor2, starts both, and prints a reading in PPB from
each every 2.5 seconds. sensor1 is created with adc_addr=0x4A and
config_pin=25, sensor2 with adc_addr=0x49 and config_pin=32.
The example opens I2C bus 0 with SCL on pin 22 and SDA on pin 21. Change
them to the pins your controller's Qwiic connector or your wiring uses.
You do not need to wire LMPEN to pins 25 and 32 on these boards, whatever
the example's comments say: each board holds it low itself. Where the comments
mention address jumpers, this board's own address, from 0x30 to 0x37, is
set with the three-position ADDRESS switch on its top side.
The example code
# FILE: electrochemical-twoSensors.py
# AUTHOR: Fran Fodor @ Soldered
# BRIEF: Two O3 sensor PPB reading example using two breakouts on one I2C bus.
# LAST UPDATED: 2026-05-21
# Connecting diagram:
#
# Qwiic------------------------>Qwiic
# LMPEN------------------------>25 (GPIO pin, required for I2C configuration)
#
# Qwiic------------------------>Qwiic (same bus)
# LMPEN------------------------>32 (GPIO pin, required for I2C configuration)
#
# Set different ADC I2C addresses on each breakout using the address jumpers.
# Both LMP91000 chips share address 0x48 — the LMPEN pin selects which one
# is active during configuration, so a GPIO pin is required for each sensor.
from machine import I2C, Pin
import time
from ElectrochemicalGasSensor import ElectrochemicalGasSensor, SENSOR_O3
# Initialize shared I2C bus
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# Sensor 1: ADC address 0x4A, LMPEN on pin 25
sensor1 = ElectrochemicalGasSensor(SENSOR_O3, i2c, adc_addr=0x4A, config_pin=25)
# Sensor 2: ADC address 0x49, LMPEN on pin 32
sensor2 = ElectrochemicalGasSensor(SENSOR_O3, i2c, adc_addr=0x49, config_pin=32)
# -------------------------------------------------------------------------
# Setup
# -------------------------------------------------------------------------
print("Electrochemical Gas Sensor - Two Sensors Example")
if not sensor1.begin():
print("ERROR: Can't init sensor 1! Check connections!")
while True:
time.sleep_ms(100)
print("Sensor 1 initialized successfully!")
if not sensor2.begin():
print("ERROR: Can't init sensor 2! Check connections!")
while True:
time.sleep_ms(100)
print("Sensor 2 initialized successfully!")
# -------------------------------------------------------------------------
# Main loop
# -------------------------------------------------------------------------
while True:
reading1 = sensor1.getPPB()
reading2 = sensor2.getPPB()
print("Sensor 1 reading: {:.5f} PPB".format(reading1))
print("Sensor 2 reading: {:.5f} PPB".format(reading2))
time.sleep_ms(2500)
🔗Open the complete example
Examples/electrochemical-twoSensors.py at commit 623e1e6
What two of these boards print with the example 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 0x4A or 0x49, the addresses this
example passes, and begin() failed for a sensor created at 0x49. If a
sensor's begin() fails, the example prints
ERROR: Can't init sensor 1! Check connections! (or sensor 2) and stops
there.
When both begin() calls succeed, the shell shows:
Electrochemical Gas Sensor - Two Sensors Example
Sensor 1 initialized successfully!
Sensor 2 initialized successfully!
After that, every 2.5 seconds, a line Sensor 1 reading: and a line
Sensor 2 reading: , each followed by a value with five decimals and PPB.
Functions used
I2C(id, scl, sda)returns I2CCreates the I2C bus object from MicroPython's machine module, which both sensor objects share. The example uses bus 0 with SCL on Pin(22) and SDA on Pin(21). I2C and Pin come with MicroPython and are not part of this library.
ReturnsThe I2C bus object.
Parameters
| Type | Name | Description |
|---|---|---|
int | id | The hardware I2C bus, 0 in the example. |
Pin | scl | The clock pin, Pin(22) in the example. |
Pin | sda | The data pin, Pin(21) in the example. |
ElectrochemicalGasSensor(sensor_type, i2c=None, adc_addr=0x49, config_pin=None)returns ElectrochemicalGasSensorCreates one sensor object. Nothing is sent to the board until you call begin(). The example creates sensor1 with adc_addr=0x4A and config_pin=25, and sensor2 with adc_addr=0x49 and config_pin=32.
ReturnsThe sensor object.
Parameters
| Type | Name | Description |
|---|---|---|
SensorConfig | sensor_type | The front end and conversion settings, SENSOR_O3 for both sensors in the example. |
I2C | i2c | The bus to use; both sensors share the same one. |
int | adc_addr | The address the module talks to, 0x49 by default; 0x4A for sensor1 and 0x49 for sensor2 here. An address from 0x30 to 0x37 makes begin() use the bridge commands; any other address is taken as the ADS1115's own address. |
int | config_pin | A GPIO pin the module holds high and pulls low while it writes the LMP91000 settings; 25 for sensor1 and 32 for sensor2 here. None by default; not used for an address from 0x30 to 0x37. |
sensor.begin()returns boolConfigures the ADC and the LMP91000 from the sensor configuration. For an adc_addr from 0x30 to 0x37 it checks that the board's bridge answers and sends it the ADC gain, the slowest ADC data rate and the LMP91000 settings, retrying each command for up to 500 ms. For any other address it sets up the ADS1115 at that address with the same gain and data rate and writes the LMP91000 settings directly, pulling config_pin low while it does. The example calls it on sensor1, then on sensor2.
ReturnsTrue when every step succeeded, False otherwise.
sensor.getPPB()returns floatTakes one reading and returns it in parts per billion: the getPPM() value multiplied by 1000. getPPM() subtracts the internal zero (a share of the board's 2.5 V reference), adds the configuration's zero calibration, divides by the TIA gain and by the configuration's nanoamperes per PPM, and returns 0.0 for a negative result.
ReturnsThe concentration in PPB.
Putting it together
SENSOR_O3 is the preset for an SGX-403-20 ozone cell. The module has no
preset for this board's SGX-4OX-ROHS oxygen cell yet, so the values the example
prints are calculated with the ozone cell's settings. The
custom configuration
page shows how to write your own.