Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/pvainio/scd30

Sensirion SCD30 CO2 sensor I2C driver
https://github.com/pvainio/scd30

co2 co2-sensor i2c i2c-device i2c-sensors iot scd30 sensirion sensirion-scd30

Last synced: 21 days ago
JSON representation

Sensirion SCD30 CO2 sensor I2C driver

Awesome Lists containing this project

README

        

# Sensirion SCD30 CO2 sensor i2c driver module for Golang

## Overview

With this module Sensirion SCD30 CO2 sensor can be accessed throug i2c bus.
Implemented:
- starting and stopping continuous measurements
- checking for ready measurement
- reading ready measurement
- getting and setting temperature compensation

## Example

```go
package main

import (
"log"
"time"

"github.com/pvainio/scd30"
"periph.io/x/conn/v3/i2c/i2creg"
"periph.io/x/host/v3"
)

func main() {
if _, err := host.Init(); err != nil {
log.Fatal(err)
}

bus, err := i2creg.Open("")
if err != nil {
log.Fatal(err)
}
defer bus.Close()

dev, err := scd30.Open(bus)
if err != nil {
log.Fatal(err)
}

var interval uint16 = 5

dev.StartMeasurements(interval)

for {
time.Sleep(time.Duration(interval) * time.Second)
if hasMeasurement, err := dev.HasMeasurement(); err != nil {
log.Fatalf("error %v", err)
} else if !hasMeasurement {
return
}

m, err := dev.GetMeasurement()
if err != nil {
log.Fatalf("error %v", err)
}

log.Printf("Got measure %f ppm %f%% %fC", m.CO2, m.Humidity, m.Temperature)
}
}
```