aht20

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: MIT Imports: 4 Imported by: 0

README

aht20-go

https://github.com/tinygo-org/drivers/aht20/aht20https://github.com/d2r2/go-i2c 移植

package main

import (
	"fmt"

	"github.com/d2r2/go-i2c"
	logger "github.com/d2r2/go-logger"

	aht20 "github.com/used255/aht20-go"
)

func main() {
	logger.ChangePackageLogLevel("i2c", logger.InfoLevel)
	bus, err := i2c.NewI2C(0x38, 1)
	if err != nil {
		return
	}
	aht20 := aht20.AHT20New(bus)
	err = aht20.ReadWithRetry(3)
	if err != nil {
		return
	}
	fmt.Println("温度:", aht20.Celsius(), "摄氏度")
	fmt.Println("相对湿度:", aht20.RelHumidity(), "%")
}

Documentation

Index

Constants

View Source
const (
	CMD_INITIALIZE = 0xBE
	CMD_STATUS     = 0x71
	CMD_TRIGGER    = 0xAC
	CMD_SOFTRESET  = 0xBA

	STATUS_BUSY       = 0x80
	STATUS_CALIBRATED = 0x08
)

Variables

View Source
var (
	ErrBusy    = errors.New("AHT20 busy")
	ErrTimeout = errors.New("timeout")
)

Functions

This section is empty.

Types

type AHT20

type AHT20 struct {
	// contains filtered or unexported fields
}

AHT20 wraps an I2C connection(github.com/d2r2/go-i2c) to an AHT20 .

func AHT20New

func AHT20New(bus *i2c.I2C) AHT20

New creates a new AHT20 connection. The I2C bus must already be configured.

This function only creates the AHT20 object, it does not touch the AHT20.

func (*AHT20) Celsius

func (d *AHT20) Celsius() float32

Temperature in degrees celsius

func (*AHT20) Configure

func (d *AHT20) Configure()

Configure the AHT20

func (*AHT20) RawHumidity

func (d *AHT20) RawHumidity() uint32

func (*AHT20) RawTemp

func (d *AHT20) RawTemp() uint32

func (*AHT20) Read

func (d *AHT20) Read() error

Read the temperature and humidity

The actual temperature and humidity are stored and can be accessed using `Temp` and `Humidity`.

func (*AHT20) ReadWithRetry

func (d *AHT20) ReadWithRetry(i int) error

func (*AHT20) RelHumidity

func (d *AHT20) RelHumidity() float32

func (*AHT20) Reset

func (d *AHT20) Reset()

Reset the AHT20

func (*AHT20) Status

func (d *AHT20) Status() byte

Status of the AHT20

func (*AHT20) Tx

func (i *AHT20) Tx(w, r []byte) error

Jump to

Keyboard shortcuts

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