bme280

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2019 License: GPL-3.0 Imports: 4 Imported by: 8

README

bme280

GoDoc

Golang library to read data from Bosch BME280 sensor. It requires library to talk to the device via following interface:

type bus interface {
	ReadReg(byte, []byte) error
	WriteReg(byte, []byte) error
}

One of the libraries which matches this interface is experimental standard I/O lib.

Example usage

package main

import (
	"fmt"

	"golang.org/x/exp/io/i2c"

	"github.com/quhar/bme280"
)

func main() {

	d, err := i2c.Open(&i2c.Devfs{Dev: "/dev/i2c-1"}, bme280.I2CAddr)
	if err != nil {
		panic(err)
	}

	b := bme280.New(d)
	err = b.Init()

	t, p, h, err := b.EnvData()

	if err != nil {
		panic(err)
	}

	fmt.Printf("Temp: %fC, Press: %fhPa, Hum: %f%%\n", t, p, h)
}

Documentation

Overview

bmw280 reads sensor data from Bosh BME280 sensor. TODO: unit tests.

Index

Constants

View Source
const (
	T1 byte = 0x88 + iota*2
	T2
	T3
	P1
	P2
	P3
	P4
	P5
	P6
	P7
	P8
	P9
	H1 byte = 0xA1
	H2 byte = 0xE1
	H3 byte = 0xE3
	H4 byte = 0xE4
	H5 byte = 0xE5
	H6 byte = 0xE7
)

Compensation registers addresses.

View Source
const (
	TempCompAddr  byte = 0x88
	PressCompAddr byte = 0x8E
	H1CompAddr    byte = 0xA1
	H2CompAddr    byte = 0xE1
)
View Source
const (
	HumAddr   byte = 0xFD
	TempAddr  byte = 0xFA
	PressAddr byte = 0xF7
	DataAddr  byte = 0xF7
)

Data registers addresses.

View Source
const (
	IDAddr       byte = 0xD0
	ResetAddr    byte = 0xE0
	CtrlHumAddr  byte = 0xF2
	StatusAddr   byte = 0xF3
	CtrlMeasAddr byte = 0xF4
	ConfigAddr   byte = 0xF5
)

Other registers addresses.

View Source
const (
	// I2CAddr is default BME280 I2C address.
	I2CAddr int = 0x77
	// ResetVal is a value which when written to ResetAddr resets the sensor.
	ResetVal byte = 0xB6
	// IDVal is a ID value of the sensor.
	IDVal byte = 0x60
)

General constants.

View Source
const (
	OverSmpl1 byte
	OverSmpl2
	OverSmpl4
	OverSmpl8
	OverSmpl16
)

Oversampling constants.

View Source
const (
	SleepMode  byte = 0x00
	ForcedMode byte = 0x01
	NormalMode byte = 0x03
)

Modes of operation.

View Source
const (
	FilterOff byte = iota << 2
	Filter2
	Filter4
	Filter8
	Filter16
)

Filter settins

View Source
const (
	// Standby for 0.5 ms.
	Stndby05 byte = iota << 5
	// Standby for 62.5 ms.
	Stndby625
	// Standby for 125 ms.
	Stndby125
	// Standby for 250 ms.
	Stndby250
	// Standby for 500 ms.
	Stndby500
	// Standby for 1000 ms.
	Stbdby1000
	// Standby for 10 ms.
	Stndby10
	// Standby for 20 ms.
	Stndby20
)

Normal mode standby modes.

View Source
const (
	Celsius = iota
	Fahrenheit
	Kelvin
)

Available temperature units.

View Source
const (
	HPa = iota
	Bar
	PSI
)

Available pressure units.

Variables

This section is empty.

Functions

This section is empty.

Types

type BME280

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

BME280 is an object representing BME280 sensor.

func New

func New(dev bus, opts ...Option) *BME280

New returns new BME280 object. New object has following default values: mode = ForcedMode tempOverSmpl = 16 pressOverSmpl = 16 humOverSmpl = 16 filter = off standby = 500ms Temperature units Celsius Presure units hPa

func (*BME280) EnvData

func (b *BME280) EnvData() (temp, press, hum float64, err error)

EnvData returns compensated temperature, pressure and humidity.

func (*BME280) Hum

func (b *BME280) Hum() (float64, error)

Hum returns humidity

func (*BME280) Init

func (b *BME280) Init() error

init initializes BME280 and loads calibration data

func (*BME280) Press

func (b *BME280) Press() (float64, error)

Press returns pressure in set units.

func (*BME280) RawData

func (b *BME280) RawData() (temp, press, hum int32, err error)

RawData returnes un-compensated data read from the sensor.

func (*BME280) SetPressUnit

func (b *BME280) SetPressUnit(unit int)

SetPressUnit sets pressure unit.

func (*BME280) SetTempUnit

func (b *BME280) SetTempUnit(unit int)

SetTempUnit sets temperature unit.

func (*BME280) Temp

func (b *BME280) Temp() (float64, error)

Temp returns temperature in set units.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is an interface used to set various options in BME280 object.

func Filter

func Filter(f byte) Option

Filter sets default IIR filter value.

func HumOverSmpl

func HumOverSmpl(o byte) Option

HumOverSmpl sets default oversampling for humidity.

func Mode

func Mode(m byte) Option

Mode sets default sensors Mode of operation (Sleep, Standby, Forced).

func PressOverSmpl

func PressOverSmpl(o byte) Option

PressOverSmpl sets default oversampling for pressure.

func PressUnit

func PressUnit(u int) Option

PressUnits set default pressure units.

func Standby

func Standby(s byte) Option

Standby sets default Tstandby for Normal mode.

func TempOverSmpl

func TempOverSmpl(o byte) Option

TempOverSmpl sets default oversampling for temperature.

func TempUnit

func TempUnit(u int) Option

TempUnits set default temperature units.

Directories

Path Synopsis
i2c is example usage of BME280 library with I2C bus.
i2c is example usage of BME280 library with I2C bus.

Jump to

Keyboard shortcuts

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