mcp9808

package
v3.6.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package mcp9808 controls a Microchip MCP9808 digital I²C temperature sensor.

Features

-40°C and +125°C Operating Range.

User-Selectable Measurement Resolution: +0.5°C, +0.25°C, +0.125°C, +0.0625°C.

User-Programmable Temperature Alerts.

Datasheet

http://ww1.microchip.com/downloads/en/DeviceDoc/25095A.pdf

Index

Examples

Constants

View Source
const (
	Maximum resolution = 0
	Low     resolution = 1
	Medium  resolution = 2
	High    resolution = 3
)

Valid resolution values.

Variables

View Source
var DefaultOpts = Opts{
	Addr: 0x18,
	Res:  Maximum,
}

DefaultOpts is the recommended default options.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	AlertMode  string
	AlertLevel physic.Temperature
}

Alert represents an alert generated by the device.

type Dev

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

Dev is a handle to the mcp9808 sensor.

func New

func New(bus i2c.Bus, opts *Opts) (*Dev, error)

New opens a handle to an mcp9808 sensor.

func (*Dev) Halt

func (d *Dev) Halt() error

Halt put the mcp9808 into shutdown mode. It will not read temperatures while in shutdown mode.

func (*Dev) Precision

func (d *Dev) Precision(e *physic.Env)

Precision implement SenseEnv.

func (*Dev) Sense

func (d *Dev) Sense(e *physic.Env) error

Sense reads the current temperature.

func (*Dev) SenseContinuous

func (d *Dev) SenseContinuous(interval time.Duration) (<-chan physic.Env, error)

SenseContinuous returns measurements as °C, on a continuous basis. The application must call Halt() to stop the sensing when done to stop the sensor and close the channel. It's the responsibility of the caller to retrieve the values from the channel as fast as possible, otherwise the interval may not be respected.

func (*Dev) SenseTemp

func (d *Dev) SenseTemp() (physic.Temperature, error)

SenseTemp reads the current temperature.

Example
Output:

func (*Dev) SenseWithAlerts

func (d *Dev) SenseWithAlerts(lower, upper, critical physic.Temperature) (physic.Temperature, []Alert, error)

SenseWithAlerts reads the ambient temperature and returns an slice of any alerts that have been tripped. Lower must be less than upper which must be less than critical.

Example
Output:

func (*Dev) String

func (d *Dev) String() string

type Opts

type Opts struct {
	Addr int
	Res  resolution
}

Opts holds the configuration options.

Slave Address

Depending which pins the A0, A1 and A2 pins are connected to will change the slave address. Default configuration is address 0x18 (Ax pins to GND). For a full address table see datasheet.

Directories

Path Synopsis
Package mcp9808smoketest implements a smoke test for the mcp9808.
Package mcp9808smoketest implements a smoke test for the mcp9808.

Jump to

Keyboard shortcuts

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