Categorygithub.com/used255/go-aht20
modulepackage
0.7.0
Repository: https://github.com/used255/go-aht20.git
Documentation: pkg.go.dev

# README

go-aht20

GoDoc MIT License

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

AHT20 产品规格书 AHT20 Datasheet

package main

import (
	"fmt"
	"log"

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

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

func main() {
	//logger.ChangePackageLogLevel("i2c", logger.DebugLevel)
	logger.ChangePackageLogLevel("aht20", logger.DebugLevel)

	bus, err := i2c.NewI2C(0x38, 0)
	if err != nil {
		log.Fatal(err)
	}
	defer bus.Close()

	s := aht20.New(bus)
	s.Configure()

	err = s.Read()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("温度:", s.Celsius(), "摄氏度")
	fmt.Println("相对湿度:", s.RelHumidity(), "%")
}

您也可以看看

# Packages

No description provided by the author

# Functions

New creates a new AHT20 connection.
New creates a new AHT20 connection.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author

# Structs

Device wraps an I2C connection to an AHT20 device.