am2320

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2019 License: Apache-2.0 Imports: 5 Imported by: 1

README

Build Status

go-am2320

Code to access an AM2320 via i2c on Raspberry Pi

Usage

package main

import (
    "log"

    "github.com/oltoko/go-am2320"
)

func main() {
    
    sensor := am2320.Create(am2320.DefaultI2CAddr)

    values, err := sensor.Read()
    if err != nil {
        log.Fatalln("Failed to read from Sensor", err)
    }

    log.Printf("%.2f °C", values.Temperature)
    log.Printf("%.2f %%", values.Humidity)
}

Documentation

Overview

Package am2320 contains the Code to read Temperature and Humidity from the environment with the Aosong AM2320 sensor. Please see the Datasheet for more information: https://akizukidenshi.com/download/ds/aosong/AM2320.pdf

Index

Constants

View Source
const (
	// DefaultI2CAddr is the default Address of the AM2320.
	DefaultI2CAddr = 0x5c
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Sensor

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

Sensor which represents the I²C Device.

func Create

func Create(addr int) Sensor

Create the sensor which read Temperature and Humidity from the given I²C Device. In most cases you should use DefaultI2CAddr as address.

func (Sensor) Read

func (sensor Sensor) Read() (*SensorValues, error)

Read is used to read the actual Temperature and Humidity from the AM2320 Sensor

type SensorValues

type SensorValues struct {
	Temperature, Humidity float32
}

SensorValues contains the results of reading the current Temperature and Humidity detected by the Sensor.

The Temperature is in °C between -40 to 80 Humidity is in % between 100 and 0

Jump to

Keyboard shortcuts

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