Code Monkey home page Code Monkey logo

go-bsbmp's Introduction

Bosch Sensortec BMP180, BMP280, BME280, BMP388 temperature, atmospheric pressure and humidity sensors

Build Status Go Report Card GoDoc MIT License

BMP180 (pdf reference), BMP280 (pdf reference) and BME280 (pdf reference) are populare sensors among Arduino and Raspberry PI developers. Sensors are compact and quite accurately measuring, working via i2c bus interface: image

BMP388 (pdf reference) is the next generation of the BMP280. Improved temperature coefficient, and the addition of a FIFO. Parameters measured are Temperature and Absolute Atmospheric Pressure.

Here is a library written in Go programming language for Raspberry PI and counterparts, which gives you in the output temperature and atmospheric pressure values (making all necessary i2c-bus interracting and values computing).

Golang usage

func main() {
	// Create new connection to i2c-bus on 1 line with address 0x76.
	// Use i2cdetect utility to find device address over the i2c-bus
	i2c, err := i2c.NewI2C(0x76, 1)
	if err != nil {
		log.Fatal(err)
	}
	defer i2c.Close()
	// Uncomment next line to supress verbose output
	//logger.ChangePackageLogLevel("i2c", logger.InfoLevel)

	sensor, err := bsbmp.NewBMP(bsbmp.BMP280, i2c)
	if err != nil {
		log.Fatal(err)
	}
	// Uncomment next line to supress verbose output
	//logger.ChangePackageLogLevel("bsbmp", logger.InfoLevel)

	// Read temperature in celsius degree
	t, err := sensor.ReadTemperatureC(bsbmp.ACCURACY_STANDARD)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Temprature = %v*C\n", t)
	// Read atmospheric pressure in pascal
	p, err := sensor.ReadPressurePa(bsbmp.ACCURACY_STANDARD)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Pressure = %v Pa\n", p)
	// Read atmospheric pressure in mmHg
	p1, err := sensor.ReadPressureMmHg(bsbmp.ACCURACY_STANDARD)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Pressure = %v mmHg\n", p1)
	// Read atmospheric altitude in meters above sea level, if we assume
	// that pressure at see level is equal to 101325 Pa.
	a, err := sensor.ReadAltitude(bsbmp.ACCURACY_STANDARD)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Altitude = %v m\n", a)
}

Getting help

GoDoc documentation

Installation

$ go get -u github.com/d2r2/go-bsbmp

Troubleshoting

  • How to obtain fresh Golang installation to RPi device (either any RPi clone): If your RaspberryPI golang installation taken by default from repository is outdated, you may consider to install actual golang mannualy from official Golang site. Download tar.gz file containing armv6l in the name. Follow installation instructions.

  • How to enable I2C bus on RPi device: If you employ RaspberryPI, use raspi-config utility to activate i2c-bus on the OS level. Go to "Interfaceing Options" menu, to active I2C bus. Probably you will need to reboot to load i2c kernel module. Finally you should have device like /dev/i2c-1 present in the system.

  • How to find I2C bus allocation and device address: Use i2cdetect utility in format "i2cdetect -y X", where X may vary from 0 to 5 or more, to discover address occupied by peripheral device. To install utility you should run apt install i2c-tools on debian-kind system. i2cdetect -y 1 sample output:

          0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
     00:          -- -- -- -- -- -- -- -- -- -- -- -- --
     10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
     20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
     30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
     40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
     50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
     60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
     70: -- -- -- -- -- -- 76 --    
    

Contribute authors

Contact

Please use Github issue tracker for filing bugs or feature requests.

License

Go-bsbmp is licensed under MIT License.

go-bsbmp's People

Contributors

d2r2 avatar k6td avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

go-bsbmp's Issues

panic: runtime error: integer divide by zero

I've got an error:

panic: runtime error: integer divide by zero

goroutine 40 [running]:
github.com/d2r2/go-bsbmp.(*SensorBMP180).ReadPressureMult10Pa(0x2502020, 0x2500080, 0x3, 0x4087becc, 0xc0000000, 0x4087becc)
	/home/pi/go/src/github.com/d2r2/go-bsbmp/bmp180.go:340 +0xfa4
github.com/d2r2/go-bsbmp.(*BMP).ReadAltitude(0x2500090, 0x3, 0x4087becc, 0x1, 0x4b2038)
	/home/pi/go/src/github.com/d2r2/go-bsbmp/bmp.go:213 +0x38
main.main.func3(0x2500090)

Compilation error

Trying to perform the command:

go get -u github.com/d2r2/go-bsbmp

I get the response:

# github.com/d2r2/go-i2c
../../../go/src/github.com/d2r2/go-i2c/i2c.go:36:26: undefined: I2C_SLAVE

What am I doing wrong?

Incorrect altitude reading

Hello,

I'm doing a quick test with my BMP388, and it displays
INFO Altitude = -24135.46 m

Am I reading it correctly? My altitude is around 156m

Thanks,

(here is the full output:)

