Skip to content

Latest commit

 

History

History
36 lines (31 loc) · 522 Bytes

README.md

File metadata and controls

36 lines (31 loc) · 522 Bytes

mhz19

Read CO2 concentration from MH-Z19 on Raspberry Pi.

Installation

$ go get github.com/kebhr/mhz19/cmd/mhz19

Usage

$ mhz19
{"co2": "554"}

Use as a library

package main

import (
	"log"
	"github.com/kebhr/mhz19"
)

func main() {
	m := mhz19.MHZ19{}
	myDevicePath := "/dev/ttyS0"
	if err := m.Connect(myDevicePath); err != nil {
		log.Fatal(err)
	}
	v, err := m.ReadCO2()
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("CO2 Concentration: %dppm\n", v)
}