Read the gas concentration
What this example shows
The electrochemical-bridgeBoard.py example starts the board at its default
address, 0x30, sets up the analog front end for one gas cell, and prints the
gas concentration in parts per million (PPM) every 2.5 seconds.
Behind address 0x30 is the board's ATtiny404. It configures the LMP91000 and reads the ADS1115 on the board's own internal bus, so your script only ever talks to one I2C device.
The example code
The example uses the ozone preset, SENSOR_O3, and opens I2C bus 0 with SCL
on pin 22 and SDA on pin 21. Change the pins to match your controller, and
import and pass the preset for your cell: SENSOR_CO, SENSOR_NO2,
SENSOR_SO2, SENSOR_NO, SENSOR_H2S, SENSOR_NH3 or SENSOR_CL2. The
example's comments call the address setting "jumpers on the back of the
board"; on this board it is the ADDRESS switch on the top. If you set it to
another address, change adc_addr to match. The comments also say LMPEN is
tied to GND; on this board it goes to the header and to the ATtiny404, and
the library does not drive it. The comment that mentions "legacy boards with
0x49/0x4A/0x4B" means boards read at those addresses, where the library talks
to an ADS1115 directly instead of to the bridge. This board answers at 0x30 to
0x37.
# FILE: electrochemical-bridgeBoard.py
# AUTHOR: Fran Fodor @ Soldered
# BRIEF: Single sensor PPM reading example for the ATtiny404 bridge board revision,
# which allows daisy-chaining multiple boards on one I2C bus.
# LAST UPDATED: 2026-07-23
# Connecting diagram:
#
# Qwiic------------------------>Qwiic
#
# Note: on this board revision, LMPEN is hardwired to GND, so there's no
# config_pin to set - it's ignored whenever adc_addr falls in the bridge
# range (0x30-0x37). Set the desired address using the jumpers on the back
# of the board before powering it on.
from machine import I2C, Pin
import time
from ElectrochemicalGasSensor import ElectrochemicalGasSensor, SENSOR_O3
# Initialize I2C
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# (address = 0x30 + jumper offset, giving a range of 0x30-0x37).
# Any additional boards on the same bus just need a different jumper
# setting, same as twoSensors.py does for legacy boards with 0x49/0x4A/0x4B.
sensor = ElectrochemicalGasSensor(SENSOR_O3, i2c, adc_addr=0x30)
# -------------------------------------------------------------------------
# Setup
# -------------------------------------------------------------------------
print("Electrochemical Gas Sensor - ATtiny Bridge Board Example")
if not sensor.begin():
print("ERROR: Can't init the sensor! Check connections and jumper address!")
while True:
time.sleep_ms(100)
print("Sensor initialized successfully!")
# -------------------------------------------------------------------------
# Main loop
# -------------------------------------------------------------------------
while True:
reading = sensor.getPPM()
# If PPB is more relevant for your sensor, use:
# reading = sensor.getPPB()
print("Sensor reading: {:.5f} PPM".format(reading))
time.sleep_ms(2500)
🔗Open the complete example
Examples/electrochemical-bridgeBoard.py at commit 623e1e6
Expected result, in the shell:
Electrochemical Gas Sensor - ATtiny Bridge Board Example
Sensor initialized successfully!
Then a line every 2.5 seconds: Sensor reading: , the concentration with five
decimals, and PPM. If the board does not answer, the script prints
ERROR: Can't init the sensor! Check connections and jumper address! 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 ElectrochemicalGasSensorCreates the sensor object for one 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. The example passes 0x30.
ReturnsThe sensor object.
Parameters
| Name | Type | Description |
|---|---|---|
sensor_type | SensorConfig | The preset for your cell: SENSOR_CO, SENSOR_NO2, SENSOR_SO2, SENSOR_O3, SENSOR_NO, SENSOR_H2S, SENSOR_NH3, SENSOR_CL2, or your own SensorConfig. |
i2c | machine.I2C | The I2C bus the board is on. When left out, the library opens I2C bus 0 with SCL on pin 22 and SDA on pin 21 on an ESP32 port, or I2C with SCL on pin 5 and SDA on pin 4 on an ESP8266 port, and raises an exception on any other board. |
adc_addr | int | The board's I2C address, 0x30 to 0x37 as set by the address switch. 0x30 out of the box. |
config_pin | int | A GPIO number for the LMP91000 enable line. 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, so the example leaves it out. None by default. |
begin()returns boolChecks that the bridge answers, sends the ADC gain from the preset, and configures the LMP91000 with the preset's gain, load, reference, bias and mode. Call it once before reading.
ReturnsTrue when the bridge answered and both configurations succeeded, False otherwise. Each step gives up after 500 ms without an answer.
getPPM()returns floatTakes one ADC reading through the bridge 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. A negative result is returned as 0.
ReturnsThe gas concentration in PPM.
getPPB()returns floatThe same reading as getPPM(), in parts per billion.
ReturnsThe gas concentration in PPB, getPPM() x 1000.
Putting it together
Create one ElectrochemicalGasSensor per board, with the preset for its cell,
the I2C bus and its address. Call begin() once and stop if it returns
False. Then call getPPM() or getPPB() as often as you need a reading.
To run more than one board on the same bus, give each its own address with the
address switch (0x30 to 0x37) and create one object per address on the same
i2c bus.