bmxx80 provides support for a popular sensor family from Bosch:
BMP180 can be used over I²C. BME280 and BMP280 can use either I²C or SPI.
They all provide low precision temperature measurement.
The driver as the following functionality:
Use cmd/bmxx80 to retrieve measurement from the device.
Purpose: gather temperature, pressure and relative humidity (BME280 only).
This example uses either a BME280 or BMP280 connected via I²C.
package main
import (
"fmt"
"log"
"periph.io/x/conn/v3/i2c/i2creg"
"periph.io/x/conn/v3/physic"
"periph.io/x/devices/v3/bmxx80"
"periph.io/x/host/v3"
)
func main() {
// Load all the drivers:
if _, err := host.Init(); err != nil {
log.Fatal(err)
}
// Open a handle to the first available I²C bus:
bus, err := i2creg.Open("")
if err != nil {
log.Fatal(err)
}
defer bus.Close()
// Open a handle to a bme280/bmp280 connected on the I²C bus using default
// settings:
dev, err := bmxx80.NewI2C(bus, 0x76, &bmxx80.DefaultOpts)
if err != nil {
log.Fatal(err)
}
defer dev.Halt()
// Read temperature from the sensor:
var env physic.Env
if err = dev.Sense(&env); err != nil {
log.Fatal(err)
}
fmt.Printf("%8s %10s %9s\n", env.Temperature, env.Pressure, env.Humidity)
}
Setup for BME280/BMP280 smoke test:
It confirms that two BME280/BMP280 sensors can be driven simultaneously, one connected via I²C, one via SPI. They shall measure mostly the same atmospheric properties.
These links are for the BME280:
The periph authors do not endorse any specific seller. These are only provided for your convenience.