z19

package module
v0.0.0-...-e303ef7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2023 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

mh-z19

Reading mh-z19 sensors with wiringpi and golang on raspberry pi.

Example

package main

import (
	"fmt"

	z19 "github.com/eternal-flame-AD/mh-z19"
	"github.com/tarm/serial"
)

func main() {
	connConfig := z19.CreateSerialConfig()
	connConfig.Name = "/dev/serial0"

	port, err := serial.OpenPort(connConfig)
	if err != nil {
		panic(err)
	}
	defer port.Close()
	concentration, err := z19.TakeReading(port)
	if err != nil {
		panic(err)
	}
	fmt.Printf("co2=%d ppm\n", concentration)
}

```# co2

Documentation

Index

Constants

View Source
const BaudRate = 9600

BaudRate is the UART baud rate of the sensor

Variables

This section is empty.

Functions

func CreateSerialConfig

func CreateSerialConfig() *serial.Config

CreateSerialConfig creates a serial configuration with the baud rate of mh-z19

func SpanPointCalibration

func SpanPointCalibration(i io.Writer, ref uint16) error

SpanPointCalibration sends a span point calibration command to the sensor with a reference CO2 concentration

func TakeReading

func TakeReading(i io.ReadWriter) (uint16, error)

TakeReading takes a reading from the sensor

func ZeroPointCalibration

func ZeroPointCalibration(i io.Writer) error

ZeroPointCalibration sends a zero calibration command to the sensor

Types

type Command

type Command byte

Command is a command sent to the sensor

const (
	// CmdGetReading takes a reading
	CmdGetReading Command = 0x86
	// CmdZeroPointCalibration performs a zero point calibration
	CmdZeroPointCalibration Command = 0x87
	// CmdSpanPointCalibration performs a span point calibration
	CmdSpanPointCalibration Command = 0x88
)

Directories

Path Synopsis
cmd
mh-z19 command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址