Read two sensors on one bus
What this example shows
The module's electrochemical-twoSensors.py example reads two boards on one
I2C bus. It creates one sensor object per board, starts both, and prints both
concentrations in ppb (parts per billion) every 2.5 seconds.
The example creates sensor1 with adc_addr=0x4A and config_pin=25, and
sensor2 with adc_addr=0x49 and config_pin=32, so the two sensors differ
in their address and their LMPEN pin.
The example's comments wire each board's LMPEN to the GPIO it passes as
config_pin, 25 and 32. On this board, LMPEN is the LMP91000's enable input
on the bottom header, and it is also wired to the board's ATtiny404 (see the
pin table on the Hardware details page).
Both sensors use the ozone preset, SENSOR_O3. SENSOR_NO2 is the module's
preset for this board's SGX-4NO2 cell; change it in the import line and in
both lines that create a sensor. The example opens I2C bus 0 with SCL on pin
22 and SDA on pin 21; change them to match your controller.
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
Expected result:
Electrochemical Gas Sensor - Two Sensors Example
Sensor 1 initialized successfully!
Sensor 2 initialized successfully!
Then every 2.5 seconds the example prints two lines, one starting with
Sensor 1 reading: and one with Sensor 2 reading:, each followed by that
board's concentration in ppb with five decimals. If a board fails to start, it
prints ERROR: Can't init sensor 1! Check connections! (or sensor 2) and
waits in a loop.
Functions used
ElectrochemicalGasSensor(sensor_type, i2c=None, adc_addr=0x49, config_pin=None)returns ElectrochemicalGasSensorCreates one sensor object. With a config_pin it also sets that pin as an output and drives it high. Nothing is sent over I2C until you call begin(). The example creates two, one per board, on the same I2C object.
ReturnsThe sensor object.
Parameters
| Type | Name | Description |
|---|---|---|
SensorConfig | sensor_type | The cell's preset. SENSOR_NO2 is the preset for this board's SGX-4NO2 cell. |
I2C | i2c | The I2C bus, shared by both sensors in the example. With None, the module picks the pins by the port MicroPython reports: I2C bus 0 on pins 22 (SCL) and 21 (SDA) on the ESP32 port, scl=Pin(5), sda=Pin(4) on the ESP8266 port. On a port it does not recognise, it raises Board not recognized, please pass an I2C object manually. |
int | adc_addr | The address begin() talks to, 0x49 by default; the example passes 0x4A and 0x49. From 0x30 to 0x37 the module sends its commands to the ATtiny404; from 0x48 to 0x4B it addresses the ADS1115 at adc_addr and the LMP91000 directly. |
int | config_pin | GPIO number for the LMP91000's enable pin (LMPEN), used only at 0x48 to 0x4B. None by default; the example passes 25 and 32. |
sensor.begin()returns boolStarts one sensor and writes the preset to it. At 0x30 to 0x37 it checks that the ATtiny404 answers, then sends the ADC gain and data rate and the LMP91000 configuration, each step retrying until the board answers or 500 ms pass. At 0x48 to 0x4B it checks that the ADS1115 shows up in an I2C scan at adc_addr, sets its gain and its slowest data rate, and writes the configuration to the LMP91000 at 0x48, pulling config_pin low while it does. Call it once for each sensor before reading.
ReturnsTrue when every step succeeded, False otherwise.
sensor.getPPB()returns floatTakes a new reading from one sensor and returns its gas concentration in parts per billion: getPPM() multiplied by 1000. A negative result is returned as 0.0.
ReturnsThe gas concentration in ppb.
Putting it together
Both sensor objects share one I2C object and differ in their address and
LMPEN pin. The example starts sensor1, then sensor2, and stops in a loop
at the first one that fails. Each pass of the main loop reads both sensors
with getPPB(), prints the two values with five decimals, and waits 2.5
seconds.