![]() |
Qwiic_SCD4x_Py
2.0.0-1-gaedadef
Python for SFE Qwiic SCD4x
|
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) | |
def qwiic_scd4x.QwiicSCD4x.__init__ | ( | self, | |
address = None , |
|||
i2c_driver = None |
|||
) |
Constructor.
int,optional | address: The I2C address to use for the device If not provided, the default address is used |
I2CDriver,optional | i2c_driver: An existing i2c driver object If not provided, a driver object is created |
def qwiic_scd4x.QwiicSCD4x.begin | ( | self, | |
measBegin = True , |
|||
autoCalibrate = True , |
|||
skipStopPeriodicMeasurement = False , |
|||
pollAndSetDeviceType = True |
|||
) |
Initializes this device with default parameters.
True
if successful, otherwise False
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.
list | of int data: The data to compute the CRC for |
def qwiic_scd4x.QwiicSCD4x.convert_hex_to_ascii | ( | self, | |
digit | |||
) |
Convert a hex digit to its ASCII representation.
int | digit: The hex digit to convert |
def qwiic_scd4x.QwiicSCD4x.get_automatic_self_calibration_enabled | ( | self | ) |
Check if automatic self calibration is enabled.
See 3.7.3
True
if enabled, otherwise False
def qwiic_scd4x.QwiicSCD4x.get_co2 | ( | self | ) |
def qwiic_scd4x.QwiicSCD4x.get_data_ready_status | ( | self | ) |
Returns true when data is available.
See 3.8.2
True
if data is ready, otherwise False
def qwiic_scd4x.QwiicSCD4x.get_feature_set_version | ( | self | ) |
Save the feature set version/sensor type of the sensor.
True
if successful, otherwise False
def qwiic_scd4x.QwiicSCD4x.get_humidity | ( | self | ) |
Get the humidity value.
Call read_measurement() first to update the value
def qwiic_scd4x.QwiicSCD4x.get_sensor_altitude | ( | self | ) |
Get the sensor altitude (metres above sea level).
See 3.6.4
def qwiic_scd4x.QwiicSCD4x.get_sensor_type | ( | self | ) |
Get the sensor type.
Allowable versions are kTypeSCD40, kTypeSCD41, and kTypeSDC4xInvalid
def qwiic_scd4x.QwiicSCD4x.get_serial_number | ( | self | ) |
Get the serial number of the sensor.
int | serialNumber: The serial number of the sensor |
None
def qwiic_scd4x.QwiicSCD4x.get_temperature | ( | self | ) |
Get the temperature value.
Call read_measurement() first to update the value
def qwiic_scd4x.QwiicSCD4x.get_temperature_offset | ( | self | ) |
Get the temperature offset (C).
See 3.6.2
def qwiic_scd4x.QwiicSCD4x.is_connected | ( | self | ) |
Determines if this device is connected.
True
if connected, otherwise False
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:
True
if successful, otherwise False
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.
True
if successful, otherwise False
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.
int | delayMillis: The delay in milliseconds to wait after performing the factory reset |
True
if successful, otherwise False
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:
int | concentration: The concentration to recalibrate to |
True
if successful, otherwise False
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.
True
if successful, otherwise False
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.
int | delayMillis: The delay in milliseconds to wait after persisting the settings |
True
if successful, otherwise False
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).
True
if successful, otherwise False
:rtype def qwiic_scd4x.QwiicSCD4x.read_register | ( | self, | |
registerAddress, | |||
delayMillis = 1 |
|||
) |
Read a register from the sensor.
Gets two bytes from SCD4x plus CRC
int | registerAddress: The address of the register to read |
int | delayMillis: The delay in milliseconds to wait after reading the register |
None
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
int | delayMillis: The delay in milliseconds to wait after re-initializing |
True
if successful, otherwise False
def qwiic_scd4x.QwiicSCD4x.send_command | ( | self, | |
command, | |||
arguments = None |
|||
) |
Sends a command along with arguments and CRC.
int | command: The command to send |
int | arguments: A 16 bit value containing the arguments to send |
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
int | pressure: The pressure to set. Must be between 0 and 6553500 |
int | delayMillis: The delay in milliseconds to wait after setting the pressure |
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.
bool | enabled: True to enable, False to disable |
int | delayMillis: The delay in milliseconds to wait after setting the calibration |
True
if successful, otherwise False
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.
int | altitude: The altitude to set |
int | delayMillis: The delay in milliseconds to wait after setting the altitude |
def qwiic_scd4x.QwiicSCD4x.set_sensor_type | ( | self, | |
sensorType | |||
) |
Set the sensor type.
Allowable versions are kTypeSCD40, kTypeSCD41, and kTypeSDC4xInvalid
int | sensorType: The sensor type to set |
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.
int | offset: The temperature offset to set. Must be between 0 and 175 |
int | delayMillis: The delay in milliseconds to wait after setting the offset |
True
if successful, otherwise False
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
True
if successful, otherwise False
def qwiic_scd4x.QwiicSCD4x.start_periodic_measurement | ( | self | ) |
Start periodic measurements.
See 3.5.1 signal update interval is 5 seconds.
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.
int | delayMillis: The delay in milliseconds to wait after stopping the measurement |
qwiic_scd4x.QwiicSCD4x.address |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |