bme280

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2019 License: Apache-2.0 Imports: 6 Imported by: 2

README

BME280 driver

GoDoc Build Status

Go driver for the Bosch BME280 sensor.

Example

// Error handling is omitted
device, err := i2c.Open(&i2c.Devfs{Dev: "/dev/i2c-1"}, bme280.I2CAddr)
b := bme280.New(driver)
err = driver.InitWith(bme280.ModeForced, bme280.Settings{
		Filter:                  bme280.FilterOff,
		Standby:                 bme280.StandByTime1000ms,
		PressureOversampling:    bme280.Oversampling16x,
		TemperatureOversampling: bme280.Oversampling16x,
		HumidityOversampling:    bme280.Oversampling16x,
	})

response, err := driver.Read()

References

Documentation

Overview

Package bme280 implements Bosch BME280 sensor driver in Go It allows for reaching temperature, pressure and humidity data provided by the sensor

It is designed to work well with the golang.org/x/exp/io/i2c package See https://godoc.org/golang.org/x/exp/io/i2c

Index

Constants

View Source
const (
	I2CAddr = 0x77

	// Stand-by modes
	StandByTime1ms    StandByTime = 0x00
	StandByTime62_5ms StandByTime = 0x01
	StandByTime125ms  StandByTime = 0x02
	StandByTime250ms  StandByTime = 0x03
	StandByTime500ms  StandByTime = 0x04
	StandByTime1000ms StandByTime = 0x05
	StandByTime10ms   StandByTime = 0x06
	StandByTime20ms   StandByTime = 0x07

	// Filter coefficients
	FilterOff Filter = 0x00
	Filter2   Filter = 0x01
	Filter4   Filter = 0x02
	Filter8   Filter = 0x03
	Filter16  Filter = 0x04

	// Oversampling
	OversamplingOff Oversampling = 0x00
	Oversampling1x  Oversampling = 0x01
	Oversampling2x  Oversampling = 0x02
	Oversampling4x  Oversampling = 0x03
	Oversampling8x  Oversampling = 0x04
	Oversampling16x Oversampling = 0x05
)

noinspection GoUnusedConst,GoSnakeCaseUsage

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

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

func New

func New(device bus) *Driver

Creates a new BME280 Driver

The device argument can be an instance of i2c.Device struct from golang.org/x/exp/io/i2c package

func (*Driver) Close added in v0.2.0

func (d *Driver) Close() error

func (*Driver) GetMode

func (d *Driver) GetMode() (Mode, error)

Gets the current power mode of the device

Note that either ModeNormal or ModeSleep will be returned. ModeForced is only active during a measurement, the device later returns to ModeSleep. See device datasheet for details.

func (*Driver) GetSettings

func (d *Driver) GetSettings() (Settings, error)

Reads and outputs the current device settings

func (*Driver) Init

func (d *Driver) Init() error

Initializes the Driver

func (*Driver) InitWith

func (d *Driver) InitWith(mode Mode, c Settings) error

Initializes the Driver with provided Mode and Settings

func (*Driver) Read

func (d *Driver) Read() (Response, error)

Reads data from Device

If ModeForced is selected an ad-hoc measurement is performed.

func (*Driver) SetMode

func (d *Driver) SetMode(m Mode) error

func (*Driver) SetSettings

func (d *Driver) SetSettings(s Settings) error

func (*Driver) Sleep

func (d *Driver) Sleep() error

Puts the device to sleep

type Filter

type Filter byte

func (Filter) String

func (i Filter) String() string

type Mode

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

func (Mode) String

func (i Mode) String() string

type Oversampling

type Oversampling byte

func (Oversampling) String

func (i Oversampling) String() string

type Response

type Response struct {
	Temperature float64
	Pressure    float64
	Humidity    float64
}

type Settings

type Settings struct {
	Filter                  Filter
	Standby                 StandByTime
	PressureOversampling    Oversampling
	TemperatureOversampling Oversampling
	HumidityOversampling    Oversampling
}

type StandByTime

type StandByTime byte

func (StandByTime) String

func (i StandByTime) String() string

Jump to

Keyboard shortcuts

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