adafruit_scd4x

Driver for Sensirion SCD4X CO2 sensor

  • Author(s): ladyada

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_scd4x.SCD4X(i2c_bus, address=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

Returns the CO2 concentration in PPM (parts per million)

Note

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

property altitude

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

Check the sensor to see if new data is available

factory_reset()

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

force_calibration(target_co2)

Forces the sensor to recalibrate with a given current CO2

persist_settings()

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

reinit()

Reinitializes the sensor by reloading user settings from EEPROM.

property relative_humidity

Returns the current relative humidity in %rH.

Note

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

property self_calibration_enabled

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()

Performs a self test, takes up to 10 seconds

property serial_number

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

set_ambient_pressure(ambient_pressure)

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

start_low_periodic_measurement()

Put sensor into low power working mode, about 30s per measurement

start_periodic_measurement()

Put sensor into working mode, about 5s per measurement

stop_periodic_measurement()

Stop measurement mode

property temperature

Returns the current temperature in degrees Celsius

Note

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

property temperature_offset

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().