Read the CO concentration
What this example shows
The electrochemical-bridgeBoard.py example opens I2C, creates the sensor at
the board's default address, 0x30, and prints the gas concentration in ppm every
2.5 seconds. Any address from 0x30 to 0x37 makes the module talk to the board's
ATtiny404 bridge, which sets up the front end and ADC for you, so LMPEN needs
no wiring.
Before you run it, change SENSOR_O3 to SENSOR_CO in the import line and
in the ElectrochemicalGasSensor(...) line. SENSOR_O3 is the module's
preset for the ozone cell, so getPPM() would convert with that cell's
sensitivity and zero. This board carries the SGX-4CO carbon monoxide cell, and
the module's preset for it is SENSOR_CO.
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-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)
On this board, the address is set with the three-switch ADDRESS DIP switch on the top
side, at the top left, not with jumpers on the back, and the default 0x30 needs
no change. LMPEN is pulled to GND through 10 kΩ rather than wired straight to
it; either way, you connect nothing to it.
Expected result in the Thonny shell, once the board answers:
Electrochemical Gas Sensor - ATtiny Bridge Board Example
Sensor initialized successfully!
Sensor reading: 0.29653 PPM
Sensor reading: 0.32569 PPM
Sensor reading: 0.32431 PPM
Sensor reading: 0.32453 PPM
Then a line every 2.5 seconds: Sensor reading: , the concentration in ppm
with five decimals, and PPM. A result below zero is printed as 0.00000.
Functions used
ElectrochemicalGasSensor(sensor_type, i2c=None, adc_addr=0x49, config_pin=None)returns ElectrochemicalGasSensorCreates the sensor object. With adc_addr from 0x30 to 0x37, begin() talks to the board through its ATtiny404 bridge; this example passes 0x30, the board's default address.
ReturnsThe sensor object.
Parameters
| Parameter | Type | Description |
|---|---|---|
sensor_type | SensorConfig | The cell's preset. For this board's SGX-4CO cell the module's preset is SENSOR_CO. |
i2c | machine.I2C | An initialised I2C bus. 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_addr | int | The I2C address. Default 0x49. From 0x30 to 0x37 the module uses the bridge. |
config_pin | int or None | A 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 boolAt a bridge address, checks that the bridge answers, sends it the ADC gain and data rate from the preset, then the front end's configuration. A bus error is retried until a 500 ms timeout for each step.
ReturnsTrue if every step succeeded, False otherwise.
getPPM()returns floatHas the bridge make one ADC conversion, takes off the internal zero and adds the zero calibration, then converts the cell current to ppm with the preset's sensitivity.
ReturnsThe gas concentration in ppm; 0.0 when the result would be negative.
getPPB()returns floatThe same measurement as getPPM(), in parts per billion. The example shows it as a commented-out alternative.
ReturnsgetPPM() multiplied by 1000.
Putting it together
Open the I2C bus, create the object with SENSOR_CO and adc_addr=0x30, call
begin() once and check it, then call getPPM() in your loop. A second board
on the same bus needs a different address on its switches and its own object.