bme280_go

package module
v0.0.0-...-35c86ff Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: MIT Imports: 4 Imported by: 2

README

bme20_go

A Native Golang driver for the Adafruit BME280 Breakout board.

Usage

Create a BME Object:

bme := BME280{}

Initialize it with the proper device (for the Raspberry Pi 3, this works):

dev := "/dev/i2c-1"
r := bme.bme280Init(dev)

Any return other than -256 is success.

To read values:

readings := bme.bme280ReadValues()

readings will be a 3-value array of ints. Temperature, Pressure, Humidity, in that order. Temperature is the Temperature in C * 100 so to get the actual temperature:

f := float64(float64(readings[0]) / 100.00)

Pressure is currently not properly implemented, and should not be iused. Humidity is returned as realtive humidity * 1024, so to get the humidity value:

f = float64(rets[2]) / 1024.00

It's a good idea to call

defer bme.Dev.Close()

after the call to init so that the device will be closed after you're done with it.

Error Handling

There is none at this point. You have to handle them. but if the return array has a -256 for a value in a spot, it's likely that an error occured.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BME280

type BME280 struct {
	Dev    *i2c.Device
	Config bme280Config
	// contains filtered or unexported fields
}

BME280 holds the device and all configuration data for the sensor

func (*BME280) BME280Init

func (bme280 *BME280) BME280Init(channel string, addr int) int

BME280Init Opens a file system handle to the I2C device reads the calibration data and sets the device into auto sensing mode

func (*BME280) BME280ReadAltitude

func (bme280 *BME280) BME280ReadAltitude(seaLevel float32) float32

func (*BME280) BME280ReadHumidity

func (bme280 *BME280) BME280ReadHumidity() float32

func (*BME280) BME280ReadPressure

func (bme280 *BME280) BME280ReadPressure() float32

func (*BME280) BME280ReadTemperature

func (bme280 *BME280) BME280ReadTemperature() float32

func (*BME280) BME280ReadValues

func (bme280 *BME280) BME280ReadValues() BMEData

bme280ReadValues Reads the sensor register values and translate them into calibrated readings using the previously loaded calibration data Temperature is expressed in Celsius degrees as T * 100 (for 2 decimal places) Pressure is <future> Humidity is express as H * 1024 (10 bit fraction)

func (*BME280) BME280SeaLevelForAltitude

func (bme280 *BME280) BME280SeaLevelForAltitude(altitude float32, atmospheric float32) float32

!

  • Calculates the pressure at sea level (in hPa) from the specified
  • altitude (in meters), and atmospheric pressure (in hPa).
  • @param altitude Altitude in meters
  • @param atmospheric Atmospheric pressure in hPa
  • @returns the pressure at sea level (in hPa) from the specified altitude

func (*BME280) BMESetAddress

func (bme280 *BME280) BMESetAddress(addr int)

type BMEData

type BMEData struct {
	Temperature float32
	Humidity    float32
	Pressure    float32
	Altitude    float32
}

BMEData contains the read-values from the sensor

Jump to

Keyboard shortcuts

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