Skip to main content

Step through a heater profile in sequential mode

What this example shows​

In sequential mode the sensor steps through a heater profile on its own, sleeping between the measurements. The example sets a ten-step profile (heater temperatures from 100 to 320 °C, 150 ms each) and a 250 ms sleep between steps. It then prints every new measurement with the profile step it was measured at.

The example creates the sensor with BME690(), so on the esp32 and esp8266 ports it uses I2C(0) with SDA on pin 21 and SCL on pin 22, at address 0x76.

The example code​

# FILE: bme690-sequentialMode.py
# AUTHOR: Josip Simun Kuci @ Soldered
# BRIEF: Run the BME690 in sequential mode, where the sensor steps through a
# heater profile on its own, sleeping between the measurements
# WORKS WITH: BME690 breakout board: solde.red/333411
# LAST UPDATED: 2026-09-16

from bme690 import (
BME690,
BME69X_ERROR,
BME69X_ODR_250_MS,
BME69X_SEQUENTIAL_MODE,
)
import time

# Heater temperature profile in degrees Celsius.
HEATER_TEMP = [320, 100, 100, 100, 200, 200, 200, 320, 320, 320]

# Heating duration profile in milliseconds.
HEATER_DUR = [150, 150, 150, 150, 150, 150, 150, 150, 150, 150]

sensor = BME690()

sensor.set_tph()

# Sleep duration between two measurements of the profile.
sensor.set_seq_sleep(BME69X_ODR_250_MS)

sensor.set_heater_prof(HEATER_TEMP, HEATER_DUR)
sensor.set_op_mode(BME69X_SEQUENTIAL_MODE)

if sensor.check_status() == BME69X_ERROR:
raise Exception("BME690 setup failed: " + sensor.status_string())

print(
"Timestamp(ms), Temperature(C), Pressure(Pa), Humidity(%), "
"Gas resistance(Ohm), Status, Gas index"
)

while True:
if sensor.fetch_data():
fields_left = 1

while fields_left:
data, fields_left = sensor.get_data()

print(
"{}, {:.2f}, {:.2f}, {:.2f}, {:.2f}, 0x{:02x}, {}".format(
time.ticks_ms(),
data.temperature,
data.pressure,
data.humidity,
data.gas_resistance,
data.status,
data.gas_index,
)
)

time.sleep_ms(100)

🔗Open the complete example

Examples/bme690-sequentialMode.py at commit 91a07b5

→

Expected result:

ShellMicroPython
Timestamp(ms), Temperature(C), Pressure(Pa), Humidity(%), Gas resistance(Ohm), Status, Gas index

Each new field then prints one row: the millisecond counter, temperature in °C, pressure in Pa, humidity in % r.H. and gas resistance in Ω (each to two decimals), the status byte in hex and the heater profile step, from 0 to 9. 0xb0 in the status means new data, a valid gas measurement and a stable heater.

Functions used​

BME690(i2c=None, address=BME69X_I2C_ADDR_LOW, amb_temp=25)returns BME690

Creates the sensor object. It soft-resets the sensor, checks its chip ID (0x61) and reads the calibration data. It raises an exception when the sensor does not answer or another chip is at the address; every other function records its result in the status instead of raising.

ReturnsThe sensor object.

Parameters

TypeNameDescription
I2Ci2cA ready machine.I2C object. Left out, the module opens I2C(0) with SCL on pin 22 and SDA on pin 21 on the esp32 and esp8266 ports and one Soldered board firmware, and raises an exception on any other port.
intaddressThe I2C address: BME69X_I2C_ADDR_LOW (0x76, the default) or BME69X_I2C_ADDR_HIGH (0x77).
intamb_tempAmbient temperature in °C, used to work out the heater setting. 25 by default.
sensor.set_tph(os_temp=BME69X_OS_2X, os_pres=BME69X_OS_16X, os_hum=BME69X_OS_1X)returns None

Sets the oversampling for temperature, pressure and humidity. Called without arguments, as here, it sets the defaults of the Arduino library.

ReturnsNothing. The result is in the status.

Parameters

TypeNameDescription
intos_tempTemperature oversampling, BME69X_OS_NONE to BME69X_OS_16X.
intos_presPressure oversampling, BME69X_OS_NONE to BME69X_OS_16X.
intos_humHumidity oversampling, BME69X_OS_NONE to BME69X_OS_16X.
sensor.set_seq_sleep(odr=BME69X_ODR_0_59_MS)returns None

Sets how long the sensor sleeps between two measurements in sequential mode.

ReturnsNothing. The result is in the status.

Parameters

TypeNameDescription
intodrBME69X_ODR_0_59_MS, BME69X_ODR_10_MS, BME69X_ODR_20_MS, BME69X_ODR_62_5_MS, BME69X_ODR_125_MS, BME69X_ODR_250_MS, BME69X_ODR_500_MS, BME69X_ODR_1000_MS or BME69X_ODR_NONE. The example uses BME69X_ODR_250_MS.
sensor.set_heater_prof(temp, dur, shared_heatr_dur=None)returns None

Sets the gas heater profile and switches the heater on. With a list of temperatures and a list of durations and no shared duration, as here, it writes a sequential-mode profile, one step per list entry. Temperatures above 400 °C are capped at 400 °C.

ReturnsNothing. The result is in the status.

Parameters

TypeNameDescription
listtempHeater temperature of each step in °C. The example uses HEATER_TEMP.
listdurHeating duration of each step in ms. The example uses HEATER_DUR.
intshared_heatr_durParallel mode only; leave it out in sequential mode.
sensor.set_op_mode(op_mode)returns None

Puts the sensor to sleep, then sets the requested mode. With BME69X_SEQUENTIAL_MODE the sensor starts working through the profile on its own. The mode is remembered for fetch_data() and get_data().

ReturnsNothing. The result is in the status.

Parameters

TypeNameDescription
intop_modeBME69X_SLEEP_MODE, BME69X_FORCED_MODE, BME69X_PARALLEL_MODE or BME69X_SEQUENTIAL_MODE.
sensor.check_status()returns int

Sums up the status the last function left behind.

ReturnsBME69X_ERROR (-1) after an error, BME69X_WARNING (1) after a warning, BME69X_OK (0) otherwise.

sensor.status_string()returns str

Describes the current status code in a few words, such as Communication failure or No new data.

ReturnsThe description, an empty string when the status is OK.

sensor.fetch_data()returns int

Reads the sensor's three result fields into the module's buffer and sorts them so the oldest new sample comes first. When nothing new is there, the status reads No new data.

ReturnsThe number of new data fields, 0 when there are none.

sensor.get_data()returns tuple

Hands out the next new field from the buffer as a BME690Data object with temperature (°C), pressure (Pa), humidity (% r.H.), gas_resistance (Ω), status, gas_index (the profile step) and meas_index.

Returns(data, fields_left): the BME690Data, or None when there is no new data, and how many new fields are left after this one.

Putting it together​

After set_tph(), set_seq_sleep() and set_heater_prof(), the call set_op_mode(BME69X_SEQUENTIAL_MODE) leaves the sensor running through the profile by itself. Every 100 ms the loop asks fetch_data() for new fields and reads them one by one with get_data() until fields_left reaches 0. The gas_index column tells you which of the ten heater steps a row was measured at.