Add support for LPS22HB MEMS nano pressure sensor (#297)

lps22hb: add support for lps22hb
This commit is contained in:
Alan Wang
2021-11-06 18:14:21 +08:00
committed by GitHub
parent 76ff632134
commit 82e9e4a7f3
6 changed files with 171 additions and 1 deletions
+37
View File
@@ -0,0 +1,37 @@
package main
import (
"machine"
"time"
"tinygo.org/x/drivers/lps22hb"
)
func main() {
machine.I2C1.Configure(machine.I2CConfig{
SCL: machine.P0_15, // SCL1 on Nano 33 BLE Sense
SDA: machine.P0_14, // SDA1 on Nano 33 BLE Sense
Frequency: machine.TWI_FREQ_400KHZ,
})
sensor := lps22hb.New(machine.I2C1)
if !sensor.Connected() {
println("LPS22HB not connected!")
return
}
sensor.Configure()
for {
p, _ := sensor.ReadPressure()
t, _ := sensor.ReadTemperature()
println("p =", float32(p)/1000.0, "hPa / t =", float32(t)/1000.0, "*C")
time.Sleep(time.Second)
// note: the device would power down itself after each query
}
}