Zero-point calibration
What this example shows
The electrochemical-calibrateSensor.py example adds a fixed voltage offset,
CUSTOM_CALIBRATION, to every reading, then prints readings in PPB every 2.5
seconds. It creates the sensor with adc_addr=0x49 and config_pin=32.
The example's own comment says how to use the offset: with none of the target
gas present, adjust CUSTOM_CALIBRATION until the reading is just above 0
PPB. It starts at 0, which adds nothing.
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 to pin 32 on this board, whatever the
example's comments say: the board holds it low itself.
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
Examples/electrochemical-calibrateSensor.py at commit 623e1e6
What this board prints with the example as written has not been measured yet.
When this board was tested over Qwiic, an I2C scan found only one address,
0x30, and begin() failed for a sensor created at 0x49, the address this
example passes. If begin() fails, the example prints
ERROR: Can't init the sensor! Check connections! after its title line and
stops there.
When begin() succeeds, the shell shows:
Electrochemical Gas Sensor - Calibration Example
Sensor initialized successfully!
After that, a line Sensor reading: followed by a value with five decimals
and PPB arrives every 2.5 seconds.
Functions used
I2C(id, scl, sda)returns I2CCreates 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
| 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 to the board until you call begin(). The example passes the sensor configuration, the bus, adc_addr=0x49 and config_pin=32.
ReturnsThe sensor object.
Parameters
| Type | Name | Description |
|---|---|---|
SensorConfig | sensor_type | The front end and conversion settings, such as SENSOR_O3. The presets are defined in ElectrochemicalGasSensor.py. |
I2C | i2c | The 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. |
int | adc_addr | The address the module talks to, 0x49 by default and in this example. An address from 0x30 to 0x37 makes begin() use the bridge commands; any other address is taken as the ADS1115's own address. |
int | config_pin | A GPIO pin the module holds high and pulls low while it writes the LMP91000 settings, 32 in this example. None by default; not used for an address from 0x30 to 0x37. |
sensor.begin()returns boolConfigures the ADC and the LMP91000 from the sensor configuration. For an adc_addr from 0x30 to 0x37 it checks that the board's bridge answers and sends it the ADC gain, the slowest ADC data rate and the LMP91000 settings, retrying each command for up to 500 ms. For any other address it sets up the ADS1115 at that address with the same gain and data rate and writes the LMP91000 settings directly, pulling config_pin low while it does when one is given.
ReturnsTrue when every step succeeded, False otherwise.
sensor.setCustomZeroCalibration(calibration)returns NoneSets the zero-point offset, in volts, that getPPM() adds to the measured voltage. It writes the value into the sensor configuration object you passed to the constructor, SENSOR_O3 in the example.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
float | calibration | The offset in volts, CUSTOM_CALIBRATION in the example. |
sensor.getPPB()returns floatTakes one reading and returns it in parts per billion: the getPPM() value multiplied by 1000. getPPM() subtracts the internal zero (a share of the board's 2.5 V reference), adds the zero-point offset, divides by the TIA gain and by the configuration's nanoamperes per PPM, and returns 0.0 for a negative result.
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; its internal_zero_calibration field sets
the same offset when the configuration is created.