mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-10 18:03:41 +00:00
Initial support for BMP180 digital pressure sensor (#11)
* Initial support for BMP180 digital pressure sensor Note that Pressure & Temperature return int32 and millis unit (millidegrees and mPa)
This commit is contained in:
committed by
Ron Evans
parent
773b01e911
commit
3af2f18437
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/tinygo-org/drivers/bmp180"
|
||||
"machine"
|
||||
)
|
||||
|
||||
func main() {
|
||||
machine.I2C0.Configure(machine.I2CConfig{})
|
||||
sensor := bmp180.New(machine.I2C0)
|
||||
sensor.Configure()
|
||||
|
||||
connected := sensor.Connected()
|
||||
if !connected {
|
||||
println("BMP180 not detected")
|
||||
return
|
||||
}
|
||||
println("BMP180 detected")
|
||||
|
||||
for {
|
||||
temp, _ := sensor.Temperature()
|
||||
println("Temperature:", float32(temp)/1000, "ºC")
|
||||
|
||||
pressure, _ := sensor.Pressure()
|
||||
println("Pressure", float32(pressure)/100000, "hPa")
|
||||
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user