Skip to main content

Read two sensors on one bus

What this example shows​

The electrochemical-twoSensors.py example reads two boards on one I2C bus and prints both readings in ppb (parts per billion) every 2.5 seconds. It creates one sensor object per board: sensor1 at adc_addr=0x4A with config_pin=25, and sensor2 at adc_addr=0x49 with config_pin=32. At these addresses the module talks to each board's ADS1115 and LMP91000 directly, not through the ATtiny404 bridge, and the example's comments ask for each board's LMPEN connected to its GPIO. See the library overview for how the address decides this.

On this board the ADS1115 address is set by the solder jumpers JP2 (0x49, closed as it comes), JP3 (0x4A) and JP4 (0x4B). The board for sensor2 keeps JP2 closed for 0x49. On the board for sensor1, cut JP2 and then bridge JP3 for 0x4A. Keep exactly one of JP2, JP3 and JP4 closed on each board. See Hardware Details for the jumper table and which combinations to avoid.

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

The example passes SENSOR_O3, the module's preset for an ozone cell. For a nitric oxide reading, use SENSOR_NO in place of SENSOR_O3 in all three places (the import line and both ElectrochemicalGasSensor(...) lines). SENSOR_NO is the preset for this board's SGX-4NO-250 cell: 400 nA per ppm, a 120 kΩ amplifier gain and a positive 12% bias.

The example code​

The listing is the module's file at the pinned commit. Only comment lines are left out: the header line that names another product's store page, and the connecting-diagram lines that name an old board.

# 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, with SENSOR_NO for both boards (readings in clean air; yours will differ):

ShellMicroPython
Electrochemical Gas Sensor - Two Sensors Example
Sensor 1 initialized successfully!
Sensor 2 initialized successfully!
Sensor 1 reading: 5.88777 PPB
Sensor 2 reading: 6.11838 PPB
Sensor 1 reading: 6.30553 PPB
Sensor 2 reading: 6.01070 PPB
Sensor 1 reading: 5.75920 PPB
Sensor 2 reading: 5.93205 PPB

The readings come in pairs of lines starting Sensor 1 reading: and Sensor 2 reading: , one pair every 2.5 seconds, with each concentration in ppb to five decimals and PPB at the end. If a begin() fails, the example prints ERROR: Can't init sensor 1! Check connections! (or sensor 2) and stays in a loop.

Functions used​

I2C(0, scl=Pin(22), sda=Pin(21))returns I2C

Creates hardware I2C bus 0 on the given SCL and SDA pins. machine.I2C and machine.Pin come with MicroPython and are not part of the Soldered module (see docs.micropython.org, machine.I2C and machine.Pin).

ReturnsThe I2C bus object both sensors share.

Parameters

TypeNameDescription
intidThe hardware I2C bus, 0 in the example.
PinsclThe clock pin, Pin(22) in the example.
PinsdaThe data pin, Pin(21) in the example.
ElectrochemicalGasSensor(sensor_type, i2c=None, adc_addr=0x49, config_pin=None)returns ElectrochemicalGasSensor

Creates one sensor object per board. Nothing is sent over I2C until you call begin(). With i2c=None the module opens a bus itself on the boards it recognises, including an ESP32, where it opens I2C(0, scl=Pin(22), sda=Pin(21)), and an ESP8266, where it opens I2C(scl=Pin(5), sda=Pin(4)). On a board it does not recognise it raises an exception.

ReturnsThe sensor object.

Parameters

TypeNameDescription
SensorConfigsensor_typeThe cell preset, SENSOR_O3 for both boards in the example. SENSOR_NO is the one for this board's cell.
I2Ci2cThe I2C bus, the same one for both boards.
intadc_addrThe board's I2C address, 0x4A for sensor 1 and 0x49 for sensor 2 in the example. For 0x30 to 0x37 the module talks to that board's ATtiny404 bridge; for any other address it talks to the ADS1115 at that address and to the LMP91000 directly.
intconfig_pinA GPIO for that board's LMPEN, 25 and 32 in the example. The module holds it high and pulls it low only while it configures that board's LMP91000. Unused at addresses 0x30 to 0x37.
sensor1.begin()returns bool

Starts sensor 1. For an address from 0x30 to 0x37 it checks that the board's bridge answers and sends the ADC and front-end settings through it, waiting up to 500 ms for each step. For any other address it checks that the ADS1115 answers at adc_addr in an I2C scan, sets the preset's ADC gain and the slowest data rate, then configures the LMP91000 at 0x48 (gain, load, reference, internal zero, bias and mode), pulling config_pin low only during that configuration. sensor2.begin() does the same for the second board.

ReturnsTrue when every step succeeded, False otherwise.

sensor1.getPPB()returns float

Takes one reading from that board with getPPM() and multiplies it by 1000. getPPM() reads ADC channel 0 (at 0x30 to 0x37, the bridge runs the conversion), subtracts the internal zero (2.5 V times the preset's internal zero percentage), adds the zero calibration, then divides by the amplifier gain and by the preset's nA per ppm. sensor2.getPPB() reads the second board.

ReturnsThe gas concentration in ppb. A negative result is returned as 0.0.

Putting it together​

Each board gets its own sensor object at its own address, and both share one I2C bus. The example starts sensor 1, then sensor 2, and stops at the first one that fails. In the loop it reads both boards and prints the two readings together.