Calibrate the zero point
What this example shows
The library's electrochemical-calibrateSensor.py example adds a fixed voltage offset, CUSTOM_CALIBRATION, to every ADC reading before it is turned into a concentration. In air with none of the target gas, adjust that value until the reading is just barely 0.
The example creates the sensor with the ozone cell preset, SENSOR_O3, at adc_addr=0x49 with config_pin=32. SENSOR_SO2 is the library's preset for this board's SO2 cell: change SENSOR_O3 to SENSOR_SO2 in the import line and in the line that creates sensor to get SO2 values. The script creates the I2C bus on GPIO 22 (SCL) and GPIO 21 (SDA); change those numbers if your board uses other pins.
On this board the LMP91000 and ADS1115 sit on the board's own bus 2, and your controller reaches them through the board's address on the Qwiic bus: 0x30 as shipped, 0x30 to 0x37 with the ADDRESS switch. The example's adc_addr=0x49 talks to an ADS1115 directly. Pass the board's address instead, for example sensor = ElectrochemicalGasSensor(SENSOR_SO2, i2c, adc_addr=0x30). Where the connecting diagram says LMPEN goes to GPIO 32, on this board LMPEN is already pulled to GND by a 10 kΩ resistor and also runs to the on-board microcontroller, and at the board's addresses the module does not use config_pin (see Hardware Details).
The listing is the library's file at the pinned commit, apart from two comment-only lines, which link to another Soldered product or name a controller board in the connecting diagram, and are left out.
The example code
# FILE: electrochemical-calibrateSensor.py
# AUTHOR: Fran Fodor @ Soldered
# BRIEF: Sensor zero-point calibration example.
# LAST UPDATED: 2026-05-21
# Connecting diagram:
#
# Qwiic------------------------>Qwiic
# LMPEN------------------------>32 (GPIO pin, required for configuration)
from machine import I2C, Pin
import time
from ElectrochemicalGasSensor import ElectrochemicalGasSensor, SENSOR_O3
# This value is added to the voltage read from the ADC.
# In an environment with 0 of the target gas, the reading after calibration
# should be just barely 0 PPB — adjust this value until that is the case.
CUSTOM_CALIBRATION = 0
# Initialize I2C
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# Custom ADC address (0x49 default) and GPIO pin for LMPEN
sensor = ElectrochemicalGasSensor(SENSOR_O3, i2c, adc_addr=0x49, config_pin=32)
# -------------------------------------------------------------------------
# Setup
# -------------------------------------------------------------------------
print("Electrochemical Gas Sensor - Calibration Example")
if not sensor.begin():
print("ERROR: Can't init the sensor! Check connections!")
while True:
time.sleep_ms(100)
# Apply the zero-point calibration offset
sensor.setCustomZeroCalibration(CUSTOM_CALIBRATION)
print("Sensor initialized successfully!")
# -------------------------------------------------------------------------
# Main loop
# -------------------------------------------------------------------------
while True:
reading = sensor.getPPB()
# O3 is typically measured in PPB
# Switch to getPPM() if PPM is more relevant for your use case
print("Sensor reading: {:.5f} PPB".format(reading))
time.sleep_ms(2500)
🔗Open the complete example
electrochemical-calibrateSensor.py at the pinned commit
Expected result:
Electrochemical Gas Sensor - Calibration Example
Sensor initialized successfully!
Then a Sensor reading: line in ppb follows every 2.5 seconds.
Functions used
ElectrochemicalGasSensor(sensor_type, i2c=None, adc_addr=0x49, config_pin=None)returns ElectrochemicalGasSensorCreates the sensor object from a cell preset, an I2C object, an address and an optional enable pin. The example passes adc_addr=0x49 and config_pin=32.
ReturnsThe sensor object.
Parameters
| Parameter | Type | Description |
|---|---|---|
sensor_type | SensorConfig | The cell preset. SENSOR_SO2 is the preset for this board's cell. |
i2c | I2C | An initialised machine.I2C object. |
adc_addr | int | The address the module talks to. 0x30 to 0x37 selects the module's bridge mode, which talks to the board's on-board microcontroller; any other value talks to an ADS1115 directly at that address. Default 0x49. |
config_pin | int | GPIO for the LMP91000's enable line. Not used at addresses 0x30 to 0x37. Default None. |
begin()returns boolChecks that the board answers and sends the ADC and LMP91000 settings from the preset to it.
ReturnsTrue when the board answered and took every setting, False otherwise.
setCustomZeroCalibration(calibration)returns NoneSets the voltage offset that is added to every reading before it is turned into a concentration. It replaces the preset's own zero calibration value, which is 0 for SENSOR_SO2.
ReturnsNothing.
Parameters
| Parameter | Type | Description |
|---|---|---|
calibration | float | The offset in volts. |
getPPB()returns floatHas the board take one ADC reading and returns the concentration in parts per billion, including the zero calibration offset. A result below zero is returned as 0.
ReturnsGas concentration in ppb.
getPPM()returns floatThe same reading in ppm. The example names it in a comment as an alternative.
ReturnsGas concentration in ppm.
Putting it together
Put the board in air without SO2 and run the script with CUSTOM_CALIBRATION = 0. Change the value until the reading is just barely 0, then use the same value with setCustomZeroCalibration() in your own script.