| 1 |
Bosch Sensortec BMP180, BMP280, BME280, BMP388 temperature, atmospheric pressure and humidity sensors |
| 2 |
============================================================================================= |
| 3 |
|
| 4 |
[](https://travis-ci.org/d2r2/go-bsbmp) |
| 5 |
[](https://goreportcard.com/report/github.com/d2r2/go-bsbmp) |
| 6 |
[](https://godoc.org/github.com/d2r2/go-bsbmp) |
| 7 |
[](./LICENSE) |
| 8 |
|
| 9 |
BMP180 ([pdf reference](https://raw.github.com/d2r2/go-bsbmp/master/docs/BST-BMP180-DS000-09.pdf)), BMP280 ([pdf reference](https://raw.github.com/d2r2/go-bsbmp/master/docs/BST-BMP280-DS001-11.pdf)) and BME280 ([pdf reference](https://raw.github.com/d2r2/go-bsbmp/master/docs/BST-BME280_DS001-12.pdf)) are populare sensors among Arduino and Raspberry PI developers. |
| 10 |
Sensors are compact and quite accurately measuring, working via i2c bus interface: |
| 11 |
 |
| 12 |
|
| 13 |
BMP388 ([pdf reference](https://raw.github.com/d2r2/go-bsbmp/master/docs/BST-BMP388-DS001-11.pdf)) is the next generation of the BMP280. Improved temperature coefficient, and the addition of a FIFO. Parameters measured are Temperature and Absolute Atmospheric Pressure. |
| 14 |
|
| 15 |
Here is a library written in [Go programming language](https://golang.org/) 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). |
| 16 |
|
| 17 |
Golang usage |
| 18 |
------------ |
| 19 |
|
| 20 |
|
| 21 |
```go |
| 22 |
func main() { |
| 23 |
// Create new connection to i2c-bus on 1 line with address 0x76. |
| 24 |
// Use i2cdetect utility to find device address over the i2c-bus |
| 25 |
i2c, err := i2c.NewI2C(0x76, 1) |
| 26 |
if err != nil { |
| 27 |
log.Fatal(err) |
| 28 |
} |
| 29 |
defer i2c.Close() |
| 30 |
// Uncomment next line to supress verbose output |
| 31 |
//logger.ChangePackageLogLevel("i2c", logger.InfoLevel) |
| 32 |
|
| 33 |
sensor, err := bsbmp.NewBMP(bsbmp.BMP280, i2c) |
| 34 |
if err != nil { |
| 35 |
log.Fatal(err) |
| 36 |
} |
| 37 |
// Uncomment next line to supress verbose output |
| 38 |
//logger.ChangePackageLogLevel("bsbmp", logger.InfoLevel) |
| 39 |
|
| 40 |
// Read temperature in celsius degree |
| 41 |
t, err := sensor.ReadTemperatureC(bsbmp.ACCURACY_STANDARD) |
| 42 |
if err != nil { |
| 43 |
log.Fatal(err) |
| 44 |
} |
| 45 |
log.Printf("Temprature = %v*C\n", t) |
| 46 |
// Read atmospheric pressure in pascal |
| 47 |
p, err := sensor.ReadPressurePa(bsbmp.ACCURACY_STANDARD) |
| 48 |
if err != nil { |
| 49 |
log.Fatal(err) |
| 50 |
} |
| 51 |
log.Printf("Pressure = %v Pa\n", p) |
| 52 |
// Read atmospheric pressure in mmHg |
| 53 |
p1, err := sensor.ReadPressureMmHg(bsbmp.ACCURACY_STANDARD) |
| 54 |
if err != nil { |
| 55 |
log.Fatal(err) |
| 56 |
} |
| 57 |
log.Printf("Pressure = %v mmHg\n", p1) |
| 58 |
// Read atmospheric altitude in meters above sea level, if we assume |
| 59 |
// that pressure at see level is equal to 101325 Pa. |
| 60 |
a, err := sensor.ReadAltitude(bsbmp.ACCURACY_STANDARD) |
| 61 |
if err != nil { |
| 62 |
log.Fatal(err) |
| 63 |
} |
| 64 |
log.Printf("Altitude = %v m\n", a) |
| 65 |
} |
| 66 |
``` |
| 67 |
|
| 68 |
|
| 69 |
Getting help |
| 70 |
------------ |
| 71 |
|
| 72 |
GoDoc [documentation](http://godoc.org/github.com/d2r2/go-bsbmp) |
| 73 |
|
| 74 |
Installation |
| 75 |
------------ |
| 76 |
|
| 77 |
```bash |
| 78 |
$ go get -u github.com/d2r2/go-bsbmp |
| 79 |
``` |
| 80 |
|
| 81 |
Troubleshoting |
| 82 |
-------------- |
| 83 |
|
| 84 |
- *How to obtain fresh Golang installation to RPi device (either any RPi clone):* |
| 85 |
If your RaspberryPI golang installation taken by default from repository is outdated, you may consider |
| 86 |
to install actual golang mannualy from official Golang [site](https://golang.org/dl/). Download |
| 87 |
tar.gz file containing armv6l in the name. Follow installation instructions. |
| 88 |
|
| 89 |
- *How to enable I2C bus on RPi device:* |
| 90 |
If you employ RaspberryPI, use raspi-config utility to activate i2c-bus on the OS level. |
| 91 |
Go to "Interfaceing Options" menu, to active I2C bus. |
| 92 |
Probably you will need to reboot to load i2c kernel module. |
| 93 |
Finally you should have device like /dev/i2c-1 present in the system. |
| 94 |
|
| 95 |
- *How to find I2C bus allocation and device address:* |
| 96 |
Use i2cdetect utility in format "i2cdetect -y X", where X may vary from 0 to 5 or more, |
| 97 |
to discover address occupied by peripheral device. To install utility you should run |
| 98 |
`apt install i2c-tools` on debian-kind system. `i2cdetect -y 1` sample output: |
| 99 |
``` |
| 100 |
0 1 2 3 4 5 6 7 8 9 a b c d e f |
| 101 |
00: -- -- -- -- -- -- -- -- -- -- -- -- -- |
| 102 |
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
| 103 |
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
| 104 |
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
| 105 |
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
| 106 |
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
| 107 |
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
| 108 |
70: -- -- -- -- -- -- 76 -- |
| 109 |
``` |
| 110 |
|
| 111 |
Contribute authors |
| 112 |
------------------ |
| 113 |
|
| 114 |
* [Kevin Rowett](https://github.com/K6TD): new sensor BMP388 support implementation. |
| 115 |
|
| 116 |
|
| 117 |
Contact |
| 118 |
------- |
| 119 |
|
| 120 |
Please use [Github issue tracker](https://github.com/d2r2/go-bsbmp/issues) for filing bugs or feature requests. |
| 121 |
|
| 122 |
|
| 123 |
License |
| 124 |
------- |
| 125 |
|
| 126 |
Go-bsbmp is licensed under MIT License. |