bme280

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: BSD-3-Clause Imports: 4 Imported by: 23

Documentation

Overview

Package bme280 provides a driver for the BME280 digital combined humidity and pressure sensor by Bosch.

Datasheet: https://cdn-shop.adafruit.com/datasheets/BST-BME280_DS001-10.pdf

Index

Constants

View Source
const (
	CTRL_MEAS_ADDR        = 0xF4
	CTRL_HUMIDITY_ADDR    = 0xF2
	CTRL_CONFIG           = 0xF5
	REG_PRESSURE          = 0xF7
	REG_CALIBRATION       = 0x88
	REG_CALIBRATION_H1    = 0xA1
	REG_CALIBRATION_H2LSB = 0xE1
	CMD_RESET             = 0xE0

	WHO_AM_I = 0xD0
	CHIP_ID  = 0x60
)

Registers. Names, addresses and comments copied from the datasheet.

View Source
const (
	Period0_5ms  Period = 0b000
	Period62_5ms        = 0b001
	Period125ms         = 0b010
	Period250ms         = 0b011
	Period500ms         = 0b100
	Period1000ms        = 0b101
	Period10ms          = 0b110
	Period20ms          = 0b111
)

Period of standby in normal mode which controls how often measurements are taken

Note Period10ms and Period20ms are out of sequence, but are per the datasheet

View Source
const Address = 0x76

The I2C address which this device listens to.

View Source
const (
	SEALEVEL_PRESSURE float32 = 1013.25 // in hPa
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.24.0

type Config struct {
	Pressure    Oversampling
	Temperature Oversampling
	Humidity    Oversampling
	Period      Period
	Mode        Mode
	IIR         FilterCoefficient
}

Config contains settings for filtering, sampling, and modes of operation

type Device

type Device struct {
	Address uint16

	Config Config
	// contains filtered or unexported fields
}

Device wraps an I2C connection to a BME280 device.

func New

func New(bus drivers.I2C) Device

New creates a new BME280 connection. The I2C bus must already be configured.

This function only creates the Device object, it does not touch the device.

func (*Device) Configure

func (d *Device) Configure()

ConfigureWithSettings sets up the device for communication and read the calibration coefficients.

The default configuration is the Indoor Navigation settings from the BME280 datasheet.

func (*Device) ConfigureWithSettings added in v0.24.0

func (d *Device) ConfigureWithSettings(config Config)

ConfigureWithSettings sets up the device for communication and read the calibration coefficients.

The default configuration if config is left at defaults is the Indoor Navigation settings from the BME280 datasheet.

func (*Device) Connected

func (d *Device) Connected() bool

Connected returns whether a BME280 has been found. It does a "who am I" request and checks the response.

func (*Device) ReadAltitude

func (d *Device) ReadAltitude() (alt int32, err error)

ReadAltitude returns the current altitude in meters based on the current barometric pressure and estimated pressure at sea level. Calculation is based on code from Adafruit BME280 library

https://github.com/adafruit/Adafruit_BME280_Library

func (*Device) ReadHumidity

func (d *Device) ReadHumidity() (int32, error)

ReadHumidity returns the relative humidity in hundredths of a percent

func (*Device) ReadPressure

func (d *Device) ReadPressure() (int32, error)

ReadPressure returns the pressure in milli pascals mPa

func (*Device) ReadTemperature

func (d *Device) ReadTemperature() (int32, error)

ReadTemperature returns the temperature in celsius milli degrees (°C/1000)

func (*Device) Reset

func (d *Device) Reset()

Reset the device

func (*Device) SetMode added in v0.24.0

func (d *Device) SetMode(mode Mode)

SetMode can set the device to Sleep, Normal or Forced mode

Calling this method is optional, Configure can be used to set the initial mode if no mode change is desired. This method is most useful to switch between Sleep and Normal modes.

type FilterCoefficient added in v0.24.0

type FilterCoefficient byte
const (
	Coeff0 FilterCoefficient = iota
	Coeff2
	Coeff4
	Coeff8
	Coeff16
)

IIR filter coefficients, higher values means steadier measurements but slower reaction times

type Mode added in v0.24.0

type Mode byte
const (
	ModeNormal Mode = 0x03
	ModeForced Mode = 0x01
	ModeSleep  Mode = 0x00
)

In normal mode (the default) the sensor takes masurements periodically. In forced mode, the sensor takes a measurement only when requested.

For use-cases with infrequent sampling, forced mode is more power efficient.

type Oversampling added in v0.24.0

type Oversampling byte
const (
	SamplingOff Oversampling = iota
	Sampling1X
	Sampling2X
	Sampling4X
	Sampling8X
	Sampling16X
)

Increasing sampling rate increases precision but also the wait time for measurements. The datasheet has a table of suggested values for oversampling, output data rates, and iir filter coefficients by use case.

type Period added in v0.24.0

type Period byte

Jump to

Keyboard shortcuts

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