mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-07 16:33:39 +00:00
82e9e4a7f3
lps22hb: add support for lps22hb
38 lines
672 B
Go
38 lines
672 B
Go
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
|
|
|
|
}
|
|
|
|
}
|