zircote / bme280

Golang library to read data from Bosch BME280 sensor.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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)
}

About

Golang library to read data from Bosch BME280 sensor.

License:GNU General Public License v3.0


Languages

Language:Go 100.0%