tmp102

package
v3.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Copyright 2024 The Periph Authors. All rights reserved. Use of this source code is governed under the Apache License, Version 2.0 that can be found in the LICENSE file.

tmp102 provides a package for interfacing a Texas Instruments TMP102 I2C temperature sensor. This driver is also compatible with the TMP112 and TMP75 sensors.

Range: -40°C - 125°C

Accuracy: +/- 0.5°C

Resolution: 0.0625°C

For detailed information, refer to the datasheet.

A command line example is available in periph.io/x/devices/cmd/tmp102

Index

Constants

View Source
const (
	// Conversion (sample) Rates. The device default is 4 readings/second.
	RateQuarterHertz ConversionRate = iota
	RateOneHertz
	RateFourHertz
	RateEightHertz

	// ModeComparator sets the device to operate in Comparator mode.
	// Refer to section 6.4.5.1 of the TMP102 datasheet. When used, the
	// ALERT pin of the TMP102 will trigger.
	ModeComparator AlertMode = 0
	// ModeInterrupt sets the device to operate in Interrupt mode.
	// Note that reading the temperature will clear the alert, so be aware
	// if you're using SenseContinuous.
	ModeInterrupt AlertMode = 1

	// The minimum temperature in StandardMode the device can read.
	MinimumTemperature physic.Temperature = physic.ZeroCelsius - 40*physic.Kelvin
	// The maximum temperature in StandardMode the device can read.
	MaximumTemperature physic.Temperature = physic.ZeroCelsius + 125*physic.Kelvin
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AlertMode

type AlertMode byte

type ConversionRate

type ConversionRate byte

type Dev

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

Dev represents a TMP102 sensor.

func NewI2C

func NewI2C(b i2c.Bus, addr uint16, opts *Opts) (*Dev, error)

NewI2C returns a new TMP102 sensor using the specified bus and address. If opts is not supplied, the configuration of the sensor is set to the default on startup.

func (*Dev) GetAlertMode

func (dev *Dev) GetAlertMode() (mode AlertMode, rangeLow, rangeHigh physic.Temperature, err error)

GetAlertMode returns the current alert settings for the device.

func (*Dev) Halt

func (dev *Dev) Halt() error

Halt shuts down the device. If a SenseContinuous operation is in progress, its aborted. Implements conn.Resource

func (*Dev) Precision

func (dev *Dev) Precision(env *physic.Env)

Precision returns the sensor's precision, or minimum value between steps the device can make. The specified precision is 0.0625 degrees Celsius. Note that the accuracy of the device is +/- 0.5 degrees Celsius.

func (*Dev) ReadConfiguration

func (dev *Dev) ReadConfiguration() uint16

readConfiguration returns the device's configuration registers as a 16 bit unsigned integer. Refer to the datasheet for interpretation.

func (*Dev) Sense

func (dev *Dev) Sense(env *physic.Env) error

Sense reads temperature from the device and writes the value to the specified env variable. Implements physic.SenseEnv.

func (*Dev) SenseContinuous

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

SenseContinuous continuously reads from the device and writes the value to the returned channel. Implements physic.SenseEnv. To terminate the continuous read, call Halt().

func (*Dev) SetAlertMode

func (dev *Dev) SetAlertMode(mode AlertMode, rangeLow, rangeHigh physic.Temperature) error

SetAlertMode sets the device to operate in alert (thermostat) mode. Alert mode will set the Alert pin on the device to active mode when the conditions apply. Refer to section 6.4.5 and section 6.5.4 of the TMP102 datasheet.

To detect the alert trigger, you will need to connect the device ALERT pin to a GPIO pin on your SBC and configure that GPIO pin with edge detection, or continuously poll the GPIO pin state. If you choose polling, care should be taken if you're also using SenseContinuous.

func (*Dev) String

func (dev *Dev) String() string

type Opts

type Opts struct {
	SampleRate   ConversionRate
	AlertSetting AlertMode
	AlertLow     physic.Temperature
	AlertHigh    physic.Temperature
}

Opts represents configurable options for the TMP102.

Jump to

Keyboard shortcuts

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