Use Sensirion SCD4X CO2 sensors (SCD40 and SCD41) in Elixir.
iex> {:ok, scd} = SCD4X.start_link(bus_name: "i2c-1")
{:ok, #PID<0.1407.0>}
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
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
}}