tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/hts221/main.go (about) 1 package main 2 3 import ( 4 "machine" 5 "time" 6 7 "tinygo.org/x/drivers/hts221" 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 := hts221.New(machine.I2C1) 20 21 sensor.Configure() // power on and calibrate 22 23 if !sensor.Connected() { 24 println("HTS221 not connected!") 25 return 26 } 27 28 for { 29 h, _ := sensor.ReadHumidity() 30 t, _ := sensor.ReadTemperature() 31 println("h =", float32(h)/100.0, "% / t =", float32(t)/1000.0, "*C") 32 time.Sleep(time.Second) 33 } 34 35 }