bme280spi

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package bme280spi 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 (
	Wrongchip = iota + 1
	FailedToReadCompensation
	FailedToGetReading
	ErrorCalculatingTemperature
	ErrorCalculatingHumidity
	ErrorCalculatingPressure
	BadValue
)

Error codes

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

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 DeviceSPI

type DeviceSPI struct {
	// Chip select pin
	CSB machine.Pin

	Bus drivers.SPI

	Config Config
	// contains filtered or unexported fields
}

DeviceSPI implements the Sensor interface as an SPI connection to a BME280. There is// also an I2C version available, see tinygo.org/x/drivers/bme280

func NewSPI

func NewSPI(csb machine.Pin, spi drivers.SPI, usage sensorUsage) *DeviceSPI

NewSPI returns a new device driver. The pin and SPI interface are not touched, provide a fully configured SPI object and call Configure to start using this device. usage selects soem standard configs 1 - weatherMonitoring (default) 2- humiditySensing 3 - indoorNavigation 4 - gaming

func (*DeviceSPI) Configure

func (d *DeviceSPI) Configure() error

Configure configures the BME280 for use. It configures the CSB pin and configures the BME280. Assumes the SPI interface is running

func (*DeviceSPI) Read

func (d *DeviceSPI) Read() (*SensorReading, error)

Read is a method to read the sensor and return a SensorReading data structure

func (*DeviceSPI) Reset

func (d *DeviceSPI) Reset()

Reset is a method to reset the device

type FilterCoefficient

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

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

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

type Period byte

type Sensor

type Sensor interface {
	Configure() error
	// Callibrate() error
	Read() (*SensorReading, error)
	Reset()
}

Sensor is an interface to a pressure/temperature/humidity/altitude sensor

type SensorReading

type SensorReading struct {
	Pressure    uint32
	Temperature int32
	Humidity    uint32
}

SensorReading is a structure to return a set of pressure/temperature/ humidity/altitude readings from a sensor. There are three implied decimal places ie -1.234 is represented as integer 1234.

type Status

type Status int

Status is used for error reporting - see StatusErr

type StatusErr

type StatusErr struct {
	Status  Status
	Message string
}

StatusErr is an implementation of error interface to include a Status integer

func (StatusErr) Error

func (se StatusErr) Error() string

Jump to

Keyboard shortcuts

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