Skip to content

Use Sensirion SCD4x CO2 sensors (SCD40 and SCD41) in Elixir

License

Notifications You must be signed in to change notification settings

mnishiguchi/scd4x

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SCD4X

Hex version API docs CI Publish

Use Sensirion SCD4X CO2 sensors (SCD40 and SCD41) in Elixir.

Usage

Start the sensor server

iex> {:ok, scd} = SCD4X.start_link(bus_name: "i2c-1")
{:ok, #PID<0.1407.0>}

Periodic measurement

The sensor updates the measurement every 5 seconds once the periodic measurement is started.

iex> SCD4X.start_periodic_measurement(scd)
:ok

iex> SCD4X.measure(scd)
{:ok,
 %SCD4X.Measurement{
   co2_ppm: 612,
   humidity_rh: 59.07440185546875,
   temperature_c: 30.331497192382812,
   timestamp_ms: 620482
 }}

SCD4X.stop_periodic_measurement(scd)
:ok

Single shot measurement

The measurement can be performed on demand without the periodic measurement.

iex> SCD4X.measure(scd, :single_shot)
{:ok,
 %SCD4X.Measurement{
   co2_ppm: 638,
   humidity_rh: 70.49713134765625,
   temperature_c: 26.63848876953125,
   timestamp_ms: 400768
 }}