bmxx80

package
v3.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package bmxx80 controls a Bosch BMP180/BME280/BMP280 device over I²C, or SPI for the BMx280.

BMx280

https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280_DS001-11.pdf https://www.mouser.com/datasheet/2/783/BST-BME280_DS001-11-844833.pdf

https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMP280-DS001-18.pdf

https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMP180-DS000-121.pdf

The font the official datasheet on page 15 is hard to read, a copy with readable text can be found here:

https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf

Notes on the BMP180 datasheet

The results of the calculations in the algorithm on page 15 are partly wrong. It looks like the original authors used non-integer calculations and some nubers were rounded. Take the results of the calculations with a grain of salt.

Example
package main

import (
	"fmt"
	"log"

	"periph.io/x/periph/conn/i2c/i2creg"
	"periph.io/x/periph/conn/physic"
	"periph.io/x/periph/devices/bmxx80"
	"periph.io/x/periph/host"
)

func main() {
	// Make sure periph is initialized.
	if _, err := host.Init(); err != nil {
		log.Fatal(err)
	}

	// Use i2creg I²C bus registry to find the first available I²C bus.
	b, err := i2creg.Open("")
	if err != nil {
		log.Fatalf("failed to open I²C: %v", err)
	}
	defer b.Close()

	d, err := bmxx80.NewI2C(b, 0x76, &bmxx80.DefaultOpts)
	if err != nil {
		log.Fatalf("failed to initialize bme280: %v", err)
	}
	e := physic.Env{}
	if err := d.Sense(&e); err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%8s %10s %9s\n", e.Temperature, e.Pressure, e.Humidity)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultOpts = Opts{
	Temperature: O4x,
	Pressure:    O4x,
	Humidity:    O4x,
}

DefaultOpts is the recommended default options.

Functions

This section is empty.

Types

type Dev

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

Dev is a handle to an initialized BMxx80 device.

The actual device type was auto detected.

func NewI2C

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

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

The address must be 0x76 or 0x77. BMP180 uses 0x77. BME280/BMP280 default to 0x76 and can optionally use 0x77. The value used depends on HW configuration of the sensor's SDO pin.

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 either a BME280 or BMP280 environmental sensor.

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 BMxx80 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)

Precision implements physic.SenseEnv.

func (*Dev) Sense

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

Sense requests a one time measurement as °C, kPa and % of relative humidity.

The very first measurements may be of poor quality.

func (*Dev) SenseContinuous

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

SenseContinuous returns measurements as °C, kPa and % of relative humidity 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) String

func (d *Dev) String() string

type Filter

type Filter uint8

Filter specifies the internal IIR filter to get steadier measurements.

Oversampling will get better measurements than filtering but at a larger power consumption cost, which may slightly affect temperature measurement.

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

Possible filtering values.

The higher the filter, the slower the value converges but the more stable the measurement is.

type Opts

type Opts struct {
	// Temperature can only be oversampled on BME280/BMP280.
	//
	// Temperature must be measured for pressure and humidity to be measured.
	Temperature Oversampling
	// Pressure can be oversampled up to 8x on BMP180 and 16x on BME280/BMP280.
	Pressure Oversampling
	// Humidity sensing is only supported on BME280. The value is ignored on other
	// devices.
	Humidity Oversampling
	// Filter is only used while using SenseContinuous() and is only supported on
	// BMx280.
	Filter Filter
}

Opts defines the options for the device.

Recommended sensing settings as per the datasheet:

→ Weather monitoring: manual sampling once per minute, all sensors O1x. Power consumption: 0.16µA, filter NoFilter. RMS noise: 3.3Pa / 30cm, 0.07%RH.

→ Humidity sensing: manual sampling once per second, pressure Off, humidity and temperature O1X, filter NoFilter. Power consumption: 2.9µA, 0.07%RH.

→ Indoor navigation: continuous sampling at 40ms with filter F16, pressure O16x, temperature O2x, humidity O1x, filter F16. Power consumption 633µA. RMS noise: 0.2Pa / 1.7cm.

→ Gaming: continuous sampling at 40ms with filter F16, pressure O4x, temperature O1x, humidity Off, filter F16. Power consumption 581µA. RMS noise: 0.3Pa / 2.5cm.

See the datasheet for more details about the trade offs.

type Oversampling

type Oversampling uint8

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

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

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

Possible oversampling values.

The higher the more time and power it takes to take a measurement. Even at 16x for all 3 sensors, it is less than 100ms albeit increased power consumption may increase the temperature reading.

func (Oversampling) String

func (o Oversampling) String() string

Directories

Path Synopsis
Package bmx280smoketest is leveraged by periph-smoketest to verify that two BME280/BMP280, one over I²C, one over SPI, read roughly the same temperature, humidity and pressure.
Package bmx280smoketest is leveraged by periph-smoketest to verify that two BME280/BMP280, 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