Qwiic_SCD4x_Py  2.0.0-1-gaedadef
Python for SFE Qwiic SCD4x
Loading...
Searching...
No Matches
qwiic_scd4x.QwiicSCD4x Class Reference
Inheritance diagram for qwiic_scd4x.QwiicSCD4x:

Public Member Functions

def __init__ (self, address=None, i2c_driver=None)
 Constructor. More...
 
def is_connected (self)
 Determines if this device is connected. More...
 
def begin (self, measBegin=True, autoCalibrate=True, skipStopPeriodicMeasurement=False, pollAndSetDeviceType=True)
 Initializes this device with default parameters. More...
 
def start_periodic_measurement (self)
 Start periodic measurements. More...
 
def stop_periodic_measurement (self, delayMillis=500)
 stop_periodic_measurement can be called before begin() if required Note that the sensor will only respond to other commands after waiting 500 ms after issuing the stop_periodic_measurement command. More...
 
def read_measurement (self)
 Get 9 bytes from SCD4x. More...
 
def get_co2 (self)
 Get the CO2 value. More...
 
def get_humidity (self)
 Get the humidity value. More...
 
def get_temperature (self)
 Get the temperature value. More...
 
def set_temperature_offset (self, offset, delayMillis=1)
 Set the temperature offset (C). More...
 
def get_temperature_offset (self)
 Get the temperature offset (C). More...
 
def set_sensor_altitude (self, altitude, delayMillis=1)
 Set the sensor altitude (metres above sea level). More...
 
def get_sensor_altitude (self)
 Get the sensor altitude (metres above sea level). More...
 
def set_ambient_pressure (self, pressure, delayMillis=1)
 Set the ambient pressure (Pa). More...
 
def perform_forced_recalibration (self, concentration)
 Perform forced recalibration. More...
 
def start_low_power_periodic_measurement (self)
 Start low power periodic measurements. More...
 
def get_data_ready_status (self)
 Returns true when data is available. More...
 
