pi_weather.core.sensors.stcc4.handler module

Logic to handle and manage the STCC4 sensor

class pi_weather.core.sensors.stcc4.handler.STCC4[source]

Bases: object

Base class for STCC4 CO2 sensor

__init__()[source]

C-tor init function

Return type:

None

calculation_crc(data)[source]

Calculate the CRC (Cyclic Redundancy Check) for input data Data words are succeeded by an 8-bit checksum (denoted as Cyclic Redundancy Check (CRC))

Parameters:

data (List | Tuple) – List or tuple of 16-bit integers

Return type:

int

Returns:

Calculated CRC value

get_product_id()[source]

Get the sensor ID

Return type:

int

Returns:

Sensor ID as bytes if successful, None otherwise

start_measurement()[source]

Start continuous measurement

Return type:

bool

Returns:

True if successful, False otherwise

stop_measurement()[source]

Stop continuous measurement

Return type:

bool

Returns:

True if successful, False otherwise

get_measurement()[source]

Read measurement data

Returns:

Tuple of (co2_concentration, temperature, humidity, sensor_status).

Return type:

Dict[str, int | float] | None

set_rht_compensation(temperature, humidity)[source]

Set temperature and humidity compensation

Parameters:
  • temperature (int) – Temperature compensation value, range of 10 to 40 degrees Celsius.

  • humidity (int) – Humidity compensation value, range of 20 to 80 percent relative humidity.

Return type:

bool

Returns:

True if successful, False otherwise

set_pressure_compensation(pressure)[source]

Set pressure compensation

Parameters:

pressure (int) – Pressure compensation value, range of 400 to 1100 hPa

Return type:

bool

Returns:

True if successful, False otherwise

single_measurement()[source]

Perform a single shot measurement

Return type:

bool

Returns:

True if successful, False otherwise

fall_asleep()[source]

Put the sensor into sleep mode

Return type:

bool

Returns:

True if successful, False otherwise

wakeup()[source]

Wake up the sensor from sleep mode

Return type:

bool

Returns:

True if successful, False otherwise

soft_reset()[source]

Perform a soft reset of the sensor

Return type:

bool

Returns:

True if successful, False otherwise

factory_reset()[source]

Perform a factory reset of the sensor

Return type:

bool

Returns:

True if successful, False otherwise

enable_testing_mode()[source]

Enable testing mode

Return type:

bool

Returns:

True if successful, False otherwise

disable_testing_mode()[source]

Disable testing mode

Return type:

bool

Returns:

True if successful, False otherwise

forced_recalibration(target_ppm)[source]

Perform forced recalibration

Parameters:

target_ppm (int) – Target PPM value for recalibration, must be between 0 and 32000 ppm.

Return type:

int | None

Returns:

Correction value if successful, None otherwise

class pi_weather.core.sensors.stcc4.handler.STCC4I2C(i2c_addr=100, bus=3)[source]

Bases: STCC4

STCC4I2C class Use the I2C protocol to drive the STCC4 sensor

Parameters:
__init__(i2c_addr=100, bus=3)[source]

C-tor init function

Parameters:
  • i2c_addr (int) – I2C device address

  • bus (int) – I2C bus identifier

Return type:

None

_write_cmd16(cmd)[source]

Write a 16-bit command to the sensor

Parameters:

cmd (int) – Command to write

Return type:

bool

Returns:

True if successful, False otherwise

_write_cmd8(cmd)[source]

Write an 8-bit command to the sensor

Parameters:

cmd (int) – Command to write

Return type:

bool

Returns:

True if successful, False otherwise

_write_data(cmd, data)[source]

Write data to the sensor

Parameters:
  • cmd (int) – Command to write before data

  • data (List | Tuple) – List or tuple of 16-bit integers to write

Return type:

bool

Returns:

True if successful, False otherwise

_read_data(cmd, length)[source]

Read data from the sensor

Parameters:
  • cmd (int) – Command to write before reading

  • length (int) – Number of bytes to read

Return type:

bytes | None

Returns:

Read bytes if successful, None otherwise

get_product_id()[source]

Function retrieving and returning the sensor product ID

Returns:

Sensor product ID

Return type:

int

start_measurement()[source]

Function to start measurements

Starts continuous measurement with 1s sampling interval. Note that the sensor and the microcontroller are subject to clock tolerances. The effective sampling interval is 1s +/- 150 ms.

Returns:

True if successful, False otherwise

Return type:

bool

stop_measurement()[source]

Function to stop continuous measurements

The stop_continuous_measurement command will finish the currently running measurement before returning to idle mode. During the execution time, the sensor will not acknowledge its I2C address nor accept commands.

Returns:

True if successful, False otherwise

Return type:

bool

get_measurement(force_sampling_sleep=False)[source]

Function to get instantaneous measurements

Parameters:

force_sampling_sleep (bool) – Bool to force a sampling sleep (see constants.py)

Returns:

Tuple with CO2 concentration, temperature, humidity and sensor status

Return type:

Dict[str, int | float] | None

set_rht_compensation(temperature, humidity)[source]

Function to set relative humidity + temperature compensation values

Parameters:
  • temperature (float) – External temperature (T) compensation value

  • humidity (float) – External relative humidity (RH) compensation value

Returns:

True if command was successful, False otherwise

Return type:

bool

set_pressure_compensation(pressure)[source]

Function to set pressure compensation to STCC4 sensor

Parameters:

pressure (int) – External pressure (P) compensation value (int in hPa)

Returns:

True if command was successful, False otherwise

Return type:

bool

single_measurement()[source]

Function to perform a single-short measurement

The measure_single_shot command conducts an on-demand measurement of CO2 gas concentration.

Returns:

True if command was successful, False otherwise

Return type:

bool

fall_asleep()[source]

Function to make the sensor fall asleep

The enter_sleep_mode command sets the sensor from idle to sleep mode through the I2C interface. The written relative humidity, temperature, pressure compensation values and ASC state are retained while in sleep mode.

Returns:

True if command was successful, False otherwise

Return type:

bool

wakeup()[source]

Function to wake up the sensor

The exit_sleep_mode command wakes the sensor up from sleep mode to idle mode upon receiving its I2C address, a write data direction bit and a payload byte 0x00.

Returns:

True if command was successful, False otherwise

Return type:

bool

soft_reset()[source]

Function to perform a soft reset

The perform_soft_reset command triggers a soft reset of the sensor through the I2C general call reset as implemented according to the NXP I2C-bus specification and user manual

Returns:

True if command was successful, False otherwise

Return type:

bool

factory_reset()[source]

Function to perform a factory reset

The perform_factory_reset command resets the FRC and ASC algorithm history :return: True if command was successful, False otherwise

Return type:

bool

enable_testing_mode()[source]

Function to enable testing mode :return: Nothing

Return type:

bool

disable_testing_mode()[source]

Function to disable testing mode :return: Nothing

Return type:

bool

forced_recalibration(target_ppm)[source]

Function to forced recalibration

The perform_forced_recalibration command (FRC) is used to correct the sensor’s CO2 concentration output with an externally provided target CO2 concentration.

Ensure the sensor reading and environmental conditions, including CO2 concentration, are stable for the duration of the recommended operation sequence. See Section 3.5 for the signal output and input conversion.

Parameters:

target_ppm (int) – Target PPM

Returns:

Applied FRC correction

Return type:

int | None