bme280

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2017 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package bme280 controls a Bosch BME280 device over I²C.

Datasheet

https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280_DS001-11.pdf

Example
bus, err := i2creg.Open("")
if err != nil {
	log.Fatalf("failed to open I²C: %v", err)
}
defer bus.Close()
dev, err := NewI2C(bus, nil)
if err != nil {
	log.Fatalf("failed to initialize bme280: %v", err)
}
env := devices.Environment{}
if err := dev.Sense(&env); err != nil {
	log.Fatal(err)
}
fmt.Printf("%8s %10s %9s\n", env.Temperature, env.Pressure, env.Humidity)
Output:

Index

Examples

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
}

Dev is an handle to a bme280.

func NewI2C

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

NewI2C returns an object that communicates over I²C to BME280 environmental sensor.

It is recommended to call Halt() when done with the device so it stops sampling.

func NewSPI

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

NewSPI returns an object that communicates over SPI to BME280 environmental sensor.

Recommended values are O4x for oversampling, S20ms for standby and FOff for filter if planing to call frequently, else use S500ms to get a bit more than one reading per second.

It is recommended to call Halt() when done with the device so it stops sampling.

When using SPI, the CS line must be used.

func (*Dev) Halt

func (d *Dev) Halt() error

Halt stops the bme280 from acquiring measurements.

It is recommended to call to reduce idle power usage.

func (*Dev) Sense

func (d *Dev) Sense(env *devices.Environment) error

Sense returns measurements as °C, kPa and % of relative humidity.

func (*Dev) String

func (d *Dev) String() string

type Filter

type Filter uint8

Filter specifies the internal IIR filter to get steady measurements without using oversampling. This is mainly used to reduce power consumption.

const (
	FOff Filter = 0
	F2   Filter = 1
	F4   Filter = 2
	F8   Filter = 3
	F16  Filter = 4
)

Possible filtering values.

type Opts

type Opts struct {
	Temperature Oversampling
	Pressure    Oversampling
	Humidity    Oversampling
	Standby     Standby
	Filter      Filter
	Address     uint16
}

Opts is optional options to pass to the constructor.

Recommended (and default) values are O4x for oversampling, S20ms for standby and FOff for filter if planing to call frequently, else use S500ms to get a bit more than one reading per second.

Address is only used on creation of an I²C-device. Its default value is 0x76. It can be set to 0x77. Both values depend on HW configuration of the sensor's SDO pin. This has no effect with NewSPI()

BUG(maruel): Remove the Standby flag and replace with a WaitForNextSample(time.Duration). Then use the closest value automatically.

type Oversampling

type Oversampling uint8

Oversampling affects how much time is taken to measure each of temperature, pressure and humidity.

Temperature must be measured for pressure and humidity to be measured. The duration is approximatively:

duration_in_ms = 1 + 2*temp + 2*press+0.5 + 2*humidy+0.5

Using high oversampling and low standby results in highest power consumption, but this is still below 1mA so we generally don't care.

const (
	No   Oversampling = 0
	O1x  Oversampling = 1
	O2x  Oversampling = 2
	O4x  Oversampling = 3
	O8x  Oversampling = 4
	O16x Oversampling = 5
)

Possible oversampling values.

type Standby

type Standby uint8

Standby is the time the BME280 waits idle between measurements. This reduces power consumption when the host won't read the values as fast as the measurements are done.

const (
	S500us Standby = 0
	S10ms  Standby = 6
	S20ms  Standby = 7
	S62ms  Standby = 1
	S125ms Standby = 2
	S250ms Standby = 3
	S500ms Standby = 4
	S1s    Standby = 5
)

Possible standby values, these determines the refresh rate.

Notes

Bugs

  • Remove the Standby flag and replace with a WaitForNextSample(time.Duration). Then use the closest value automatically.

Directories

Path Synopsis
Package bme280smoketest is leveraged by periph-smoketest to verify that two BME280, one over I²C, one over SPI, read roughly the same temperature, humidity and pressure.
Package bme280smoketest is leveraged by periph-smoketest to verify that two BME280, one over I²C, one over SPI, read roughly the same temperature, humidity and pressure.

Jump to

Keyboard shortcuts

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