bme280

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2025 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package bme280 provides a driver for the BME280 temperature, humidity, and pressure sensor using I2C communication.

Index

Constants

View Source
const (
	DefaultI2CBus     = "/dev/i2c-1"
	DefaultI2CAddress = 0x77
)

Variables

View Source
var (
	ErrInitFailed    = errors.New("failed to initialize BME280")
	ErrReadFailed    = errors.New("failed to read from BME280")
	ErrMarshalFailed = errors.New("failed to marshal BME280 data")
)

Functions

func ConvertCtoF

func ConvertCtoF(celsius float64) float64

ConvertCtoF converts Celsius to Fahrenheit

Types

type BME280

type BME280 struct {
	*devices.DeviceBase[Env]
	// contains filtered or unexported fields
}

BME280 represents an I2C temperature, humidity and pressure sensor. It defaults to address 0x77 and implements the device.Device interface.

func New

func New(id, bus string, addr int) (b *BME280, err error)

Create a new BME280 at the give bus and address. Defaults are typically /dev/i2c-1 address 0x99 func New(id, bus string, addr int) (*BME280, error) {

func (*BME280) Close

func (b *BME280) Close() error

func (*BME280) Get

func (b *BME280) Get() (resp Env, err error)

Read one Response from the sensor. If this device is being mocked we will make up some random floating point numbers between 0 and 100.

func (*BME280) Name added in v0.0.3

func (b *BME280) Name() string

func (*BME280) Open

func (b *BME280) Open() error

Init opens the i2c bus at the specified address and gets the device ready for reading

func (*BME280) Set

func (b *BME280) Set(v Env) error

type BME280Config

type BME280Config struct {
	Mode       bme280.Mode
	Filter     bme280.Filter
	Standby    bme280.StandByTime
	Oversample struct {
		Pressure    bme280.Oversampling
		Temperature bme280.Oversampling
		Humidity    bme280.Oversampling
	}
}

BME280Config holds the configuration for the BME280 sensor

func DefaultConfig

func DefaultConfig() BME280Config

DefaultConfig returns the default configuration

type BME280Mock added in v0.0.3

type BME280Mock struct {
	*devices.DeviceBase[Env]

	Env
	// contains filtered or unexported fields
}

BME280Mock provides a mocked BME280 for testing purposes

func (*BME280Mock) Close added in v0.0.3

func (b *BME280Mock) Close() error

func (*BME280Mock) Get added in v0.0.3

func (b *BME280Mock) Get() (Env, error)

func (*BME280Mock) Open added in v0.0.3

func (b *BME280Mock) Open() error

func (*BME280Mock) Set added in v0.0.3

func (b *BME280Mock) Set(v Env) error

type Env

type Env bme280.Response

func (*Env) JSON added in v0.0.3

func (e *Env) JSON() ([]byte, error)

Jump to

Keyboard shortcuts

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