2020-05-03T10:21:20.470 [     i2c] DEBUG  Write 2 hex bytes: [1b13]
2020-05-03T10:21:20.471 [     i2c] DEBUG  Write U8 19 to reg 0x1B
2020-05-03T10:21:20.471 [     i2c] DEBUG  Write 1 hex bytes: [03]
2020-05-03T10:21:20.471 [     i2c] DEBUG  Read 1 hex bytes: [70]
2020-05-03T10:21:20.471 [     i2c] DEBUG  Read U8 112 from reg 0x3
2020-05-03T10:21:20.471 [   bsbmp] DEBUG  Busy flag=0x70
2020-05-03T10:21:20.472 [     i2c] DEBUG  Write 2 hex bytes: [1d11]
2020-05-03T10:21:20.472 [     i2c] DEBUG  Write U8 17 to reg 0x1D
2020-05-03T10:21:20.472 [     i2c] DEBUG  Write 1 hex bytes: [03]
2020-05-03T10:21:20.473 [     i2c] DEBUG  Read 1 hex bytes: [70]
2020-05-03T10:21:20.473 [     i2c] DEBUG  Read U8 112 from reg 0x3
2020-05-03T10:21:20.473 [   bsbmp] DEBUG  Busy flag=0x70
2020-05-03T10:21:20.473 [     i2c] DEBUG  Read 3 bytes starting from reg 0x7...
2020-05-03T10:21:20.473 [     i2c] DEBUG  Write 1 hex bytes: [07]
2020-05-03T10:21:20.474 [     i2c] DEBUG  Read 3 hex bytes: [000e7f]
2020-05-03T10:21:20.474 [     i2c] DEBUG  Read 3 bytes starting from reg 0x4...
2020-05-03T10:21:20.474 [     i2c] DEBUG  Write 1 hex bytes: [04]
2020-05-03T10:21:20.475 [     i2c] DEBUG  Read 3 hex bytes: [00ab70]
2020-05-03T10:21:20.475 [   bsbmp] DEBUG  ut=8326656, up=7383808
2020-05-03T10:21:20.475 [     i2c] DEBUG  Write 1 hex bytes: [31]
2020-05-03T10:21:20.477 [     i2c] DEBUG  Read 21 hex bytes: [246b9c49f668ffbdf523009765b87af3f6d3400ec4]
2020-05-03T10:21:20.477 [   bsbmp] DEBUG  t_lin=1497076
2020-05-03T10:21:20.477 [   bsbmp] DEBUG  ----------
2020-05-03T10:21:20.477 [   bsbmp] DEBUG  partial_data1=2241236549776
2020-05-03T10:21:20.477 [   bsbmp] DEBUG  partial_data2=35019321090
2020-05-03T10:21:20.478 [   bsbmp] DEBUG  partial_data3=204791348203643
2020-05-03T10:21:20.478 [   bsbmp] DEBUG  partial_data4=-63997296313638
2020-05-03T10:21:20.478 [   bsbmp] DEBUG  partial_data5=-466177202353408
2020-05-03T10:21:20.478 [   bsbmp] DEBUG  partial_data6=197267091319947264
2020-05-03T10:21:20.478 [   bsbmp] DEBUG  offset=3856896776478295514
2020-05-03T10:21:20.478 [   bsbmp] DEBUG  ----------
2020-05-03T10:21:20.478 [   bsbmp] DEBUG  partial_data2=0
2020-05-03T10:21:20.478 [   bsbmp] DEBUG  partial_data4=313773116968640
2020-05-03T10:21:20.478 [   bsbmp] DEBUG  partial_data5=-59686858178691072
2020-05-03T10:21:20.478 [   bsbmp] DEBUG  sensitivity=-1222990638783574336
2020-05-03T10:21:20.478 [   bsbmp] DEBUG  ----------
2020-05-03T10:21:20.478 [   bsbmp] DEBUG  ----------
2020-05-03T10:21:20.478 [   bsbmp] DEBUG  partial_data1=-538249496372655104
2020-05-03T10:21:20.478 [   bsbmp] DEBUG  partial_data2=20959064
2020-05-03T10:21:20.479 [   bsbmp] DEBUG  partial_data3=1108528984
2020-05-03T10:21:20.479 [   bsbmp] DEBUG  partial_data4=999165671422
2020-05-03T10:21:20.479 [   bsbmp] DEBUG  partial_data5=14409467730412373
2020-05-03T10:21:20.479 [   bsbmp] DEBUG  partial_data6=54520620580864
2020-05-03T10:21:20.479 [   bsbmp] DEBUG  ----------
2020-05-03T10:21:20.479 [   bsbmp] DEBUG  partial_data2=-49915118940
2020-05-03T10:21:20.479 [   bsbmp] DEBUG  partial_data3=-2879403551172840
2020-05-03T10:21:20.479 [   bsbmp] DEBUG  partial_data4=437504761926158307
2020-05-03T10:21:20.479 [    main] INFO  Altitude = -24135.46 m

Debug level logging annoying

Can logger be set manually? Seems like you left it at logger.DebugLevel. Prints out a LOT of stuff I don't need.

see logger.go

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.