Skip to main content

Read the sensor

What this example shows​

The electrochemical-bridgeBoard.py example starts the board through its ATtiny404 at 0x30, sends the analog front end its settings, and prints a reading every 2.5 seconds. Your controller only ever talks to the ATtiny404; it forwards the settings to the LMP91000 and reads the ADS1115 for you.

The example opens I2C bus 0 with SCL on pin 22 and SDA on pin 21. Change them to the pins your controller's Qwiic connector or your wiring uses. You do not need to wire LMPEN: the board holds it low itself. Where the example's comments mention address jumpers on the back of the board, this board uses the three-position ADDRESS switch on its top side instead.

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

→

Expected result:

ShellMicroPython
Electrochemical Gas Sensor - ATtiny Bridge Board Example
Sensor initialized successfully!

After that, a line Sensor reading: followed by a value with five decimals and PPM arrives every 2.5 seconds. If the board does not answer, the example prints ERROR: Can't init the sensor! Check connections and jumper address! and stops there.

Functions used​

I2C(id, scl, sda)returns I2C

Creates the I2C bus object from MicroPython's machine module, which the sensor object uses. The example uses bus 0 with SCL on Pin(22) and SDA on Pin(21). I2C and Pin come with MicroPython and are not part of this library.

ReturnsThe I2C bus object.

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 the sensor object. Nothing is sent to the board until you call begin(). An adc_addr from 0x30 to 0x37 tells the module this is a board with the ATtiny404 bridge, and config_pin is then ignored.

ReturnsThe sensor object.

Parameters

TypeNameDescription
SensorConfigsensor_typeThe front end and conversion settings, such as SENSOR_O3. The presets are defined in ElectrochemicalGasSensor.py.
I2Ci2cThe bus to use. When left out, the module picks pins only on boards it recognises (ESP32: bus 0, SCL 22, SDA 21; ESP8266: SCL 5, SDA 4) and raises an exception otherwise.
intadc_addrThe address the module talks to, 0x49 by default and 0x30 in this example. An address from 0x30 to 0x37 makes begin() use the bridge commands, matching the board's ADDRESS switch.
intconfig_pinA GPIO pin the module holds high and pulls low while it writes the LMP91000 settings. Not used for an address from 0x30 to 0x37.
sensor.begin()returns bool

Checks that the bridge answers, sends it the ADC gain and the slowest ADC data rate, then sends the LMP91000 settings from the sensor configuration. Each command to the bridge is retried for up to 500 ms.

ReturnsTrue when every step succeeded, False otherwise.

sensor.getPPM()returns float

Asks the bridge for one ADC conversion and turns the voltage into a concentration: it subtracts the internal zero (a share of the board's 2.5 V reference), adds the configuration's zero calibration, divides by the TIA gain to get the cell current, then divides by the configuration's nanoamperes per PPM. A negative result is returned as 0.0.

ReturnsThe concentration in PPM, calculated with the sensor configuration you passed to the constructor.

sensor.getPPB()returns float

The commented-out alternative in the example: the same reading as getPPM(), multiplied by 1000.

ReturnsThe concentration in PPB.

Putting it together​

SENSOR_O3 is the preset for an SGX-403-20 ozone cell. The module has no preset for this board's SGX-4OX-ROHS oxygen cell yet, so the value the example prints is calculated with the ozone cell's settings. The custom configuration page shows how to write your own SensorConfig, with the bias and reference settings for this cell.

After power-up the cell can take up to 15 minutes to settle, so let it run before you trust a reading.

Up to eight boards share one bus: give each one its own address with the ADDRESS switch and create one ElectrochemicalGasSensor per address, from 0x30 to 0x37.