ds18b20

package
v3.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Overview

Package ds18b20 interfaces to Dallas Semi / Maxim DS18S20, DS18B20 and MAX31820 1-wire temperature sensors.

Note that both DS18B20 and MAX31820 use family code 0x28.

Both powered sensors and parasitically powered sensors are supported as long as the bus driver can provide sufficient power using an active pull-up.

The DS18B20/DS18S20 alarm functionality and reading/writing the 2 alarm bytes in the EEPROM are not supported.

More details

See https://periph.io/device/ds18b20/ for more details about the device.

Datasheets

https://datasheets.maximintegrated.com/en/ds/DS18B20-PAR.pdf

https://datasheets.maximintegrated.com/en/ds/DS18S20.pdf

https://datasheets.maximintegrated.com/en/ds/MAX31820.pdf

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertAll

func ConvertAll(o onewire.Bus, maxResolutionBits int) error

ConvertAll performs a conversion on all DS18B20 devices on the bus.

During the conversion it places the bus in strong pull-up mode to power parasitic devices and returns when the conversions have completed. This time period is determined by the maximum resolution of all devices on the bus and must be provided.

ConvertAll uses time.Sleep to wait for the conversion to finish, which takes from 94ms to 752ms.

func StartAll added in v3.6.10

func StartAll(o onewire.Bus) error

StartAll starts a conversion on all DS18B20 devices on the bus. Similar to ConvertAll but returns without waiting for conversion to finish. To be used in conjunction with LastTemp() function. Conversion timing must be handled by other means.

Types

type Dev

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

Dev is a handle to a Dallas Semi / Maxim DS18B20 temperature sensor on a 1-wire bus.

func New

func New(o onewire.Bus, addr onewire.Address, resolutionBits int) (*Dev, error)

New returns an object that communicates over 1-wire to the DS18B20 sensor with the specified 64-bit address.

resolutionBits must be in the range 9..12 and determines how many bits of precision the readings have. The resolution affects the conversion time: 9bits:94ms, 10bits:188ms, 11bits:375ms, 12bits:750ms.

A resolution of 10 bits corresponds to 0.25C and tends to be a good compromise between conversion time and the device's inherent accuracy of +/-0.5C.

func (*Dev) Family added in v3.6.12

func (d *Dev) Family() Family

func (*Dev) Halt

func (d *Dev) Halt() error

Halt implements conn.Resource.

func (*Dev) LastTemp

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

LastTemp reads the temperature resulting from the last conversion from the device.

It is useful in combination with ConvertAll.

func (*Dev) Precision

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

Precision implements physic.SenseEnv.

func (*Dev) Sense

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

Sense implements physic.SenseEnv.

func (*Dev) SenseContinuous

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

SenseContinuous implements physic.SenseEnv.

func (*Dev) String

func (d *Dev) String() string

type Family added in v3.6.12

type Family byte

Family code of the specific device type

const DS18B20 Family = 0x28
const DS18S20 Family = 0x10

func (Family) String added in v3.6.12

func (f Family) String() string

Jump to

Keyboard shortcuts

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