aht20

package module
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 4 Imported by: 1

README

go-aht20

GoDoc MIT License

https://github.com/tinygo-org/drivers/tree/release/aht20 of https://github.com/d2r2/go-i2c Transplant.

AHT20 产品规格书 AHT20 Datasheet

Example

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, 1)
	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(), "%")
}

Acknowledgments

Documentation

Overview

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

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 Device added in v0.5.0

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

Device wraps an I2C connection to an AHT20 device.

func New added in v0.7.0

func New(bus *i2c.I2C) Device

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

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

func NewAHT20 added in v0.3.0

func NewAHT20(bus *i2c.I2C) Device

NewAHT20 return new sensor instance.

func (*Device) Celsius added in v0.5.0

func (d *Device) Celsius() float32

Temperature in degrees celsius

func (*Device) Configure added in v0.5.0

func (d *Device) Configure()

Configure the device

func (*Device) DeciCelsius added in v0.5.0

func (d *Device) DeciCelsius() int32

Temperature in mutiples of one tenth of a degree celsius

Using this method avoids floating point calculations.

func (*Device) DeciRelHumidity added in v0.8.0

func (d *Device) DeciRelHumidity() int32

func (*Device) RawHumidity added in v0.5.0

func (d *Device) RawHumidity() uint32

func (*Device) RawTemp added in v0.5.0

func (d *Device) RawTemp() uint32

func (*Device) Read added in v0.5.0

func (d *Device) Read() error

Read the temperature and humidity

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

func (*Device) ReadRelativeHumidity added in v0.9.0

func (d *Device) ReadRelativeHumidity() (float32, error)

func (*Device) ReadTemperatureC added in v0.9.0

func (d *Device) ReadTemperatureC() (float32, error)

ReadTemperatureC reads and calculates temrature in C (celsius).

func (*Device) RelHumidity added in v0.5.0

func (d *Device) RelHumidity() float32

func (*Device) Reset added in v0.5.0

func (d *Device) Reset()

Reset the device

func (*Device) Status added in v0.5.0

func (d *Device) Status() byte

Status of the device

Directories

Path Synopsis
doc
example/1 command
example/2 command

Jump to

Keyboard shortcuts

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