def persist_settings (self, delayMillis=800)
 Persist settings: copy settings (e.g. More...
 
def get_serial_number (self)
 Get the serial number of the sensor. More...
 
def convert_hex_to_ascii (self, digit)
 Convert a hex digit to its ASCII representation. More...
 
def perform_self_test (self)
 Perform self test. More...
 
def perform_factory_reset (self, delayMillis=1200)
 Peform factory reset. More...
 
def reinit (self, delayMillis=20)
 Re-initialize the sensor, load settings from EEPROM. More...
 
def measure_single_shot (self)
 SCD41 only. More...
 
def measure_single_shot_rht_only (self)
 On-demand measurement of relative humidity and temperature only. More...
 
def get_sensor_type (self)
 Get the sensor type. More...
 
def set_sensor_type (self, sensorType)
 Set the sensor type. More...
 
def get_feature_set_version (self)
 Save the feature set version/sensor type of the sensor. More...
 
def set_automatic_self_calibration_enabled (self, enabled, delayMillis=1)
 Enable/disable automatic self calibration. More...
 
def get_automatic_self_calibration_enabled (self)
 Check if automatic self calibration is enabled. More...
 
def compute_crc8 (self, data)
 Given a list of bytes, this calculate CRC8 for those bytes CRC is only calc'd on the data portion (two bytes) of the four bytes being sent From: http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html Tested with: http://www.sunshine2k.de/coding/javascript/crc/crc_js.html x^8+x^5+x^4+1 = 0x31. More...
 
def send_command (self, command, arguments=None)
 Sends a command along with arguments and CRC. More...
 
def read_register (self, registerAddress, delayMillis=1)
 Read a register from the sensor. More...
 

Public Attributes

 address
 

Static Public Attributes

 device_name = _DEFAULT_NAME
 
 available_addresses = _AVAILABLE_I2C_ADDRESS
 
int kComStartPeriodicMeasurement = 0x21b1
 
int kComReadMeasurement = 0xec05
 
int kComStopPeriodicMeasurement = 0x3f86
 
int kComSetTemperatureOffset = 0x241d
 
int kComGetTemperatureOffset = 0x2318
 
int kComSetSensorAltitude = 0x2427
 
int kComGetSensorAltitude = 0x2322
 
int kComSetAmbientPressure = 0xe000
 
int kComPerformForcedCalibration = 0x362f
 
int kComSetAutomaticSelfCalibrationEnabled = 0x2416
 
int kComGetAutomaticSelfCalibrationEnabled = 0x2313
 
int kComStartLowPowerPeriodicMeasurement = 0x21ac
 
int kComGetDataReadyStatus = 0xe4b8
 
int kComPersistSettings = 0x3615
 
int kComGetSerialNumber = 0x3682
 
int kComPerformSelfTest = 0x3639
 
int kComPerformFactoryReset = 0x3632
 
int kComReinit = 0x3646
 
int kComGetFeatureSetVersion = 0x202F
 
int kComMeasureSingleShot = 0x219d
 
int kComMeasureSingleShotRhtOnly = 0x2196
 
int kTypeSCD40 = 0
 
int kTypeSCD41 = 1
 
int kTypeSDC4xInvalid = 2
 

Properties

 connected = property(is_connected)
 

Constructor & Destructor Documentation

◆ __init__()

def qwiic_scd4x.QwiicSCD4x.__init__ (   self,
  address = None,
  i2c_driver = None 
)

Constructor.

Parameters
int,optionaladdress: The I2C address to use for the device If not provided, the default address is used
I2CDriver,optionali2c_driver: An existing i2c driver object If not provided, a driver object is created

Member Function Documentation

◆ begin()

def qwiic_scd4x.QwiicSCD4x.begin (   self,
  measBegin = True,
  autoCalibrate = True,
  skipStopPeriodicMeasurement = False,
  pollAndSetDeviceType = True 
)

Initializes this device with default parameters.

Returns
bool Returns True if successful, otherwise False

◆ compute_crc8()

def qwiic_scd4x.QwiicSCD4x.compute_crc8 (   self,
  data 
)

Given a list of bytes, this calculate CRC8 for those bytes CRC is only calc'd on the data portion (two bytes) of the four bytes being sent From: http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html Tested with: http://www.sunshine2k.de/coding/javascript/crc/crc_js.html x^8+x^5+x^4+1 = 0x31.

Parameters
listof int data: The data to compute the CRC for
Returns
int The computed CRC8 value

◆ convert_hex_to_ascii()

def qwiic_scd4x.QwiicSCD4x.convert_hex_to_ascii (   self,
  digit 
)

Convert a hex digit to its ASCII representation.

Parameters
intdigit: The hex digit to convert
Returns
str The ASCII representation of the hex digit

◆ get_automatic_self_calibration_enabled()

def qwiic_scd4x.QwiicSCD4x.get_automatic_self_calibration_enabled (   self)

Check if automatic self calibration is enabled.

See 3.7.3

Returns
True if enabled, otherwise False

◆ get_co2()

def qwiic_scd4x.QwiicSCD4x.get_co2 (   self)

Get the CO2 value.

Call read_measurement() first to update the value

Returns
int The CO2 value

◆ get_data_ready_status()

def qwiic_scd4x.QwiicSCD4x.get_data_ready_status (   self)

Returns true when data is available.

See 3.8.2

Returns
bool True if data is ready, otherwise False

◆ get_feature_set_version()

def qwiic_scd4x.QwiicSCD4x.get_feature_set_version (   self)

Save the feature set version/sensor type of the sensor.

Returns
bool True if successful, otherwise False

◆ get_humidity()

def qwiic_scd4x.QwiicSCD4x.get_humidity (   self)

Get the humidity value.

Call read_measurement() first to update the value

Returns
int The humidity value

◆ get_sensor_altitude()

def qwiic_scd4x.QwiicSCD4x.get_sensor_altitude (   self)

Get the sensor altitude (metres above sea level).

See 3.6.4

Returns
int The sensor altitude or None if unsuccessful

◆ get_sensor_type()

def qwiic_scd4x.QwiicSCD4x.get_sensor_type (   self)

Get the sensor type.

Allowable versions are kTypeSCD40, kTypeSCD41, and kTypeSDC4xInvalid

Returns
int The sensor type

◆ get_serial_number()

def qwiic_scd4x.QwiicSCD4x.get_serial_number (   self)

Get the serial number of the sensor.

Parameters
intserialNumber: The serial number of the sensor
Returns
str Serial Number if successful, otherwise None

◆ get_temperature()

def qwiic_scd4x.QwiicSCD4x.get_temperature (   self)

Get the temperature value.

Call read_measurement() first to update the value

Returns
int The temperature value

◆ get_temperature_offset()

def qwiic_scd4x.QwiicSCD4x.get_temperature_offset (   self)

Get the temperature offset (C).

See 3.6.2

Returns
int The temperature offset or None if unsuccessful

◆ is_connected()

def qwiic_scd4x.QwiicSCD4x.is_connected (   self)

Determines if this device is connected.

Returns
bool True if connected, otherwise False

◆ measure_single_shot()

def qwiic_scd4x.QwiicSCD4x.measure_single_shot (   self)

SCD41 only.

Request a single low-power measurement. Data will be ready in 5 seconds. See 3.10.1

In addition to periodic measurement modes, the SCD41 features a single shot measurement mode, i.e. allows for on-demand measurements. The typical communication sequence is as follows:

  1. The sensor is powered up.
  2. The I2C master sends a single shot command and waits for the indicated max. command duration time.
  3. The I2C master reads out data with the read measurement sequence (chapter 3.5.2).
  4. Steps 2-3 are repeated as required by the application.
Returns
bool True if successful, otherwise False

◆ measure_single_shot_rht_only()

def qwiic_scd4x.QwiicSCD4x.measure_single_shot_rht_only (   self)

On-demand measurement of relative humidity and temperature only.

SCD41 only. Data will be ready in 50ms

The sensor output is read using the read_measurement command (chapter 3.5.2). CO2 output is returned as 0 ppm.

Returns
bool True if successful, otherwise False

◆ perform_factory_reset()

def qwiic_scd4x.QwiicSCD4x.perform_factory_reset (   self,
  delayMillis = 1200 
)

Peform factory reset.

See 3.9.4 The perform_factory_reset command resets all configuration settings stored in the EEPROM and erases the FRC and ASC algorithm history.

Parameters
intdelayMillis: The delay in milliseconds to wait after performing the factory reset
Returns
bool True if successful, otherwise False

◆ perform_forced_recalibration()

def qwiic_scd4x.QwiicSCD4x.perform_forced_recalibration (   self,
  concentration 
)

Perform forced recalibration.

See 3.7.1 To successfully conduct an accurate forced recalibration, the following steps need to be carried out:

  1. Operate the SCD4x in the operation mode later used in normal sensor operation (periodic measurement, low power periodic measurement or single shot) for > 3 minutes in an environment with homogenous and constant CO2 concentration.
  2. Issue stop_periodic_measurement. Wait 500 ms for the stop command to complete.
  3. Subsequently issue the perform_forced_recalibration command and optionally read out the FRC correction (i.e. the magnitude of the correction) after waiting for 400 ms for the command to complete. A return value of 0xffff indicates that the forced recalibration has failed.
Parameters
intconcentration: The concentration to recalibrate to
Returns
bool True if successful, otherwise False

◆ perform_self_test()

def qwiic_scd4x.QwiicSCD4x.perform_self_test (   self)

Perform self test.

Takes 10 seconds to complete. See 3.9.3 The perform_self_test feature can be used as an end-of-line test to check sensor functionality and the customer power supply to the sensor.

Returns
bool True if successful, otherwise False

◆ persist_settings()

def qwiic_scd4x.QwiicSCD4x.persist_settings (   self,
  delayMillis = 800 
)

Persist settings: copy settings (e.g.

temperature offset) from RAM to EEPROM. See 3.9.1

Configuration settings such as the temperature offset, sensor altitude and the ASC enabled/disabled parameter are by default stored in the volatile memory (RAM) only and will be lost after a power-cycle. The persist_settings command stores the current configuration in the EEPROM of the SCD4x, making them persistent across power-cycling.

WARNING: To avoid unnecessary wear of the EEPROM, the persist_settings command should only be sent when persistence is required and if actual changes to the configuration have been made. The EEPROM is guaranteed to endure at least 2000 write cycles before failure.

Parameters
intdelayMillis: The delay in milliseconds to wait after persisting the settings
Returns
bool True if successful, otherwise False

◆ read_measurement()

def qwiic_scd4x.QwiicSCD4x.read_measurement (   self)

Get 9 bytes from SCD4x.

See 3.5.2 Updates the internal CO2, humidity, and temperature values Returns true if data is read successfully Read sensor output. The measurement data can only be read out once per signal update interval as the buffer is emptied upon read-out. If no data is available in the buffer, the sensor returns a NACK. To avoid a NACK response, the get_data_ready_status can be issued to check data status (see chapter 3.8.2 for further details).

Returns
True if successful, otherwise False :rtype

◆ read_register()

def qwiic_scd4x.QwiicSCD4x.read_register (   self,
  registerAddress,
  delayMillis = 1 
)

Read a register from the sensor.

Gets two bytes from SCD4x plus CRC

Parameters
intregisterAddress: The address of the register to read
intdelayMillis: The delay in milliseconds to wait after reading the register
Returns
int The value of the register if successful, otherwise None

◆ reinit()

def qwiic_scd4x.QwiicSCD4x.reinit (   self,
  delayMillis = 20 
)

Re-initialize the sensor, load settings from EEPROM.

See 3.9.5

The reinit command reinitializes the sensor by reloading user settings from EEPROM. Before sending the reinit command, the stop measurement command must be issued. If the reinit command does not trigger the desired re-initialization, a power-cycle should be applied to the SCD4x

Parameters
intdelayMillis: The delay in milliseconds to wait after re-initializing
Returns
bool True if successful, otherwise False

◆ send_command()

def qwiic_scd4x.QwiicSCD4x.send_command (   self,
  command,
  arguments = None 
)

Sends a command along with arguments and CRC.

Parameters
intcommand: The command to send
intarguments: A 16 bit value containing the arguments to send

◆ set_ambient_pressure()

def qwiic_scd4x.QwiicSCD4x.set_ambient_pressure (   self,
  pressure,
  delayMillis = 1 
)

Set the ambient pressure (Pa).

See 3.6.5 Max command duration: 1ms

Define the ambient pressure in Pascals, so RH and CO2 are compensated for atmospheric pressure set_ambient_pressure overrides set_sensor_altitude

The user can set delayMillis to zero if they want the function to return immediately. The set_ambient_pressure command can be sent during periodic measurements to enable continuous pressure compensation. set_ambient_pressure overrides set_sensor_altitude

Parameters
intpressure: The pressure to set. Must be between 0 and 6553500
intdelayMillis: The delay in milliseconds to wait after setting the pressure

◆ set_automatic_self_calibration_enabled()

def qwiic_scd4x.QwiicSCD4x.set_automatic_self_calibration_enabled (   self,
  enabled,
  delayMillis = 1 
)

Enable/disable automatic self calibration.

See 3.7.2 Set the current state (enabled / disabled) of the automatic self-calibration. By default, ASC is enabled. To save the setting to the EEPROM, the persist_setting (see chapter 3.9.1) command must be issued.

Parameters
boolenabled: True to enable, False to disable
intdelayMillis: The delay in milliseconds to wait after setting the calibration
Returns
bool True if successful, otherwise False

◆ set_sensor_altitude()

def qwiic_scd4x.QwiicSCD4x.set_sensor_altitude (   self,
  altitude,
  delayMillis = 1 
)

Set the sensor altitude (metres above sea level).

See 3.6.3 Max command duration: 1ms The user can set delayMillis to zero if they want the function to return immediately. Reading and writing of the sensor altitude must be done while the SCD4x is in idle mode. Typically, the sensor altitude is set once after device installation. To save the setting to the EEPROM, the persist setting (see chapter 3.9.1) command must be issued. Per default, the sensor altitude is set to 0 meter above sea-level.

Parameters
intaltitude: The altitude to set
intdelayMillis: The delay in milliseconds to wait after setting the altitude

◆ set_sensor_type()

def qwiic_scd4x.QwiicSCD4x.set_sensor_type (   self,
  sensorType 
)

Set the sensor type.

Allowable versions are kTypeSCD40, kTypeSCD41, and kTypeSDC4xInvalid

Parameters
intsensorType: The sensor type to set

◆ set_temperature_offset()

def qwiic_scd4x.QwiicSCD4x.set_temperature_offset (   self,
  offset,
  delayMillis = 1 
)

Set the temperature offset (C).

See 3.6.1 Max command duration: 1ms The user can set delayMillis to zero if they want the function to return immediately. The temperature offset has no influence on the SCD4x CO2 accuracy. Setting the temperature offset of the SCD4x inside the customer device correctly allows the user to leverage the RH and T output signal.

Parameters
intoffset: The temperature offset to set. Must be between 0 and 175
intdelayMillis: The delay in milliseconds to wait after setting the offset
Returns
bool True if successful, otherwise False

◆ start_low_power_periodic_measurement()

def qwiic_scd4x.QwiicSCD4x.start_low_power_periodic_measurement (   self)

Start low power periodic measurements.

See 3.8.1 Signal update interval will be 30 seconds instead of 5

Returns
bool True if successful, otherwise False

◆ start_periodic_measurement()

def qwiic_scd4x.QwiicSCD4x.start_periodic_measurement (   self)

Start periodic measurements.

See 3.5.1 signal update interval is 5 seconds.

◆ stop_periodic_measurement()

def qwiic_scd4x.QwiicSCD4x.stop_periodic_measurement (   self,
  delayMillis = 500 
)

stop_periodic_measurement can be called before begin() if required Note that the sensor will only respond to other commands after waiting 500 ms after issuing the stop_periodic_measurement command.

Parameters
intdelayMillis: The delay in milliseconds to wait after stopping the measurement

Member Data Documentation

◆ address

qwiic_scd4x.QwiicSCD4x.address

◆ available_addresses

qwiic_scd4x.QwiicSCD4x.available_addresses = _AVAILABLE_I2C_ADDRESS
static

◆ device_name

qwiic_scd4x.QwiicSCD4x.device_name = _DEFAULT_NAME
static

◆ kComGetAutomaticSelfCalibrationEnabled

int qwiic_scd4x.QwiicSCD4x.kComGetAutomaticSelfCalibrationEnabled = 0x2313
static

◆ kComGetDataReadyStatus

int qwiic_scd4x.QwiicSCD4x.kComGetDataReadyStatus = 0xe4b8
static

◆ kComGetFeatureSetVersion

int qwiic_scd4x.QwiicSCD4x.kComGetFeatureSetVersion = 0x202F
static

◆ kComGetSensorAltitude

int qwiic_scd4x.QwiicSCD4x.kComGetSensorAltitude = 0x2322
static

◆ kComGetSerialNumber

int qwiic_scd4x.QwiicSCD4x.kComGetSerialNumber = 0x3682
static

◆ kComGetTemperatureOffset

int qwiic_scd4x.QwiicSCD4x.kComGetTemperatureOffset = 0x2318
static

◆ kComMeasureSingleShot

int qwiic_scd4x.QwiicSCD4x.kComMeasureSingleShot = 0x219d
static

◆ kComMeasureSingleShotRhtOnly

int qwiic_scd4x.QwiicSCD4x.kComMeasureSingleShotRhtOnly = 0x2196
static

◆ kComPerformFactoryReset

int qwiic_scd4x.QwiicSCD4x.kComPerformFactoryReset = 0x3632
static

◆ kComPerformForcedCalibration

int qwiic_scd4x.QwiicSCD4x.kComPerformForcedCalibration = 0x362f
static

◆ kComPerformSelfTest

int qwiic_scd4x.QwiicSCD4x.kComPerformSelfTest = 0x3639
static

◆ kComPersistSettings

int qwiic_scd4x.QwiicSCD4x.kComPersistSettings = 0x3615
static

◆ kComReadMeasurement

int qwiic_scd4x.QwiicSCD4x.kComReadMeasurement = 0xec05
static

◆ kComReinit

int qwiic_scd4x.QwiicSCD4x.kComReinit = 0x3646
static

◆ kComSetAmbientPressure

int qwiic_scd4x.QwiicSCD4x.kComSetAmbientPressure = 0xe000
static

◆ kComSetAutomaticSelfCalibrationEnabled

int qwiic_scd4x.QwiicSCD4x.kComSetAutomaticSelfCalibrationEnabled = 0x2416
static

◆ kComSetSensorAltitude

int qwiic_scd4x.QwiicSCD4x.kComSetSensorAltitude = 0x2427
static

◆ kComSetTemperatureOffset

int qwiic_scd4x.QwiicSCD4x.kComSetTemperatureOffset = 0x241d
static

◆ kComStartLowPowerPeriodicMeasurement

int qwiic_scd4x.QwiicSCD4x.kComStartLowPowerPeriodicMeasurement = 0x21ac
static

◆ kComStartPeriodicMeasurement

int qwiic_scd4x.QwiicSCD4x.kComStartPeriodicMeasurement = 0x21b1
static

◆ kComStopPeriodicMeasurement

int qwiic_scd4x.QwiicSCD4x.kComStopPeriodicMeasurement = 0x3f86
static

◆ kTypeSCD40

int qwiic_scd4x.QwiicSCD4x.kTypeSCD40 = 0
static

◆ kTypeSCD41

int qwiic_scd4x.QwiicSCD4x.kTypeSCD41 = 1
static

◆ kTypeSDC4xInvalid

int qwiic_scd4x.QwiicSCD4x.kTypeSDC4xInvalid = 2
static

Property Documentation

◆ connected

qwiic_scd4x.QwiicSCD4x.connected = property(is_connected)
static

The documentation for this class was generated from the following file: