max31865

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 9 Imported by: 2

README

mikesmitty/max31865

This is a library for using the MAX31865 PT100/PT1000 RTD temperature sensor amplifier in Go using Periph. Originally based on the vemo-france/max31865 port of Adafruit's MAX31865 library, though it has been fairly substantially rewritten. Intended for use with Adafruit's MAX31865 breakout boards PT100/PT1000 on any device supported by Periph.

Installation

go get github.com/mikesmitty/max31865

Usage

package main

import (
	"fmt"

	"github.com/mikesmitty/max31865"
	"periph.io/x/conn/v3/spi/spireg"
	"periph.io/x/host/v3"
)

func main() {
	sb, _ := spireg.Open(yourSpiBus)
	dev, _ := max31865.New(sb, max31865.AdafruitPT100())

	// Perform a one-off reading with Sense()
	var e physic.Env
	_ := dev.Sense(&e)
	fmt.Printf("Temperature: %0.2f\n", e.Temperature.Celsius())

	// Alternatively, SenseContinuous() returns a channel for continuous updates
	c, _ := dev.SenseContinuous(updateInterval)
	for {
		e := <-c
		fmt.Printf("Temperature: %0.2f\n", e.Temperature.Celsius())
	}
}

TODO

  • Improve documentation
  • Add tests
  • Surface hardware fault error codes rather than just clearing them like the Adafruit library does

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dev

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

func New

func New(p spi.Port, opts *Opts) (*Dev, error)

func (*Dev) CheckError added in v0.3.0

func (d *Dev) CheckError() error

func (*Dev) Halt

func (d *Dev) Halt() error

Halt stops the MAX31865 from acquiring measurements as initiated by SenseContinuous().

It is recommended to call this function before terminating the process to reduce idle power usage and a goroutine leak.

func (*Dev) Precision

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

15-Bit ADC Resolution; Nominal temperature resolution varies due to RTD non-linearity

func (*Dev) Sense

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

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) SetThreshold added in v0.3.1

func (d *Dev) SetThreshold(lower, upper uint16) error

func (*Dev) String

func (d *Dev) String() string

type Opts

type Opts struct {
	// ContinuousMode removes delays by leaving the bias voltage enabled between
	// readings. This slightly increases power consumption and self-heating, but
	// is useful when taking measurements as quickly as possible (< 55/66ms)
	ContinuousMode bool
	// 60Hz noise is filtered by default, enable to filter 50Hz noise instead.
	Filter50Hz  bool
	Port        string
	RefResistor float64
	RTDType     RTDType
	WireCount   WireCount
}

Opts holds various configuration options for the sensor

func AdafruitPT100

func AdafruitPT100() *Opts

func AdafruitPT1000

func AdafruitPT1000() *Opts

func DefaultOptions

func DefaultOptions() *Opts

type RTDType

type RTDType int
const (
	RTDPT100 RTDType = iota
	RTDPT1000
)

type WireCount

type WireCount int
const (
	WireCount2 WireCount = iota + 2
	WireCount3
	WireCount4
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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