API Documentation¶
SGP40¶
Sgp40I2cDevice¶
-
class
sensirion_i2c_sgp4x.sgp40.device.
Sgp40I2cDevice
(connection, slave_address=89)[source]¶ SGP40 I²C device class to allow executing I²C commands.
-
__init__
(connection, slave_address=89)[source]¶ Constructs a new SGP40 I²C device.
Parameters: - connection (I2cConnection) – The I²C connection to use for communication.
- slave_address (byte) – The I²C slave address, defaults to 0x59.
-
measure_raw
(relative_humidity=None, temperature=None)[source]¶ Read raw VOC signal
Parameters: - relative_humidity – relative humidity in percent. Defaults to 50% RH
- temperature – temperature in degree celsius. Defaults to 25°C
Returns: - raw VOC signal (
Sgp40SrawVoc
)
Return type:
-
turn_heater_off
()[source]¶ Turn Heater Off I²C Command
This command turns the hotplate off and stops the measurement. Subsequently, the sensor enters the idle mode.
-
measure_test
()[source]¶ Measure Test
This command triggers the built-in self-test checking for integrity of the hotplate and MOX material and returns the result of this test as 2 bytes
Returns: 0xD400: all tests passed successfully or 0x4B00: one or more tests have failed Return type: uint16
-
connection
¶ Get the used I²C connection.
Returns: The used I²C connection. Return type: I2cConnection
-
execute
(command)¶ Execute an I²C command on this device.
Parameters: command (I2cCommand) – The command to be executed. Returns: The interpreted response of the executed command. Return type: Depends on the executed command.
-
slave_address
¶ Get the I²C slave address.
Returns: The I²C slave address. Return type: byte
-
Sgp40I2cCommand¶
-
class
sensirion_i2c_sgp4x.sgp40.commands.
Sgp40I2cCmdBase
(command, tx_data, rx_length, read_delay, timeout, post_processing_time=0.0)[source]¶ SGP40 I²C base command.
-
__init__
(command, tx_data, rx_length, read_delay, timeout, post_processing_time=0.0)[source]¶ Constructs a new SGP40 I²C command.
Parameters: - command (int/None) – The command ID to be sent to the device. None means that no
command will be sent, i.e. only
tx_data
(if not None) will be sent. No CRC is added to these bytes since the command ID usually already contains a CRC. - tx_data (bytes-like/list/None) – Bytes to be extended with CRCs and then sent to the I²C device.
None means that no write header will be sent at all (if
command
is None too). An empty list means to send the write header (even ifcommand
is None), but without data following it. - rx_length (int/None) – Number of bytes to be read from the I²C device, including CRC bytes. None means that no read header is sent at all. Zero means to send the read header, but without reading any data.
- read_delay (float) – Delay (in Seconds) to be inserted between the end of the write operation and the beginning of the read operation. This is needed if the device needs some time to prepare the RX data, e.g. if it has to perform a measurement. Set to 0.0 to indicate that no delay is needed, i.e. the device does not need any processing time.
- timeout (float) – Timeout (in Seconds) to be used in case of clock stretching. If the device stretches the clock longer than this value, the transceive operation will be aborted with a timeout error. Set to 0.0 to indicate that the device will not stretch the clock for this command.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing of this command until it is ready to receive the next command. For example after a device reset command, the device might need some time until it is ready again. Usually this is 0.0s, i.e. no post processing is needed.
- command (int/None) – The command ID to be sent to the device. None means that no
command will be sent, i.e. only
-
interpret_response
(data)¶ Validates the CRCs of the received data from the device and returns the data with all CRCs removed.
Parameters: data (bytes) – Received raw bytes from the read operation. Returns: The received bytes, or None if there is no data received. Return type: bytes or None Raises: I2cChecksumError – If a received CRC was wrong.
-
-
class
sensirion_i2c_sgp4x.sgp40.commands.
Sgp40I2cCmdMeasureRawSignal
(relative_humidity, temperature)[source]¶ SGP40 Measure Raw Signal I²C Command
This command starts/continues the VOC measurement mode
-
__init__
(relative_humidity, temperature)[source]¶ Constructor.
Parameters: - relative_humidity (int) – Leaves humidity compensation disabled by sending the default value 0x8000 (50%RH) or enables humidity compensation when sending the relative humidity in ticks (ticks = %RH * 65535 / 100)
- temperature (int) – Leaves humidity compensation disabled by sending the default value 0x6666 (25 degC) or enables humidity compensation when sending the temperature in ticks (ticks = (degC + 45) * 65535 / 175)
-
interpret_response
(data)[source]¶ Validates the CRCs of the received data from the device and returns the interpreted data.
Parameters: data (bytes) – Received raw bytes from the read operation. Returns: the raw signal SRAW_VOC in ticks which is proportional to the logarithm of the resistance of the sensing element. Return type: Sgp40SrawVoc
Raises: I2cChecksumError – If a received CRC was wrong.
-
-
class
sensirion_i2c_sgp4x.sgp40.commands.
Sgp40I2cCmdExecuteSelfTest
[source]¶ SGP40 Execute Self Test I²C Command
This command triggers the built-in self-test checking for integrity of the hotplate and MOX material and returns the result of this test as 2 bytes
-
interpret_response
(data)[source]¶ Validates the CRCs of the received data from the device and returns the interpreted data.
Parameters: data (bytes) – Received raw bytes from the read operation. Returns: 0xD4 00: all tests passed successfully or 0x4B 00: one or more tests have failed Return type: int Raises: I2cChecksumError – If a received CRC was wrong.
-
-
class
sensirion_i2c_sgp4x.sgp40.commands.
Sgp40I2cCmdTurnHeaterOff
[source]¶ SGP40 Turn Heater Off I²C Command
This command turns the hotplate off and stops the measurement. Subsequently, the sensor enters the idle mode.
-
interpret_response
(data)¶ Validates the CRCs of the received data from the device and returns the data with all CRCs removed.
Parameters: data (bytes) – Received raw bytes from the read operation. Returns: The received bytes, or None if there is no data received. Return type: bytes or None Raises: I2cChecksumError – If a received CRC was wrong.
-
-
class
sensirion_i2c_sgp4x.sgp40.commands.
Sgp40I2cCmdGetSerialNumber
[source]¶ SGP40 Get Serial Number I²C Command
This command provides the decimal serial number of the SGP40 chip by returning 3x2 bytes.
-
interpret_response
(data)[source]¶ Validates the CRCs of the received data from the device and returns the interpreted data.
Parameters: data (bytes) – Received raw bytes from the read operation. Returns: 48-bit unique serial number Return type: list(int) Raises: I2cChecksumError – If a received CRC was wrong.
-
Response Types¶
-
class
sensirion_i2c_sgp4x.sgp40.response_types.
Sgp40SrawVoc
(ticks)[source]¶ Represents a measurement response for the raw VOC signal.
With the
ticks
you can access the raw data as received from the device.Parameters: ticks (int) – The read ticks as received from the device. -
ticks
¶ The ticks (int) as received from the device.
-
SGP41¶
Sgp41I2cDevice¶
-
class
sensirion_i2c_sgp4x.sgp41.device.
Sgp41I2cDevice
(connection, slave_address=89)[source]¶ SGP41 I²C device class to allow executing I²C commands.
-
__init__
(connection, slave_address=89)[source]¶ Constructs a new SGP41 I²C device.
Parameters: - connection (I2cConnection) – The I²C connection to use for communication.
- slave_address (byte) – The I²C slave address, defaults to 0x59.
-
conditioning
(relative_humidity=None, temperature=None)[source]¶ This command starts the conditioning, i.e., the VOC pixel will be operated at the same temperature as it is by calling the measure_raw command while the NOx pixel will be operated at a different temperature for conditioning. This command returns only the measured raw signal of the VOC pixel SRAW_VOC
WARNING: To avoid damage to the sensing material the conditioning must not exceed 10s!
Parameters: - relative_humidity – relative humidity in percent. Defaults to 50% RH
- temperature – temperature in degree celsius. Defaults to 25°C
Returns: raw VOC signal (
Sgp41SrawVoc
)Return type:
-
measure_raw
(relative_humidity=None, temperature=None)[source]¶ Read raw VOC signal and raw NOx signal
Parameters: - relative_humidity – relative humidity in percent. Defaults to 50% RH
- temperature – temperature in degree celsius. Defaults to 25°C
Returns: - raw VOC signal (
Sgp41SrawVoc
) - raw NOx signal (
Sgp41SrawNox
)
Return type: tuple
-
turn_heater_off
()[source]¶ Turn Heater Off I²C Command
This command turns the hotplate off and stops the measurement. Subsequently, the sensor enters the idle mode.
-
measure_test
()[source]¶ Measure Test
This command triggers the built-in self-test checking for integrity of the hotplate and MOX material and returns the result of this test as 2 bytes
Returns: 0xD400: all tests passed successfully or 0x4B00: one or more tests have failed Return type: uint16
-
connection
¶ Get the used I²C connection.
Returns: The used I²C connection. Return type: I2cConnection
-
execute
(command)¶ Execute an I²C command on this device.
Parameters: command (I2cCommand) – The command to be executed. Returns: The interpreted response of the executed command. Return type: Depends on the executed command.
-
slave_address
¶ Get the I²C slave address.
Returns: The I²C slave address. Return type: byte
-
Sgp41I2cCommand¶
-
class
sensirion_i2c_sgp4x.sgp41.commands.
Sgp41I2cCmdBase
(command, tx_data, rx_length, read_delay, timeout, post_processing_time=0.0)[source]¶ SGP41 I²C base command.
-
__init__
(command, tx_data, rx_length, read_delay, timeout, post_processing_time=0.0)[source]¶ Constructs a new SGP41 I²C command.
Parameters: - command (int/None) – The command ID to be sent to the device. None means that no
command will be sent, i.e. only
tx_data
(if not None) will be sent. No CRC is added to these bytes since the command ID usually already contains a CRC. - tx_data (bytes-like/list/None) – Bytes to be extended with CRCs and then sent to the I²C device.
None means that no write header will be sent at all (if
command
is None too). An empty list means to send the write header (even ifcommand
is None), but without data following it. - rx_length (int/None) – Number of bytes to be read from the I²C device, including CRC bytes. None means that no read header is sent at all. Zero means to send the read header, but without reading any data.
- read_delay (float) – Delay (in Seconds) to be inserted between the end of the write operation and the beginning of the read operation. This is needed if the device needs some time to prepare the RX data, e.g. if it has to perform a measurement. Set to 0.0 to indicate that no delay is needed, i.e. the device does not need any processing time.
- timeout (float) – Timeout (in Seconds) to be used in case of clock stretching. If the device stretches the clock longer than this value, the transceive operation will be aborted with a timeout error. Set to 0.0 to indicate that the device will not stretch the clock for this command.
- post_processing_time (float) – Maximum time in seconds the device needs for post processing of this command until it is ready to receive the next command. For example after a device reset command, the device might need some time until it is ready again. Usually this is 0.0s, i.e. no post processing is needed.
- command (int/None) – The command ID to be sent to the device. None means that no
command will be sent, i.e. only
-
interpret_response
(data)¶ Validates the CRCs of the received data from the device and returns the data with all CRCs removed.
Parameters: data (bytes) – Received raw bytes from the read operation. Returns: The received bytes, or None if there is no data received. Return type: bytes or None Raises: I2cChecksumError – If a received CRC was wrong.
-
-
class
sensirion_i2c_sgp4x.sgp41.commands.
Sgp41I2cCmdExecuteConditioning
(default_rh, default_t)[source]¶ SGP41 Execute Conditioning I²C Command
This command starts the conditioning, i.e., the VOC pixel will be operated at the same temperature as it is by calling the sgp41_measure_raw command while the NOx pixel will be operated at a different temperature for conditioning. This command returns only the measured raw signal of the VOC pixel SRAW_VOC as 2 bytes (+ 1 CRC byte).
-
__init__
(default_rh, default_t)[source]¶ Constructor.
Parameters: - default_rh (int) – Default conditions for relative humidty.
- default_t (int) – Default conditions for temperature.
-
interpret_response
(data)[source]¶ Validates the CRCs of the received data from the device and returns the interpreted data.
Parameters: data (bytes) – Received raw bytes from the read operation. Returns: the raw signal SRAW_VOC in ticks which is proportional to the logarithm of the resistance of the sensing element. Return type: Sgp41SrawVoc
Raises: I2cChecksumError – If a received CRC was wrong.
-
-
class
sensirion_i2c_sgp4x.sgp41.commands.
Sgp41I2cCmdMeasureRawSignals
(relative_humidity, temperature)[source]¶ SGP41 Measure Raw Signals I²C Command
This command starts/continues the VOC+NOx measurement mode
-
__init__
(relative_humidity, temperature)[source]¶ Constructor.
Parameters: - relative_humidity (int) – Leaves humidity compensation disabled by sending the default value 0x8000 (50%RH) or enables humidity compensation when sending the relative humidity in ticks (ticks = %RH * 65535 / 100)
- temperature (int) – Leaves humidity compensation disabled by sending the default value 0x6666 (25 degC) or enables humidity compensation when sending the temperature in ticks (ticks = (degC + 45) * 65535 / 175)
-
interpret_response
(data)[source]¶ Validates the CRCs of the received data from the device and returns the interpreted data.
Parameters: data (bytes) – Received raw bytes from the read operation. Returns: - sraw_voc (
Sgp41SrawVoc
) - the raw signal SRAW_VOC in ticks which is proportional to the logarithm of the resistance of the sensing element. - sraw_nox (
Sgp41SrawNox
) - the raw signal SRAW_NOX in ticks which is proportional to the logarithm of the resistance of the sensing element.
Return type: tuple Raises: I2cChecksumError – If a received CRC was wrong. - sraw_voc (
-
-
class
sensirion_i2c_sgp4x.sgp41.commands.
Sgp41I2cCmdExecuteSelfTest
[source]¶ SGP41 Execute Self Test I²C Command
This command triggers the built-in self-test checking for integrity of both hotplate and MOX material and returns the result of this test as 2 bytes
-
interpret_response
(data)[source]¶ Validates the CRCs of the received data from the device and returns the interpreted data.
Parameters: data (bytes) – Received raw bytes from the read operation. Returns: 0xXX 0xYY: ignore most significant byte 0xXX. The four least significant bits of the least significant byte 0xYY provide information if the self-test has or has not passed for each individual pixel. All zero mean all tests passed successfully. Check the datasheet for more detailed information. Return type: int Raises: I2cChecksumError – If a received CRC was wrong.
-
-
class
sensirion_i2c_sgp4x.sgp41.commands.
Sgp41I2cCmdTurnHeaterOff
[source]¶ SGP41 Turn Heater Off I²C Command
This command turns the hotplate off and stops the measurement. Subsequently, the sensor enters the idle mode.
-
interpret_response
(data)¶ Validates the CRCs of the received data from the device and returns the data with all CRCs removed.
Parameters: data (bytes) – Received raw bytes from the read operation. Returns: The received bytes, or None if there is no data received. Return type: bytes or None Raises: I2cChecksumError – If a received CRC was wrong.
-
-
class
sensirion_i2c_sgp4x.sgp41.commands.
Sgp41I2cCmdGetSerialNumber
[source]¶ SGP41 Get Serial Number I²C Command
This command provides the decimal serial number of the SGP41 chip by returning 3x2 bytes.
-
interpret_response
(data)[source]¶ Validates the CRCs of the received data from the device and returns the interpreted data.
Parameters: data (bytes) – Received raw bytes from the read operation. Returns: 48-bit unique serial number Return type: list(int) Raises: I2cChecksumError – If a received CRC was wrong.
-
Response Types¶
-
class
sensirion_i2c_sgp4x.sgp41.response_types.
Sgp41SrawVoc
(ticks)[source]¶ Represents a measurement response for the raw VOC signal.
With the
ticks
you can access the raw data as received from the device.Parameters: ticks (int) – The read ticks as received from the device. -
ticks
¶ The ticks (int) as received from the device.
-
-
class
sensirion_i2c_sgp4x.sgp41.response_types.
Sgp41SrawNox
(ticks)[source]¶ Represents a measurement response for the raw NOx signal.
With the
ticks
you can access the raw data as received from the device.Parameters: ticks (int) – The read ticks as received from the device. -
ticks
¶ The ticks (int) as received from the device.
-