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://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 ¶
bus, err := i2creg.Open("") if err != nil { log.Fatalf("failed to open I²C: %v", err) } defer bus.Close() dev, err := NewI2C(bus, 0x76, nil) if err != nil { log.Fatalf("failed to initialize bme280: %v", err) } env := devices.Environment{} if err := dev.Sense(&env); err != nil { log.Fatal(err) } fmt.Printf("%8s %10s %9s\n", env.Temperature, env.Pressure, env.Humidity)
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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 ¶
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 ¶
NewSPI returns an object that communicates over SPI to BME280 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 ¶
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) Sense ¶
func (d *Dev) Sense(env *devices.Environment) 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 ¶
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.
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.
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 is optional options to pass to the constructor.
Recommended (and default) values are O4x for oversampling.
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. |