adafruit_scd4x

Driver for Sensirion SCD4X CO2 sensor

  • Author(s): ladyada

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_scd4x.SCD4X(i2c_bus: I2C, address: int = 98)

CircuitPython helper class for using the SCD4X CO2 sensor

Parameters:
  • i2c_bus (I2C) – The I2C bus the SCD4X is connected to.

  • address (int) – The I2C device address for the sensor. Default is 0x62

Quickstart: Importing and using the SCD4X

Here is an example of using the SCD4X class. First you will need to import the libraries to use the sensor

import board
import adafruit_scd4x

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()   # uses board.SCL and board.SDA
scd = adafruit_scd4x.SCD4X(i2c)
scd.start_periodic_measurement()

Now you have access to the CO2, temperature and humidity using the CO2, temperature and relative_humidity attributes

if scd.data_ready:
    temperature = scd.temperature
    relative_humidity = scd.relative_humidity
    co2_ppm_level = scd.CO2
property CO2: int

Returns the CO2 concentration in PPM (parts per million)

Note

Between measurements, the most recent reading will be cached and returned.

property altitude: int

Specifies the altitude at the measurement location in meters above sea level. Setting this value adjusts the CO2 measurement calculations to account for the air pressure’s effect on readings.

Note

This value will NOT be saved and will be reset on boot unless saved with persist_settings().

property data_ready: bool

Check the sensor to see if new data is available

factory_reset() None

Resets all configuration settings stored in the EEPROM and erases the FRC and ASC algorithm history.

force_calibration(target_co2: int) None

Forces the sensor to recalibrate with a given current CO2

measure_single_shot() None

On-demand measurement of CO2 concentration, relative humidity, and temperature for SCD41 only

measure_single_shot_rht_only() None

On-demand measurement of relative humidity and temperature for SCD41 only

persist_settings() None

Save temperature offset, altitude offset, and selfcal enable settings to EEPROM

reinit() None

Reinitializes the sensor by reloading user settings from EEPROM.

property relative_humidity: float

Returns the current relative humidity in %rH.

Note

Between measurements, the most recent reading will be cached and returned.

property self_calibration_enabled: bool

Enables or disables automatic self calibration (ASC). To work correctly, the sensor must be on and active for 7 days after enabling ASC, and exposed to fresh air for at least 1 hour per day. Consult the manufacturer’s documentation for more information.

Note

This value will NOT be saved and will be reset on boot unless saved with persist_settings().

self_test() None

Performs a self test, takes up to 10 seconds

property serial_number: Tuple[int, int, int, int, int, int]

Request a 6-tuple containing the unique serial number for this sensor

set_ambient_pressure(ambient_pressure: int) None

Set the ambient pressure in hPa at any time to adjust CO2 calculations

start_low_periodic_measurement() None

Put sensor into low power working mode, about 30s per measurement. See start_periodic_measurement() for more details.

start_periodic_measurement() None

Put sensor into working mode, about 5s per measurement

Note

Only the following commands will work once in working mode:

stop_periodic_measurement() None

Stop measurement mode

property temperature: float

Returns the current temperature in degrees Celsius

Note

Between measurements, the most recent reading will be cached and returned.

property temperature_offset: float

Specifies the offset to be added to the reported measurements to account for a bias in the measured signal. Value is in degrees Celsius with a resolution of 0.01 degrees and a maximum value of 374 C

Note

This value will NOT be saved and will be reset on boot unless saved with persist_settings().