Calibrate the zero point
What this example shows
The electrochemical-calibrateSensor.py example adds a voltage offset to every
reading with setCustomZeroCalibration(). The module reports any negative
result as 0, so in air with none of the target gas you adjust
CUSTOM_CALIBRATION until the reading is just barely 0 ppb, as the example's
comment describes. It then prints a reading in ppb (parts per billion) every
2.5 seconds.
The example creates the sensor at adc_addr=0x49 with config_pin=32 for
LMPEN. It opens I2C bus 0 with SCL on pin 22 and SDA on pin 21; change
those pin numbers to your controller's I2C pins if they differ. At 0x49 the
module talks to the ADS1115 and the LMP91000 directly, not through the board's
ATtiny404 bridge. See the
library overview
for how the address decides this.
The example passes SENSOR_O3, the module's preset for an ozone cell. For a
nitric oxide reading, use SENSOR_NO in both places (the import line and
the ElectrochemicalGasSensor(...) line). SENSOR_NO is the preset for this
board's SGX-4NO-250 cell: 400 nA per ppm, a 120 kΩ amplifier gain and a
positive 12% bias.
The example code
The listing is the module's file at the pinned commit. Only comment lines are left out: the header line that names another product's store page, and the connecting-diagram line that names an old board.
# 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
Examples/electrochemical-calibrateSensor.py at commit 623e1e6
Expected result, with SENSOR_NO (readings in air with no NO; yours will
differ). The CUSTOM_CALIBRATION value these readings were taken with is not
recorded, so they may differ from what the listing's 0 gives: they show the
shape of the output, and your numbers depend on the offset you set.
Electrochemical Gas Sensor - Calibration Example
Sensor initialized successfully!
Sensor reading: 6.04131 PPB
Sensor reading: 6.16508 PPB
Sensor reading: 6.27205 PPB
Sensor reading: 5.68221 PPB
A Sensor reading: line comes every 2.5 seconds, with
the concentration in ppb to five decimals and PPB at the end. If begin()
fails, the example prints ERROR: Can't init the sensor! Check connections!
and stays in a loop.
Functions used
I2C(0, scl=Pin(22), sda=Pin(21))returns I2CCreates hardware I2C bus 0 on the given SCL and SDA pins. machine.I2C and machine.Pin come with MicroPython and are not part of the Soldered module (see docs.micropython.org, machine.I2C and machine.Pin).
ReturnsThe I2C bus object you pass to the sensor.
Parameters
| Type | Name | Description |
|---|---|---|
int | id | The hardware I2C bus, 0 in the example. |
Pin | scl | The clock pin, Pin(22) in the example. |
Pin | sda | The data pin, Pin(21) in the example. |
ElectrochemicalGasSensor(sensor_type, i2c=None, adc_addr=0x49, config_pin=None)returns ElectrochemicalGasSensorCreates the sensor object. Nothing is sent over I2C until you call begin(). With i2c=None the module opens a bus itself on the boards it recognises, including an ESP32, where it opens I2C(0, scl=Pin(22), sda=Pin(21)), and an ESP8266, where it opens I2C(scl=Pin(5), sda=Pin(4)). On a board it does not recognise it raises an exception.
ReturnsThe sensor object.
Parameters
| Type | Name | Description |
|---|---|---|
SensorConfig | sensor_type | The cell preset, SENSOR_O3 in the example. SENSOR_NO is the one for this board's cell. The module also has SENSOR_CO, SENSOR_NO2, SENSOR_SO2, SENSOR_H2S, SENSOR_NH3 and SENSOR_CL2. |
I2C | i2c | The I2C bus the board is on. |
int | adc_addr | The I2C address, 0x49 in the example. For 0x30 to 0x37 the module talks to the board's ATtiny404 bridge; for any other address it talks to the ADS1115 at that address and to the LMP91000 directly. |
int | config_pin | A GPIO for LMPEN, 32 in the example. The module holds it high and pulls it low only while it configures the LMP91000. Unused at addresses 0x30 to 0x37. |
sensor.begin()returns boolFor an address from 0x30 to 0x37 it checks that the board's bridge answers and sends the ADC and front-end settings through it, waiting up to 500 ms for each step. For any other address it checks that the ADS1115 answers at adc_addr in an I2C scan, sets the preset's ADC gain and the slowest data rate, then configures the LMP91000 at 0x48 (gain, load, reference, internal zero, bias and mode), pulling config_pin low only during that configuration when one is given.
ReturnsTrue when every step succeeded, False otherwise.
sensor.setCustomZeroCalibration(calibration)returns NoneSets the zero calibration of the sensor's preset: a voltage that getPPM() adds to every reading before it converts it. It changes the preset object itself, so every sensor created with the same preset uses the new value.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
float | calibration | The offset in volts, CUSTOM_CALIBRATION (0) in the example. |
sensor.getPPB()returns floatTakes one reading with getPPM() and multiplies it by 1000. getPPM() reads ADC channel 0 (at 0x30 to 0x37, the bridge runs the conversion), subtracts the internal zero (2.5 V times the preset's internal zero percentage), adds the zero calibration, then divides by the amplifier gain and by the preset's nA per ppm.
ReturnsThe gas concentration in ppb. A negative result is returned as 0.0.
sensor.getPPM()returns floatThe alternative the example's comment offers: the same reading in ppm.
ReturnsThe gas concentration in ppm. A negative result is returned as 0.0.
Putting it together
begin() configures the front end once, then setCustomZeroCalibration()
sets the offset before the first reading. Change CUSTOM_CALIBRATION, run the
example again in air with none of the target gas, and repeat until the
readings are just barely 0 ppb.