Skip to main content

Read the NO2 concentration

What this example shows​

The module's electrochemical-bridgeBoard.py example creates the sensor at the board's I2C address, starts it, and prints the gas concentration in ppm every 2.5 seconds. An adc_addr from 0x30 to 0x37 tells the module that it is talking to the board's ATtiny404, which runs the LMP91000 and the ADS1115 for you.

The example creates the sensor with the ozone preset, SENSOR_O3. Change SENSOR_O3 to SENSOR_NO2 in both places, the import line and the line that creates the sensor: SENSOR_NO2 is the module's preset for the SGX-4NO2 cell on this board. The example opens I2C bus 0 with SCL on pin 22 and SDA on pin 21; change them to match your controller. If you moved the ADDRESS switches, change 0x30 to the address they set.

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)

🔗Open the complete example

Examples/electrochemical-bridgeBoard.py at commit 623e1e6

→

The comment at the top of the example says LMPEN is hardwired to GND. On this board LMPEN is the LMP91000's enable input and is also wired to the ATtiny404, as Hardware Details shows. Either way you connect nothing to it: at adc_addr 0x30 to 0x37 the module does not use config_pin.

Expected result:

ShellMicroPython
Electrochemical Gas Sensor - ATtiny Bridge Board Example
Sensor initialized successfully!
Sensor reading: 0.01433 PPM
Sensor reading: 0.01325 PPM
Sensor reading: 0.01431 PPM
Sensor reading: 0.01395 PPM

A new Sensor reading: line follows every 2.5 seconds, with the NO2 concentration in ppm to five decimals. If the board does not answer, it prints ERROR: Can't init the sensor! Check connections and jumper address! and waits in a loop.

Functions used​

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

Creates the sensor object. Nothing is sent to the board until you call begin(). The address decides how begin() talks to the board: at 0x30 to 0x37 it sends its commands to the ATtiny404, and at 0x48 to 0x4B (0x49 by default) it addresses the ADS1115 at adc_addr and the LMP91000 directly.

ReturnsThe sensor object.

Parameters

TypeNameDescription
SensorConfigsensor_typeThe cell's preset. Use SENSOR_NO2 for this board's SGX-4NO2 cell.
I2Ci2cThe I2C bus. With None, the module picks the pins by the port MicroPython reports: I2C bus 0 on pins 22 (SCL) and 21 (SDA) on the ESP32 port, scl=Pin(5), sda=Pin(4) on the ESP8266 port. On a port it does not recognise, it raises Board not recognized, please pass an I2C object manually.
intadc_addrThe board's I2C address. Use 0x30 to 0x37, as set by the ADDRESS switches; 0x30 as shipped.
intconfig_pinGPIO for the LMP91000 enable pin. Not used at addresses 0x30 to 0x37; leave it out.
sensor.begin()returns bool

Checks that the board answers, then sends it the ADC gain and data rate and the LMP91000 configuration from the preset. Each step retries until the board answers or 500 ms pass. Call it once before reading.

ReturnsTrue when every step succeeded, False otherwise.

sensor.getPPM()returns float

Asks the board for a new ADC reading and turns it into a gas concentration: the voltage minus the internal zero, plus the calibration offset, divided by the TIA gain and by the cell's sensitivity in the preset. A negative result is returned as 0.0.

ReturnsThe gas concentration in ppm.

sensor.getPPB()returns float

The same reading as getPPM(), multiplied by 1000. The example mentions it in a comment as the line to use when parts per billion suit your sensor better.

ReturnsThe gas concentration in ppb.

Putting it together​

The example creates the I2C bus first and passes it to the sensor, so it does not depend on the port's default pins. If begin() returns False, it prints the error and stays in a loop. Otherwise each pass of the main loop calls getPPM() and prints the value with five decimals.