tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/lps22hb/main.go (about) 1 package main 2 3 import ( 4 "machine" 5 "time" 6 7 "tinygo.org/x/drivers/lps22hb" 8 ) 9 10 func main() { 11 12 // use Nano 33 BLE Sense's internal I2C bus 13 machine.I2C1.Configure(machine.I2CConfig{ 14 SCL: machine.SCL1_PIN, 15 SDA: machine.SDA1_PIN, 16 Frequency: machine.TWI_FREQ_400KHZ, 17 }) 18 19 sensor := lps22hb.New(machine.I2C1) 20 sensor.Configure() 21 22 if !sensor.Connected() { 23 println("LPS22HB not connected!") 24 return 25 } 26 27 for { 28 p, _ := sensor.ReadPressure() 29 t, _ := sensor.ReadTemperature() 30 println("p =", float32(p)/1000.0, "hPa / t =", float32(t)/1000.0, "*C") 31 time.Sleep(time.Second) 32 // note: the device would power down itself after each query 33 } 34 35 }