Skip to main content

Two sensors on one bus

What this example shows​

The electrochemical-twoSensors.py example reads two boards on the same I2C bus and prints both concentrations in parts per billion (ppb) every 2.5 seconds. It creates one sensor object per board, each with its own address: sensor1 with adc_addr=0x4A and config_pin=25, sensor2 with adc_addr=0x49 and config_pin=32.

What it needs on this board​

The example's addresses, 0x4A and 0x49, are ADS1115 addresses, not the board's bridge addresses. At an address outside 0x30 to 0x37 the module does not go through the bridge: begin() looks for each ADS1115 with an I2C scan and writes each LMP91000's configuration at 0x48, on the bus you pass it. The example's comments ask for a different ADC address on each breakout, set with the address jumpers, and for each board's LMPEN wired to its own GPIO (25 and 32), because both LMP91000 chips share address 0x48. The module drives each config_pin low while it writes that front end's configuration and high otherwise.

On this board the ADS1115 and the LMP91000 sit on the internal bus, which the top header brings out as SDA2 and SCL2; JP2 to JP4 set the ADS1115's address on that bus. The Qwiic connectors and SDA1/SCL1 reach only the ATtiny404 bridge, and an I2C scan over Qwiic finds only the bridge, at 0x30 as shipped. LMPEN is on the bottom header, pulled to GND through 10 kΩ and also wired to the ATtiny404.

So wire each board's top header for this example, not the Qwiic cable: connect your controller's SDA to each board's SDA2, its SCL to each board's SCL2, its 3.3 V pin to 3V3 and its GND to GND. The listing's connecting diagram shows Qwiic lines, but over Qwiic only each board's bridge answers.

Over Qwiic, two of these boards share one bus through their bridges: each needs its own address from 0x30 to 0x37, set with its three-switch ADDRESS DIP switch, and its own sensor object at that address. The switch and the jumpers are described on Hardware Details.

Before you run it, change SENSOR_O3 to SENSOR_CO in the import line and in both lines that create a sensor. SENSOR_O3 is the module's preset for the ozone cell. This board carries the SGX-4CO carbon monoxide cell, and the module's preset for it is SENSOR_CO. With the ozone preset, the module converts both readings with the ozone cell's sensitivity and zero, so the numbers are not CO concentrations.

The example opens I2C bus 0 with SCL on pin 22 and SDA on pin 21. Change them to your controller's I2C pins if they differ.

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)

The lines below are from a run of this example with two boards on one bus, each wired to the controller through its header's SDA2, SCL2, 3V3 and GND pins as described above.

Expected result in the Thonny shell:

ShellMicroPython
Electrochemical Gas Sensor - Two Sensors Example
Sensor 1 initialized successfully!
Sensor 2 initialized successfully!
Sensor 1 reading: 300.14804 PPB
Sensor 2 reading: 305.31076 PPB
Sensor 1 reading: 324.66712 PPB
Sensor 2 reading: 295.80346 PPB
Sensor 1 reading: 309.60049 PPB
Sensor 2 reading: 291.51048 PPB

Then two lines every 2.5 seconds, Sensor 1 reading: and Sensor 2 reading: , each with the concentration in ppb to five decimals and PPB. A result below zero is printed as 0.00000. If a board does not start, the shell shows ERROR: Can't init sensor 1! Check connections! (or sensor 2) and the script stops there.

Functions used​

ElectrochemicalGasSensor(sensor_type, i2c=None, adc_addr=0x49, config_pin=None)returns ElectrochemicalGasSensor

Creates one sensor object. The example calls it twice on the same I2C bus, once per board, each time with the preset, the shared bus, an ADS1115 address (0x4A, then 0x49) and a config_pin.

ReturnsThe sensor object.

Parameters

ParameterTypeDescription
sensor_typeSensorConfigThe cell's preset. For this board's SGX-4CO cell the module's preset is SENSOR_CO.
i2cmachine.I2CAn initialised I2C bus, shared by both objects here. With None, the module opens I2C 0 on pins 22 and 21 on an ESP32, or pins 5 and 4 on an ESP8266, and raises Board not recognized, please pass an I2C object manually on any other board.
adc_addrintThe I2C address. Default 0x49. From 0x30 to 0x37 the module talks to the board's ATtiny404 bridge.
config_pinint or NoneA GPIO the module drives low while it sends the front end's configuration and high otherwise. Not used at a 0x30 to 0x37 address. Default None.
begin()returns bool

Starts one sensor. At an adc_addr from 0x30 to 0x37 it checks that the bridge answers, sends it the ADC gain and data rate from the preset, then the front end's configuration, retrying a bus error until a 500 ms timeout for each step. At any other adc_addr it checks that the ADC answers at that address, sets its gain and data rate, then writes the front end's configuration with that object's config_pin held low.

ReturnsTrue if every step succeeded, False otherwise.

getPPB()returns float

Makes one measurement on that object's board and returns it in parts per billion.

ReturnsgetPPM() multiplied by 1000.

Putting it together​

Give each board its own address, create one object per board on the shared bus with SENSOR_CO and that address, call begin() on each and check it, then read each object with getPPB() in your loop. The example's addresses are ADS1115 addresses, each with a config_pin on that board's LMPEN; through the boards' bridges, the addresses are the ones on their ADDRESS switches, from 0x30 to 0x37, and no config_pin is used.