Skip to main content

Read two sensors on one bus

What this example shows​

The electrochemical-twoSensors.py example reads two boards on the same I2C bus, both with the ozone preset, and prints both concentrations in parts per billion (PPB) every 2.5 seconds.

Wire both boards to your controller through their top headers for this example, not through the Qwiic connectors: the controller's SDA to each board's SDA2, its SCL to each board's SCL2, its 3.3 V supply to each 3V3 and its ground to each GND. At these addresses the library talks to the ADS1115 and the LMP91000 directly on SDA2 and SCL2; the boards' ATtiny404 bridges are not used. Over Qwiic, only the bridge example in the Quick Start works.

The example code​

Each board gets its own ElectrochemicalGasSensor object on the shared i2c bus, created with its own address: sensor1 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.

As the example's connecting diagram says ("GPIO pin, required for I2C configuration"), wire the LMPEN pin on the 0x4A board's header to GPIO 25 and the one on the 0x49 board's header to GPIO 32. On this board, LMPEN also goes to the board's ATtiny404.

On this board, JP2 to JP4 set the address of the ADS1115 on the board's own bus (SDA2 and SCL2), the bus this example uses. JP2 is closed as shipped (0x49), so the 0x49 board stays as it is. On the 0x4A board, open JP2 before you close JP3, and leave JP4 open: closing JP3 with JP2 still closed ties SDA2 to 3V3 and stops the bus. Hardware details lists every jumper and the combinations to avoid. The board's address on the Qwiic bus is set with the ADDRESS switch.

The comments also say that both LMP91000 chips share address 0x48 and that LMPEN picks the active one. That means one chip per board: each board has a single LMP91000, at 0x48 on the board's own bus (SDA2 and SCL2).

# 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

→

The shell shows:

ShellMicroPython
Electrochemical Gas Sensor - Two Sensors Example
Sensor 1 initialized successfully!
Sensor 2 initialized successfully!

Then, every 2.5 seconds, a Sensor 1 reading: line and a Sensor 2 reading: line, each with five decimals and PPB. If a sensor's begin() fails, the script prints ERROR: Can't init sensor 1! Check connections! (or sensor 2) and waits.

Functions used​

I2C and Pin come from MicroPython's own machine module, and time.sleep_ms() from its time module. The functions below are the library's.

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

Creates the sensor object for one board; the example creates one per board. The library reads adc_addr to decide how to talk to it: for an address from 0x30 to 0x37 it uses the protocol of the ATtiny404 bridge; for any other address it talks to an ADS1115 at that address and to the LMP91000 at 0x48 itself.

ReturnsThe sensor object.

Parameters

NameTypeDescription
sensor_typeSensorConfigThe preset for the board's cell: SENSOR_CO, SENSOR_NO2, SENSOR_SO2, SENSOR_O3, SENSOR_NO, SENSOR_H2S, SENSOR_NH3, SENSOR_CL2, or your own SensorConfig.
i2cmachine.I2CThe I2C bus; pass the same object for both boards.
adc_addrintThe address begin() uses, different for each board. 0x30 to 0x37 selects the bridge protocol; this board answers at 0x30 out of the box, or at the address its switch sets. Any other value is taken as an ADS1115 address. The default is 0x49.
config_pinintA GPIO number for the LMP91000 enable line, one per board. The library holds it high and pulls it low only while it writes the LMP91000's registers itself; for an address from 0x30 to 0x37 it is not used. None by default.
begin()returns bool

Sets up the connection for adc_addr and configures the LMP91000 with the preset. For 0x30 to 0x37 it checks that the bridge answers, sends the ADC gain and has the bridge write the LMP91000's registers, each step giving up after 500 ms. For any other address it checks with an I2C scan that a device answers at adc_addr, then writes the LMP91000's registers at 0x48 when its status reads ready. Call it once for each board.

ReturnsTrue when every step succeeded, False otherwise.

getPPB()returns float

Takes one reading of the ADS1115's channel 0 (through the bridge for 0x30 to 0x37) and converts it to a concentration with the preset: it removes the internal zero offset, adds the zero calibration, divides by the amplifier gain and by the cell's sensitivity in nA per PPM, and multiplies by 1000. A negative result is returned as 0.

ReturnsThe gas concentration in PPB.

Putting it together​

Open the I2C bus once and create one sensor object per board, each with its own address. Call begin() on each and stop if one returns False, then read each board with getPPB().