bmp388

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2021 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package bmp388 provides a driver for Bosch's BMP388 digital temperature & pressure sensor. The datasheet can be found here: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp388-ds001.pdf

Index

Constants

View Source
const (
	RegChipId  byte = 0x00 // useful for checking the connection
	RegCali    byte = 0x31 // pressure & temperature compensation calibration coefficients
	RegPress   byte = 0x04 // start of pressure data registers
	RegTemp    byte = 0x07 // start of temperature data registers
	RegPwrCtrl byte = 0x1B // measurement mode & pressure/temperature sensor power register
	RegOSR     byte = 0x1C // oversampling settings register
	RegODR     byte = 0x1D //
	RegCmd     byte = 0x7E // miscellaneous command register
	RegStat    byte = 0x03 // sensor status register
	RegErr     byte = 0x02 // error status register
	RegIIR     byte = 0x1F
)
View Source
const (
	ChipId    byte = 0x50 // correct response if reading from chip id register
	PwrPress  byte = 0x01 // power on pressure sensor
	PwrTemp   byte = 0x02 // power on temperature sensor
	SoftReset byte = 0xB6 // command to reset all user configuration
	DRDYPress byte = 0x20 // for checking if pressure data is ready
	DRDYTemp  byte = 0x40 // for checking if pressure data is ready
)
View Source
const Address byte = 0x77 // default I2C address

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Pressure    Oversampling
	Temperature Oversampling
	Mode        Mode
	ODR         OutputDataRate
	IIR         FilterCoefficient
}

Config contains settings for filtering, sampling, and modes of operation

type Device

type Device struct {
	Address uint8

	Config Config
	// contains filtered or unexported fields
}

Device wraps the I2C connection and configuration values for the BMP388

func New

func New(bus drivers.I2C) Device

New returns a bmp388 struct with the default I2C address. Configure must also be called after instanting

func (*Device) Configure

func (d *Device) Configure(config Config) (err error)

Configure can enable settings on the BMP388 and reads the calibration coefficients

func (*Device) Connected

func (d *Device) Connected() bool

Connected tries to reach the bmp388 and check its chip id register. Returns true if it was able to successfully communicate over i2c and returns the correct value

func (*Device) ReadPressure

func (d *Device) ReadPressure() (int32, error)

ReadPressure returns the pressure in centipascals, i.e 10132520 / 100 = 101325.20 Pa

func (*Device) ReadTemperature

func (d *Device) ReadTemperature() (int32, error)

ReadTemperature returns the temperature in centicelsius, i.e 2426 / 100 = 24.26 C

func (*Device) SetMode

func (d *Device) SetMode(mode Mode) error

SetMode changes the run mode of the sensor, NORMAL is the one to use for most cases. Use FORCED if you plan to take measurements infrequently and want to conserve power. SLEEP will of course put the sensor to sleep

func (*Device) SoftReset

func (d *Device) SoftReset() error

SoftReset commands the BMP388 to reset of all user configuration settings

type FilterCoefficient

type FilterCoefficient byte
const (
	Coeff0 FilterCoefficient = iota
	Coeff1
	Coeff3
	Coeff7
	Coeff15
	Coeff31
	Coeff63
	Coeff127
)

IIR filter coefficients, higher values means steadier measurements but slower reaction times

type Mode

type Mode byte
const (
	Normal Mode = 0x30
	Forced Mode = 0x16
	Sleep  Mode = 0x00
)

The difference between forced and normal mode is the bmp388 goes to sleep after taking a measurement in forced mode. Set it to forced if you intend to take measurements sporadically and want to save power. The driver will handle waking the sensor up when the sensor is in forced mode.

type OutputDataRate

type OutputDataRate byte
const (
	Odr200 OutputDataRate = iota
	Odr100
	Odr50
	Odr25
	Odr12p5
	Odr6p25
	Odr3p1
	Odr1p5
	Odr0p78
	Odr0p39
	Odr0p2
	Odr0p1
	Odr0p05
	Odr0p02
	Odr0p01
	Odr0p006
	Odr0p003
	Odr0p0015
)

Output data rates in Hz. If increasing the sampling rates you need to decrease the output data rates, else the bmp388 will freeze and Configure() will return a configuration error message. In that case keep decreasing the data rate until the bmp is happy

type Oversampling

type Oversampling byte
const (
	Sampling1X Oversampling = iota
	Sampling2X
	Sampling4X
	Sampling8X
	Sampling16X
	Sampling32X
)

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.

Jump to

Keyboard shortcuts

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