Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mnishiguchi/scd4x

Use Sensirion SCD4x CO2 sensors (SCD40 and SCD41) in Elixir
https://github.com/mnishiguchi/scd4x

co2-sensor elixir elixir-lang elixir-language nerves nerves-project scd40 scd41 scd4x scd4x-sensor sensor sensors

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# SCD4X

[![Hex version](https://img.shields.io/hexpm/v/scd4x.svg 'Hex version')](https://hex.pm/packages/scd4x)
[![API docs](https://img.shields.io/hexpm/v/scd4x.svg?label=docs 'API docs')](https://hexdocs.pm/scd4x)
[![CI](https://github.com/mnishiguchi/scd4x/actions/workflows/ci.yml/badge.svg)](https://github.com/mnishiguchi/scd4x/actions/workflows/ci.yml)
[![Publish](https://github.com/mnishiguchi/scd4x/actions/workflows/publish.yml/badge.svg)](https://github.com/mnishiguchi/scd4x/actions/workflows/publish.yml)

Use [Sensirion SCD4X](https://www.sensirion.com/en/environmental-sensors/carbon-dioxide-sensors/carbon-dioxide-sensor-scd4x) [CO2](https://en.wikipedia.org/wiki/Carbon_dioxide) sensors (SCD40 and SCD41) in Elixir.

## Usage

### Start the sensor server

```elixir
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.

```elixir
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.

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